Comparator with a light sensor
A comparator is an op-amp built for decisions: its output switches fully one way or the other depending on which input is higher. Here an LDR divider is compared with a threshold from a pot. When it gets dark, the divider voltage drops below the threshold and the LM393 turns the light on.

Open this lesson in the labFree, in your browser, no account needed.
How it works
Light signal: V− = 5 × 10k / (10k + RLDR) = 5 × 10k / (10k + 1.82 kΩ) = 4.232 V
Threshold: V+ = 5 × pot = 2 V
V+ < V−, so the open-collector output is pulled low, LED off.
Near the threshold, flicker or noise can make the output chatter. A large resistor from OUT to IN+ adds hysteresis (as in the Schmitt-trigger lesson).
Try it on the bench
- Click the LDR to cover it: dark, so the LED comes on.
- Select the LDR and set 20 lux (dusk): with the threshold at 40 % it is just bright enough to stay off. Turn the threshold pot up until it switches.
- Add a 100 kΩ resistor from OUT (pin 1) to IN+ (pin 3) for hysteresis, so it cannot flicker at dusk.
Parts on the bench
- Bench power supply
- Photoresistor (LDR)
- 3 × Resistor
- Potentiometer
- Comparator
- LED
- Digital multimeter
In the course
Zen’s Electronics Design Mastery, module “Op-Amps & Analog ICs”.