This project was designed to eliminate the struggle of forgetting to turn off lights before bed, and when the room is sufficiently lit from outdoor light. People who are lazy, forgetful, and clumsy would love this. All you need to start is just two photons and a spark fun sound detector.
This is the first part of the project, it is fairly simple. All you need is a photon, some wires, a mini breadboard, and a SEN 12642 SparkFun Sound Detector. It is possible to not use the SEN 12642 sound detector, but you will have to use a microphone and an amplifier to boost the signal. With the SEN 12642 sound detector, you will want to use the envelope output pin. We have setup the Photon, so that the A0 pin is the reading the signal from the amplifier. The Vin and GND pins are used to supply power to the SEN 12642. Once its all set up, you will have to calibrate it to only activate when a certain peak signal is reached, and that will be done in the code.
The second part included the photon, mini breadboard, the photo resistor, and a 100 kohms resistor. The Vin and GND from the photon are connected to the photo resistor and resistor in order to supply power. At first a bigger resistor was used with the photo resistor, but there was too much sensitivity for the amount of light it picked up. Lowering the resistor lowered the sensitivity a little bit. The photo resistor is connected to the A0 pin on the photon in order to get the light readings. The readings would go to ThinkSpeak to show what readings the photo resistor was picking up for when the light was on or off which was all done through the code.
The last and very important part of this project is the Smart Life "Mini Plug". This plug has an internal switch which can be controlled via the internet to turn on and off, perfect for the particle platform. The other major applications that are required are IFTTT, ThingSpeak, and Webhooks. The important part of this plug is that it is compatible with IFTTT which is basically a website which can run "if this then that" statements. It is extremely important that you make a webhook that receives the particle publishes from the photon and sends them directly to IFTTT, if you don't it can take either one minute to a hour for the smart plug to respond. No one has enough time for that.
We also included certain bits of information that is transferred to each photon. For example we used particle.subscribe to turn on the D7 led on the LightSensor when the light is on. When the light is turned off the D7 blinks rapidly then turns off showing the state of the light. In the SoundDetector, we have particle.subscribed to the event BrightRoom which turns off the light when the room exceeds a certain light level to hopefully help turn off any unnecessary lights.
Here is some of our data that was graphed from 3am to about 11am, and its cool that you can see right at the point where light started to enter my room at around 7am. I was curious as to why it was pegged at 4K readings. Since most of the time this sensor was only tested at night, actual sunlight has a far greater effect on the photo resistor than a simple lamp light. In the end, a different resistor was used to lower the voltage output value to compensate. It is also fun to see all the spikes and rough data when there is a person nearby.