int relay1=8; #define LDRpin A0 // pin where we connected the LDR and the resistor int LDRValue = 0; void setup() { // put your setup code here, to run once: pinMode(relay1,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: LDRValue = analogRead(LDRpin); // read the value from the LDR Serial.println(LDRValue); // print the value to the serial port delay(100); if(LDRValue>500) digitalWrite(relay1,HIGH ); else digitalWrite(relay1,LOW); }