const int sensorPin=A0;//choose the pin for phtot resistor
const int ledPin=9;//choose the pin for LED
int lightCal;//reading the intial value of photo resistor
int lightVal;//reading for the current photo sensor
void setup() {
pinMode(ledPin,OUTPUT);// declare LED as a output
lightCal=analogRead(sensorpin);
}
void loop() {
lightVal=analogRead(sensorPin);//read input value
if(lightVal<lightCal-50){//check the input is less than threshold
digitalWrite(9, HIGH);//turn LED ON
else{
digitalWrite(9, LOW);//turn LED OFF
}
}