// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//These constants should match the photoresistor's "gamma" and "rl10" attributes
const float GAMMA = 0.7;
const float RL10 = 50;
//Condition of that day based on illumination and LDR resistance
String weatherConditions[9] = {"Full moon", "deep twilight", "twilight", "Computer monitor", "Stairway light", "Office light", "Overcast day", "Full daylight", "Direct sunlight"};
//NB: This system is constructed in such a way that the LED turns ON when its dark and OFF during the day
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.println("Hello, Master P!");
delay(2000);
lcd.setCursor(0,1);
lcd.println("Conditions tdy :");
}
void loop() {
// put your main code here, to run repeatedly:
//Convert the analog value into lux value
int analogVal = analogRead(A0);
float analogValue = analogVal;
float voltage = (analogValue / 1024) * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1000 * pow(10, GAMMA) / resistance, (1 / GAMMA)); //lux is the unit of measurement for illumination
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
if(lux >= 0.1 && lux < 1.0){ lcd.print( weatherConditions[0] ); }
else if(lux >= 1 && lux < 10){ lcd.print( weatherConditions[1]); }
else if(lux >= 10 && lux < 50){ lcd.print( weatherConditions[2]); }
else if(lux >= 50 && lux < 100){ lcd.print( weatherConditions[3]); }
else if(lux >= 100 && lux < 400){ lcd.print( weatherConditions[4]); }
else if(lux >= 400 && lux < 1000){ lcd.print( weatherConditions[5]); }
else if(lux >= 1000 && lux < 10000){ lcd.print( weatherConditions[6]); }
else if(lux >= 10000 && lux < 100000){ lcd.print( weatherConditions[7]); }
else if(lux >= 100000){ lcd.print( weatherConditions[8]); }
else{}
delay(2000);
lcd.setCursor(0,1);
lcd.print(lux);
lcd.print(" lux");
}