#define lightIn A2 // the LDR
#define LED 13 // the LED
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(lightIn, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(100);
int val = analogRead(lightIn); // Reading the binary value of the LDR
String dn = ""; // dn (Day/Night) represents whether the lights are on
if (val >= 256) // If the light is below 500 Lux (the light level considered for night)
{
digitalWrite(LED, LOW); // if night then the light is off
dn = "OFF";
}
else
{
digitalWrite(LED, HIGH); // if day then the light is on
dn = "ON";
}
Serial.print("Ambient Light level is: ");
Serial.print(val);
Serial.print(" and the lights are ");
Serial.println(dn);
}