Project Summary
As architecture students, we are in studio an excessive amount of time and because of that we typically have the lights on for extended periods of time. For our project we decided to set up a code that would calculate the cost of lighting the room when we are doing work. Even during the day we have a tendency to leave the lights on. Our device is set up so that a light sensor (photocell) detects when the lights are on by sensing a very particular range of intensity which comes from the main lights in the studio so even if the shades are open and daylight is coming in our sensor will be able to know if the light is on or if that is just daylight. Essentially the light sensor is a switch that, when activated, informs the code to start calculating the cost incurred and then display the cost on the attached LCD.
Project Members – John Mellas, Brandon Stone, John Wightman
Images
Video
Circuit Diagram
CodeĀ
#include <LiquidCrystal.h> #include <Wire.h>
#define REDLITE 3 #define GREENLITE 5 #define BLUELITE 6
// Pins int sensorPin = 0; int dataPin = 9; int t=0; float cost=0.0000000; int calculatedseconds=1;
// BS E D4 D5 D6 D7 LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// you can change the overall brightness by range 0 -> 255 int brightness = 255;
void setup() {
lcd.begin(16, 2);
// Start Serial & set pin to output Serial.begin(9600); pinMode(dataPin,OUTPUT);
pinMode(REDLITE, OUTPUT); pinMode(GREENLITE, OUTPUT); pinMode(BLUELITE, OUTPUT);
brightness = 100;
}
void loop() {
// Read the sensor pin int sensorValue = analogRead(sensorPin);
// Display Light on first row int lightReading = analogRead(dataPin);
if(lightReading>500) { t++; Serial.println(t); delay(1000);
if( t%calculatedseconds==0 ) { cost=0.0000009733*(t/calculatedseconds); Serial.println(cost,8);
} }
lcd.setCursor(0, 0); // ---------------- lcd.print("Cost $ "); lcd.setCursor(6, 0); lcd.print(cost,8);
}