/*LDR + Relay, 12 DC Motor Control
Wilhelm Schütze - Fab Academy 2015 */

 

int MTR_pin=5; //Motor is on pin 5
int LDR_pin = 0; //Read pin 0
int LDR_val = 0; //LDR data Variable

void setup() {

pinMode(MTR_pin,OUTPUT); //Motor 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 on the motor
{
digitalWrite(MTR_pin, HIGH); // Turn on the motor
}
else if (LDR_val<500) // If there is no light, turn off the motor
{
digitalWrite(MTR_pin, LOW); // Turn off the motor

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

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