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

Particle Photon Based Security System with Alerting
Intermediate
  • 1,345
  • 20

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Happy Plant Notifier
Intermediate
  • 290
  • 5

Full instructions

Get a text or call if your plant is getting too dry, along with a nice LCD display giving information regarding your plant's health.

My Guardian for the Workshop
Intermediate
  • 202
  • 4

Full instructions

Device will send emails if the door or window has been opened, and will monitor the temperature and humidity of the place.

Smart and Safe Outdoor Plant Watering System
Intermediate
  • 2,526
  • 18

Monitors soil moisture and weather forecasts to give plants just the water they need. Safe garden hose hookup for season long watering.

Christmas Gift Box
Intermediate
  • 3,684
  • 595

Full instructions

Christmas Gift Box plays music and sends an email when it is opened.

Carbon Fiber Vacuum Chamber
Intermediate
  • 3,035
  • 94

Full instructions

Our project is a carbon fiber vacuum chamber that is monitored by multiple particle photons and various sensors.

Add projectSign up / Login