COMPONENTS-
Arduino Board X 1
LDR X 1
LED X 1
5k ohm or above Resistor
What is a LDR?
. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity.
CODE-
int LDRValue = 0;
int led=9;
// result of reading the analog pin
void setup()
{
Serial.begin(9600) // sets serial port for communication
pinMode(led,OUTPUT);
}
void loop()
{
LDRValue = analogRead(LDRpin); // read the value from the LDR Serial.println(LDRValue);
// print the value to the serial port delay(100);
Serial.println(LDRValue);
if(LDRValue<300)
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
}