Smart Light & Fan

Made by jfwiddifield

The smart light and fan uses a photoresistor and temperature sensor to regulate the light output and the fan output. As the natural daylight in a room slowly starts to fade during dusk, the light gradually increases in brightness to keep the foot-candles consistent. Additionally, when the temperature reaches above a set temperature, the fan is activated until the temperature falls back below that temperature threshold.

Created: January 27th, 2015

0

The smart light and fan uses a photoresistor and temperature sensor to regulate the light output and the fan output. As the natural daylight in a room slowly starts to fade during dusk, the light gradually increases in brightness to keep the foot-candles consistent. Additionally, when the temperature reaches above a set temperature, the fan is activated until the temperature falls back below that temperature threshold.

The results of the project were mixed. The photoresistor seemed to work extremely well as depicted by the video. To make the LED adjust to the sensitivity of the photoresistor, I made two minor changes to the code; first, I created an inverse relationship between the sensor and the LED (90, 2000, 255, 0 - instead of90, 2000, 0, 255). Second, I turned off all lights and got a reading from the photoresistor of around 95 which I used to set (with a slight tolerance) the new threshold. Next, I turned on all of the lights to achieve a reasonable amount of light in the space and got a reading of around 2000, which I set as the upper threshold. 

One preliminary coding issue I encountered was the use of multiple void setup() and void loop() commands. I was previously unaware that there can only be one of each within a single sketch. Once figuring this out, I was able to take my two separate sketches (one sketch for the photoresistor + LED and one sketch for the temperature sensor) and combine them into a single sketch as seen in the coding below.

I had several troubles getting the temperature sensor to work accurately. It would often give inaccurate readings then jump all over the scale as if the temperature was fluctuating drastically every second. My intention was to connect a motor to the SparkCore which would turn on (as if it were a fan) above a certain threshold. Due to the complexities in wiring and coding, as well as the issues with the temperature sensor, I was unable to accomplish this. The temperature sensor did, however, work once in which case I was able to get an accurate reading and screenshot of the data. 

*photo credit (http://theawesomer.com/haiku-led-ceiling-fan/247920/)

0
int photoCellPin = A1;
int photoCellReading = 0;
int ledPin = D0;
int ledBrightness = 0;
int tempPin = A0;
double temperature = 0.0;
double temperatureF = 0.0;

void setup()
{pinMode(ledPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Spark.variable("light", &photoCellReading, INT);
Spark.variable("temperature", &temperature, DOUBLE);
Spark.variable("temperatureF", &temperatureF, DOUBLE);
pinMode(tempPin, INPUT);}

void loop()
{photoCellReading = analogRead(photoCellPin);
ledBrightness = map(photoCellReading, 90, 2000, 255, 0);
analogWrite(ledPin, ledBrightness);
delay(100);
int reading = analogRead(tempPin);
double voltage = (reading * 3.3) / 4095.0;
temperature = (voltage - 0.5) * 100;
temperatureF = ((temperature * 9.0) / 5.0) + 32.0;}
Click to Expand
0
x
Share this Project


About

The smart light and fan uses a photoresistor and temperature sensor to regulate the light output and the fan output. As the natural daylight in a room slowly starts to fade during dusk, the light gradually increases in brightness to keep the foot-candles consistent. Additionally, when the temperature reaches above a set temperature, the fan is activated until the temperature falls back below that temperature threshold.