INTRO
Motion controlled room lighting is convenient in all kinds of situations. It's great for those days when you're rushing out the door in the morning and forget to turn off the lights at the cost of your electric bill. For those days when you're stumbling through the door after a late night and fumbling around in the dark looking for the light switch and instead end up finding your bed in the worst way possible. It's even great if you have a hunch that your siblings are sneaking into your room and touching your things when you aren't home.
THE BASICS
The inner workings of the system aren't terribly complicated. In essence, one Photon keeps tabs on a PIR motion sensor as well as a photo resistor. If motion is detected, the photon lights up the LED on the breadboard and then checks the reading from the photo resistor to determine if the room is dark enough to warrant turning on the lights. If this is true, the photon communicates with a second photon that is connected to a two channel relay shield, which is then connected to a power strip, controlling whatever light is plugged in. The initial photon also logs the photo resistor readings (in volts) on ThingSpeak every minute. Here is the link for ThingSpeak: https://thingspeak.com/channels/249557
Note 1: Connecting to a power strip won't allow you to control any overhead lighting system in the room, but we decided that connecting to a power strip would be simpler than attempting to re-wire anything already installed in your wall. Plus, this way is potentially much more discreet looking because you can easily hide the power strip and other components and you don't have to deal with gaudy wires hanging out of your wall switches or having to attach some contraption to your wall to flip the switch for you.
Note 2: The code for the photon connected to the PIR motion sensor acts so that when motion is detected in an unlit room, the lights will turn on. One the lights are on, further motion detected by the sensor will activate a timer that counts down three minutes. At the end of the three minutes, if the motion sensor does not pick up another signal, the lights will be turned off. So, once you leave the room, the lights will turn off after three minutes. However, while you are still in the room this caveat will require that the inhabitant of the room move again if they have been idle in order to keep the lights form turning back off (unless you have Alexa connected as well, then you can tell her to keep the lights on).
PARTICLE PHOTON - THINGSPEAK INTEGRATION
Information about connecting your Particle photon to ThingSpeak can be found at the following link (courtesy of Hans and Robert Mawrey): https://www.hackster.io/15223/thingspeak-particle-photon-using-webhooks-dbd96c
As you follow the information, you might ask yourself, "What is the 'XXXXXXXXXXX' in the code that connects to your photon?" This is the API Key of your ThingSpeak account. The XXXXXXXXXX part is located in the code for the PIR and photo resistor at the bottom. If you use this code, your API key must be entered into this section.
USING ALEXA TO CONTROL THE LIGHTS
This system is also integrated with the Amazon Echo via IFTTT. So, saying, "Alexa, trigger lights on," will turn the lights on, and "Alexa, trigger lights off," will turn the lights off. Alexa will then send a command to IFTTT that will trigger the "Motion-Detected" event in the particle console, as if the motion sensor had picked up motion.
*********IMPORTANT NOTE**********
PLEASE BE CAREFUL WHEN DEALING WITH THE POWER STRIP AND RELAY CONNECTIONS TO AVOID INJURY! BECAUSE IT IS CONNECTED TO THE WALL, YOU ARE WORKING WITH A VERY HIGH VOLTAGE! IF YOU DO ANYTHING WITH THE POWER STRIP, BE SURE THE MASTER SWITCH IS TURNED OFF AND IT IS UNPLUGGED FROM THE WALL! WE WOULD HATE FOR THIS TO BE THE LAST PROJECT YOU EVER DO!
Comments