LM393 Comparator Dark Detector
Single LM393 comparator with an LDR and threshold pot — LED snaps on cleanly when the room gets dark.
Difficulty: Breadboard. Estimated build time: about 25 minutes. Estimated parts cost: about US$1.10. 6-line bill of materials. Compare supplier offers when available. A clean digital dark-detector that introduces the comparator — a part the LM393 is built for and the LM358 op-amp is not.
Build the LDR voltage divider
Connect a 10 kΩ resistor from Vcc (5 V) to one LDR terminal. Connect the other LDR terminal to GND. The midpoint node sits near GND in bright light (LDR resistance is low) and rises toward Vcc in darkness (LDR resistance climbs into the hundreds of kilohms). Wire this midpoint to LM393 pin 3 (non-inverting input, +IN1).
Build the threshold reference
Connect a 10 kΩ trimpot across Vcc and GND — outer pins to the rails, wiper to LM393 pin 2 (inverting input, −IN1). The wiper voltage is your adjustable reference. Start with the wiper at roughly mid-travel (~2.5 V on a 5 V supply); you will tune it after the circuit works.
Wire the open-collector output and LED
LM393 outputs are open-collector — they only sink current, they cannot drive HIGH on their own. Connect a 10 kΩ resistor from Vcc to LM393 pin 1 (OUT1); this is the pull-up. The output node now sits at Vcc when the comparator output is OFF (internal transistor not conducting), and gets pulled to ~0.2 V when the output is ON (transistor sinks). Connect a 470 Ω current-limit resistor from pin 1 to the LED anode, and the LED cathode to GND. The LED lights when the output is HIGH, which happens when +IN1 > −IN1, i.e. when the LDR voltage exceeds the threshold.
Power up and tune the threshold
Connect LM393 pin 8 to Vcc and pin 4 to GND. The unused second comparator's pins (5, 6, 7) can be left floating for this single-channel build. Power on. Cover the LDR — the LED should snap on within a fraction of a second. Uncover it and it should snap off, no flicker. If the threshold is wrong, turn the pot to shift the trigger toward darker or brighter conditions. Sweep your hand slowly past the LDR and watch the LED transition: it is sharp, not a fade. That sharpness is what makes the LM393 the right part for this job.