#12Beginner
Night Light with Ldr
4.8(97)
139 completed

LDR based night light project that automatically turns on the LED when the environment gets dark. Teaches automatic control logic with analog threshold comparison.
Video
Circuit Diagram

Source Code
1int value;
2
3void setup() {
4 pinMode(13, OUTPUT);
5}
6
7void loop() {
8 value = analogRead(A0);
9
10 if (value < 50) {
11 digitalWrite(13, HIGH);
12 } else {
13 digitalWrite(13, LOW);
14 }
15}