LM393 night light with a ULN2003A
An LM393 compares an LDR with a knob, its open-collector output pulled up by 10 k, and that pull-up drives a ULN2003A that lights a 12 V lamp when it gets dark. There is no microcontroller in it: the simulator solves the 7 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Intermediate Runs in your browser. Free, and no account needed.
The parts retail for about $6.70. On Mokxi they're free.
How it works
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// An LM393 night light that switches a 12 V lamp through a ULN2003A.
//
// No microcontroller. The LDR and a 10 k make a divider on 5 V whose middle
// (column 3) rises as the room gets darker; the knob sets a threshold. The
// LM393's comparator 1 has the divider on 1IN+ (pin 3) and the knob on 1IN-
// (pin 2), so when it gets dark enough that IN+ goes above IN- its output
// (1OUT, pin 1) lets go.
//
// An LM393 output is open collector: it can only pull down. The 10 k pull-up
// from 1OUT to 5 V is what makes the high, and that same 10 k is what feeds
// the ULN2003A's input 1B (pin 1). The ULN2003A then pulls 1C (pin 16) down
// and the 12 V lamp between 12 V and 1C lights.
//
// Things to try:
// - Drag the LDR darker and lighter, past the threshold: the lamp follows.
// - Delete the 10 k pull-up. The LM393 can no longer make a high at all, so
// the ULN2003A's input is never driven and the lamp never lights.
// - Turn the knob: it moves the threshold, so it decides how dark is dark.
//
// Comparator 2 is parked: 2IN+ (pin 5) on ground and 2IN- (pin 6) on 5 V, so
// its output (pin 7) is held on and nothing is left to float.
Parts list
10 parts, plus the jumper wires. They retail for about $6.70; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × Light sensor
- 2 × Resistor, 10k Ω
- 1 × Potentiometer
- 1 × LM393 dual comparator
- 1 × ULN2003A Darlington array
- 1 × Power, 12 V
- 1 × Filament lamp
How it is wired
7 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- 5 V: Resistor, 10k Ω (1) pin 2; Potentiometer pin 1; LM393 dual comparator pin 2IN-; LM393 dual comparator pin VCC; Resistor, 10k Ω (2) pin 2
- Ground: Light sensor pin 1; Potentiometer pin 3; LM393 dual comparator pin GND; LM393 dual comparator pin 2IN+; ULN2003A Darlington array pin E
- Light sensor pin 2; Resistor, 10k Ω (1) pin 1; LM393 dual comparator pin 1IN+
- Potentiometer pin 2; LM393 dual comparator pin 1IN-
- LM393 dual comparator pin 1OUT; Resistor, 10k Ω (2) pin 1; ULN2003A Darlington array pin 1B
- 12 V: ULN2003A Darlington array pin COM; Filament lamp pin 1
- ULN2003A Darlington array pin 1C; Filament lamp pin 2
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.