In the on campus apartments at UNCC, the living room and kitchen are combined into a single large room. This causes some problems, since the two parts of it are lit with different light sources controlled by different light switches. This can create situations where there is a pretty significant light gradient across the room, especially at night.
This project uses two IoT connected Particle Photons to control the light switch for the living room portion of the apartment in order to equalize the light level in the whole room. Essentially, If the living room area is darker than the kitchen area, then a servo flips on the light switch for the living area. If the kitchen area is darker than the living room area, then the servo flips the switch off.
The first photon uses a pair of photoresistors to determine the relative light level in each portion of the room. One photoresistor is attached to the back wall of the kitchen area such that it has no direct line to the light source in the living area, but is almost directly below the kitchen area light. For our physical setup, this required running a pair of wires from the points where the photoresistor appears on our schematic to its actual location, since the Photon was installed several feet away. The other photoresistor has a direct line of sight ot both the light in the living area and the window, the two primary sources of light in the living area, but is in shadow when only the kitchen light is on. For our physical setup, this photoresistor was able to remain on the same breadboard as Photon#1. The two photoresistors are in parallel with each other and each in series with a 221 Ohm resistor. Jumper wires connect the parts of the circuit between each photoresistor and their respective regular resistor to ports on the Photon configured as analog read. The software on this Photon (called Light Sensor Code below) takes an average value from each photoresistor circuit over about 1.5 seconds and compares them. If a boolean tracking the status of the living room light switch indicates the switch is down, and the photoresistor reading from the living area lower than the reading from the kitchen area, then the Photon publishes an event called "On125". If the photoresistor reading from the living area is not lower, and the boolean is in the other position, then the photon publishes the event "Off125". The boolean tracking the lightswitch position is controlled by the event "LightsLog", which is published by the second Photon and subscribed to by the first.
The second photon physically controls the living area light switch using a servo motor. This is connected directly to Photon#2, getting its power supply from the Vin and GND ports on that Photon and its control data via PWM signal from port D0. On the software side, this photon is using the Particle servo control functions and is subscribed to the events "On125" and "Off125" from Photon#1. When "On125" is published, the Photon sets the servo to 120 degrees and publishes the event "LightsLog" with the data "On". When "Off125" is published, the Photon sets the servo to 15 degrees and publishes the event "LightsLog" with the data "Off". These servo position degree values were determined through testing as the smallest amount of movement in the servo that allowed it to reliably flip the light switch.
ThingSpeak Channels:
ThingSpeak is an open IoT platform that connects to MATLAB and can provide data analytics. In this case, webhooks in the code on each of the Photons used in this project send light level and servo position data whenever the system turns the light switch on or off. Samples of the data are shown below the links to the ThingSpeak channels providing real time data on the system for each aspect.
One limitation of the ThingSpeak system is that the free version only allows a channel to accept new data every 15 seconds, which means that rapid switching of the light on and off would not appear on the ThingSpeak channel correctly. To combat this, 15 second delays would need to be put into the code for the light switch, which would reduce its effectiveness at synchronizing the lights in the main room of the apartment.
Comments