Things used in this project

Hardware components:
Photon new
Particle Photon
×1
Particle Relay Shield v2
×1
Poplite Hot Air Popper
×1
12V, 2A Power Supply
×1
Software apps and online services:
Screen%20shot%202016 03 01%20at%209.14.06%20pm
Losant Platform
Losant icon
Losant Go Mobile App
Particle Cloud API

Code

PopcornRelay.inoArduino
The onboard Particle firmware. No libraries used or required.
const int MOTOR_PIN = D3;
const unsigned long MOTOR_DURATION = 500;
const unsigned long POPCORN_DURATION = (2 * 60 + 20) * 1000; // 2 minutes, 20 seconds
const int RELAY_PIN = D0;

bool making_popcorn = false;
unsigned long started_making_popcorn;
bool running_motor = false;
unsigned long started_running_motor;

int make_popcorn (String command);

void setup () {
    pinMode (MOTOR_PIN, OUTPUT);
    pinMode (RELAY_PIN, OUTPUT);

    Particle.function ("make_popcorn", make_popcorn);
    Particle.function ("start_motor", start_motor);
}

void loop () {
    if (making_popcorn) {
        unsigned long duration = millis () - started_making_popcorn;
        if (duration > POPCORN_DURATION) {
            digitalWrite (RELAY_PIN, LOW);
            making_popcorn = false;
        }
    }
    
    if (running_motor) {
        unsigned long duration = millis () - started_running_motor;
        if (duration > MOTOR_DURATION) {
            digitalWrite(MOTOR_PIN, LOW);
            running_motor = false;
            make_popcorn (String (""));
        }
    }
}

int make_popcorn (String command) {
    if (making_popcorn) {
        return 0;
    }
    
    making_popcorn = true;
    started_making_popcorn = millis();
    digitalWrite (RELAY_PIN, HIGH);

    return 1;
}

int start_motor (String command) {
    running_motor = true;
    started_running_motor = millis();
    digitalWrite(MOTOR_PIN, HIGH);
    
    return 1;
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

WiFi Strength Meter
Easy
  • 561
  • 9

A meter that indicates the Wi-Fi signal strength in an intuitive way, using the parts I had on hand.

E-Paper Weather Display with Photon and IFTTT
Easy
  • 4,483
  • 21

Full instructions

Create a beautiful medium for weather information using Particle's cloud services and IFTTT.

2-Way Particle Photon Communication
Easy
  • 199
  • 4

Make two Particle Photons "talk" via the usage of webhooks!

IFTTT - Enabled Sensors with Particle Photon
Easy
  • 734
  • 11

Full instructions

Connect any sensor to Particle Photon and use it to trigger an IFTTT action with just a few lines of code.

Light Detecting Email Sender
Easy
  • 232
  • 4

Full instructions

Receive an email about when the light is too strong on your device; nobody wants a heated device left directly under the sun. Photon + IFTTT

MyReed-Switch Controlled by Particle Electron
Easy
  • 51
  • 0

Full instructions

Magnetism in a simple door monitoring.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog