LearnTronics
Automatic Nightlight with Delay
Recipe #25 — automatic nightlight with delay
The light-controlled switch can be improved by adding capacitance. An LDR senses darkness, a capacitor slows rapid changes, and a comparator makes a clean decision.
Put some numbers on it
These are example values, because an LDR's resistance depends strongly on the particular part and the amount of light falling on it. Here we will use P1 = 100 kΩ, R2 = R3 = 47 kΩ, C1 = 100 µF, RB = 10 kΩ, and a 1 kΩ LED resistor.
P1 and the LDR form another voltage divider:
With P1 set to 100 kΩ, an LDR resistance of 100 kΩ also produces about 4.5 V. So, with this equal R2/R3 reference, the switching point occurs when the LDR resistance is approximately equal to the resistance selected by P1. Increasing P1 makes the circuit wait for a higher LDR resistance—in other words, a darker condition—before switching.
C1 does not charge through just one resistor. The resistance it "sees" is approximately the parallel combination of P1 and the LDR:
For the dark example, 100 kΩ || 1 MΩ is about 90.9 kΩ. With C1 = 100 µF:
Starting near 0.82 V and heading toward 8.18 V, the capacitor reaches the 4.5 V comparator threshold in about 0.693 time constants, or roughly 6.3 seconds.
When the light returns and the LDR falls to about 10 kΩ, the effective resistance becomes 100 kΩ || 10 kΩ ≈ 9.1 kΩ. The time constant is then only about 0.91 s, so the same circuit turns back off much more quickly. That unequal ON/OFF delay is a real consequence of the resistance ratios, not a drawing accident.
Changing C1 scales both delays almost directly. With the same example resistances, 47 µF gives roughly half the delay, 100 µF gives the values above, and 220 µF gives a little more than twice the delay. Changing P1 affects both the darkness threshold and the timing because it is part of the sensor divider as well as part of C1's charging path.
The calculated times are examples rather than guaranteed values. Real LDRs have wide resistance tolerances, light changes are rarely instantaneous, and the exact comparator input and output behavior also matter.
Why add C1?
Without C1, a brief shadow or flicker can move the sense voltage across the threshold immediately. C1 slows that change. The nightlight therefore responds to a sustained change in light rather than every tiny disturbance.
Delay and hysteresis solve different problems
An RC delay slows changes with time. Comparator hysteresis creates separate ON and OFF thresholds. Practical sensor switches often use both so they neither react too quickly nor chatter near the switching point.