const int LED=2; // LED connect to Digital Pin
const int LDRSensor= A0; //Sensor pin connects to analog pin A0
int state; //declaring variable to store the reading
int threshold=600; //threshold voltage declared
void setup()
{
pinMode (LED, OUTPUT);
Serial.begin(9600);
}
void loop()
{
state= analogRead(LDRSensor); //sensor reading value stored in state variable
if (state < threshold)
{
digitalWrite(LED, HIGH); //if the light is below the threshold value, the LED will turns on
Serial.println(state);
delay(2000);
}
else
{
digitalWrite(LED, LOW); //otherwise, the LED is off
Serial.println(state);
delay(1000);
}
}