Fig 3
10k Resistor connected to the LDR
220 Ohm Resistor connected to the LED
Fig 4
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 200) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}