Things used in this project

Hardware components:
Photon new
Particle Photon
×2
Relay (generic)
We used a SPDT Relay (Jzc-11F), but any generic relay should do.
×1
Mfr 25fbf52 221r sml
Resistor 221 ohm
×2
Adafruit industries ada161 image 75px
Photo resistor
×1
11026 02
Jumper wires (generic)
Three of these wires will be connected straight into your house's power circuit, so you may want to make them thicker to handle the higher voltage.
×5
Power Bank
×1
Software apps and online services:
IFTTT Particle Service
Used for triggers and notifications.
Fritzing
Used to build the circuit schematics.
Hackster
ThingSpeak API
Used to record real-time data and plot graphs.
Particle - IDE
Used to generate code for photon devices.
Github IoT Debugger
Used as a WebHook to interconnect photon devices with ThingSpeak.

Schematics

Particle Photon #1
Breadboard view
Megr 3171 particle photon 1 y9mt2fll0m
Particle Photon #2
Breadboard view.
Note: The relay is rated at a 5V minimum to activate the switch from NC to NO, though we used port D7 that is rated at 3.3V. This still worked for us, but if you are having issues getting the relay to switch try running an external battery pack across the relay coil.
Megr 3171 particle photon 2 b2bose8tkq
Photon #1 Schematic
Schematic of setup
Megr 3171 photon 1 schematic ryxrbshbgv
Photon #2 Schematic
Schematic of setup
Megr 3171 photon 2 schematic xluhhvbdqy
Light Check IFTTT
This runs the code to see if the lights are on. If the lights are on, the loop is allowed to run and send events that the lights are on to activate the relay.
Megr 3171 ifttt light check via text c75vjxuwme
Lights are off IFTTT
This sends a notification to your phone letting you know that the lights have been turned off or if they were already off.
Megr 3171 ifttt lights are off fg5huwuhbc

Code

Particle Photon #1C/C++
int photoresistor = A0;
int power = A5;
int analogvalue;
int lowvalue;
int commandCheck=0;
#define publish_delay 8000
unsigned int lastPublish = 0;

void setup() {
pinMode(photoresistor,INPUT);
pinMode(power,OUTPUT);
Particle.function("checklights",check);
digitalWrite(power,HIGH);
Particle.variable("analogvalue", &analogvalue, INT);
lowvalue = 6; //This value was obtained from trial and error. It creates a buffer beween the values of when the lights are off and when the lights are on. Can be changed depending on the envirnoment that the sensor is place in.
analogvalue = analogRead(photoresistor);
}
void loop() {
    analogvalue = analogRead(photoresistor);
    unsigned long now = millis();
    if ((now - lastPublish) < publish_delay) {
        return;
    }

    int value = analogRead(A0);
    Particle.publish("thingSpeakWrite_A0", "{ \"1\": \"" + String(value) + "\", \"k\": \"R039SVKNF07FZEBQ\" }", 60, PRIVATE);
    lastPublish = now;
    while (commandCheck == 1)
    {
        if (analogvalue >= lowvalue){ //If the lights are on, event is published
        Particle.publish("maxkeithlighton","on");
        delay(1000);
    }
        else if (analogvalue < lowvalue){ //If the lights are off, it's published
        Particle.publish("maxkeithlightoff","off");
        delay(1000);
    }
    }
}
int check(String command){ //This allows us to command the relay on/off via IFTTT
    if (command=="on?") {
        commandCheck = 1;
        return 1;
    }
    else if (command=="off"){
        commandCheck =0;
        Particle.publish("maxkeithlightoff","off");
        return 0;
    }
    else {
        return -1;
    }
}
Particle Photon #2C/C++
#define publish_delay 16000
unsigned int lastPublish = 0;
void setup()
{
  Particle.subscribe("maxkeithlighton", lights);
  Particle.subscribe("maxkeithlightoff", lights);
  pinMode(D7, OUTPUT);
  
}

void loop()
{
unsigned long now = millis();
    if ((now - lastPublish) < publish_delay) {
        return;
}
    int value = digitalRead(D7);
    Particle.publish("thingSpeakWrite_D7", "{ \"1\": \"" + String(value) + "\", \"k\": \"T8YQ6CN74QADE915\" }", 60, PRIVATE);
    lastPublish = now;
}

void lights(const char *event, const char *data)
{
    if (strcmp(data,"on")==0) 
  {
       digitalWrite(D7,HIGH);
  }
    else if (strcmp(data,"off")==0) 
  {
       digitalWrite(D7,LOW);
}
}

Credits

Thanks to John McAlpine.

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

AquaNiner Pet Hydration Monitor
Intermediate
  • 434
  • 14

Full instructions

Using two Photons, IFTTT and ThingSpeak, get notifications for when your furry friend needs water and monitor how much they're drinking.

Hot Shot Hoops
Intermediate
  • 576
  • 13

Full instructions

No need to keep track of the number of baskets you make when shooting hoops. Hot Shot Hoops does the work for you.

Hot Shot Hoops

Team IOT Basketball

Temperature Mirror
Intermediate
  • 417
  • 8

Full instructions

The Temperature Mirror incorporates a digital display to allow its user to readily view time, temperature, humidity, and light.

Temperature Mirror

MEGR3171 Team 49

Pet Feeder
Intermediate
  • 452
  • 8

Full instructions

Automated pet food dispenser to feed our pets when we are not at home by using an IoT device.

Teacher Tracker
Intermediate
  • 196
  • 4

Full instructions

If you want to know when a professor comes back to his/her office so you can ask annoying questions then this an option

Alerts via Pushbullet When Smoke is Detected
Intermediate
  • 325
  • 8

Full instructions

This project uses two Particle Photons and Pushbullet to notify a user when smoke is detected by a smoke detector.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback