/*LDR + Relay, Lights On When Dark
Wilhelm Schütze - Fab Academy 2015 */

 

int LEDS_pin=5; //LEDs are on pin 5
int LDR_pin = 0; //Read pin 0
int LDR_val = 0; //LDR data Variable

void setup() {

pinMode(LEDS_pin,OUTPUT); //LEDs pin is an output

Serial.begin(9600); //Serial comunication begins
}

void loop(){


LDR_val = analogRead(LDR_pin); // Read input LDR value

if (LDR_val>=500) // If there is Light, turn off the LEDs
{
digitalWrite(LEDS_pin, LOW); // Turn off the LEDs
}
else if (LDR_val<500) // If there is no light, turn on the LEDs
{
digitalWrite(LEDS_pin, HIGH); // Turn on the LEDs

Serial.print("LDR = "); // Print LDR value on the serial monitor
Serial.println(LDR_val);

delay(100); // 0.1 sec delay
}
}