VIN Technologies › Labs › Microcontroller Lab
Light-controlled lamp (LDR + analogRead)
Microcontroller Lab · free online experiment, runs in your browser with no install or sign-up.
Open this experiment in the circuit simulator
Objective
Read an LDR divider on A0 and switch an LED on when the room gets dark.
Procedure
- Press Start Simulation with the LDR at 1 lux: the LED is on.
- Change the LDR 'lux' to 1000 and run again: the LED goes off.
Theory
The LDR and a 10 kΩ resistor form a divider: in the dark the LDR resistance is high, so A0 is low (below 300 of 1023) and the sketch lights the LED; in bright light A0 is high and the LED is off.
Questions to answer
- How would you add hysteresis so the lamp does not flicker at dusk?
Components used
Arduino UNO R3 (clone, SMD), Breadboard 400 points, LDR GL5528, LED 5mm Red, 2 × Resistor 220 ohm 1/4W
About the model
Breadboard contacts are ideal (no contact resistance or capacitance). Arduino-style C/C++ subset interpreter (not AVR machine code): no interrupts or libraries, int is 16-bit, only delay() advances time, pin modes are fixed after setup(). Outputs are 5 V behind 25 Ω.
Open this experiment in the circuit simulator