Dark detector
An op-amp comparator, an LDR and a pot light an LED when the room goes dark, no board, on a half-size breadboard. There is no microcontroller in it: the simulator solves the 6 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
IntermediateRuns in your browser. Free, and no account needed.
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.
// A dark detector: an op-amp comparator, an LDR and a pot. No board.
//
// The 10 k from 5 V and the LDR to ground make a divider. In the light the
// cell is a few hundred ohms and the middle sits near 0 V; covered, the cell
// is tens of kilohms and the middle rises towards 5 V.
//
// The op-amp compares that middle (IN+) with the pot's wiper (IN-). With no
// feedback its gain is the whole 100 000, so the output slams to one rail or
// the other: up when the middle is above the wiper, down when it is below.
//
// It does not quite reach the rail, and that is the op-amp being honest. It
// drives through 100 ohms of its own output resistance, so with 220 ohms and
// the LED hanging on it the loop is 100 + 220 + the LED's own 15, and
// (5 - 1.8) / 335 is 9.6 mA. The output sits at 4.0 V rather than 5, the LED
// lights at about half brightness, and the probe on the resistor says so.
//
// Things to try. Drag the slider on the cell towards dark and find the point
// where the LED comes on; turn the knob and the point moves. Swap IN+ and IN-
// and it becomes a light detector. Add a 1 M from OUT back to IN+ and it
// stops flickering at the threshold: that is hysteresis, and it is what the
// night light sketch does in software.
Parts list
9 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Half breadboard
- 2 × Power, 5 V
- 1 × Light sensor
- 1 × Resistor, 10k Ω
- 1 × Potentiometer
- 1 × Op-amp
- 1 × Resistor, 220 Ω
- 1 × LED, red
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 Ω pin 2; Potentiometer pin 1
- Ground: Light sensor pin 1; Potentiometer pin 3; Op-amp pin GND; LED, red pin C
- Light sensor pin 2; Resistor, 10k Ω pin 1; Op-amp pin IN+
- Potentiometer pin 2; Op-amp pin IN-
- Op-amp pin OUT; Resistor, 220 Ω pin 1
- 5 V: Op-amp pin V+
- Resistor, 220 Ω pin 2; LED, red pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.