This project uses two particle photons, two PIR motion sensors, and a servo motor to automatically turn the light in our stairway on and off whenever somebody walks by. This is because the top half (near the bedrooms) of the stairway is very dark, especially when all the bedroom doors are closed. We often forget about the light not being on until we are half way up the stair and its completely dark.
The first photon with a PIR sensor is positioned down at the end of the stair. The second photon and PIR sensor plus the servo motor is positioned up the stair near the light switch. If the 1st photon detect motion, a signal will be sent to the 2nd photon using the publish and subscribe function. The code to run the servo is in the 2nd photon and it will tell the servo motor to turn and flip the light switch. Once the light switch is turned on, there will be a delay on both photons, achieved by having each photon publish and subscribe to each other's event, and they will not do anything even if the sensors detect someone during that time. This make sure that both photons are operating synchronously. The code is set to automatically flip the switch back to the off position after the delay ends.
The PIR sensor and servo motor was included in the particle maker kit purchased from Particle. The PIR sensor works by detecting a change in temperature gradient, in which if such change occur, it will put out momentary voltage (around 3.3V) as an output, which the photon can detect using the AnalogRead command on one of the pins. The PIR sensor have a very wide detection zone (nearly 180 degree) so considerations should be given to its placement location. The range of the detection zone as well as the time delay of the output upon detection can also be increased or reduced.
Each time the motor flip the light switch to turn on the light, the 2nd photon will also sends a data value of "1" to Thingspeak. Because each "1" represents a flip of the light switch to the on position (switching the light switch off does not count), the data can be summed up to show the number of times the light was switched on per minute/hour/day, etc. using the built in "sum" function in the chart options on Thingspeak.
Click for live channel feed
1 / 2 • # of time light turn on per hour (2 days worth of data)
The light switch flipping mechanism is made using a cut out of a piece of plastic from a phone case, and then screwed onto the servo motor's axial (included with motor). Any rigid but slightly flexible plastic should work, such as one from DVD case or cheap phone case. The cut can be done with scissor or wire cutter. The size of slot for the switch will depend on the servo's distance from the switch. But the angular position of the servo's swing can be adjusted to accommodate different size slots. If the plastic is a bit thin of flimsy, an extra piece of support (made out of Popsicle stick) should be glued on to prevent the end from bending inward toward the corner of the light switch on the upward swing, which will most likely stall the motor and fail to slip the switch.
The mount for the servo motor itself is made out of a modified piece of vinyl window blinds bracket. I had a few laying around after purchasing new blinds. This bracket is plastic and fairly durable, but can still shatter if any single cut is too big. The slot for the servo can also be cut out using a wire cutter (a wire saw might be better). A drill is needed to make two mounting holes for the servo motor. The bracket was hot glued straight onto the wall (other adhesive could work too). The main purpose of this modified bracket is to offset the servo from the wall to the desired height so other methods of achieving that could work too.
The flipping of the light switch can also be done through a relay controlled by the photon (probably easier, faster, and more efficient). But since we didn't have a relay on hand nor be willing to mess around with the wiring of our apartment, controlling the switch through a servo was the next best thing.