A simple electronic lock circuit walkthrough — components, circuit connections, working principle, password input, logic operation, wiring steps, and an interactive electronic lock you can explore in the browser.
Security electronics · CD4017 sequence lock
There's no memory in this circuit and nothing stores the code. Each key is simply wired to the counter step it belongs to — press one out of turn and it has nowhere to send its signal.
Enter 3 · 1 · 5 · 2 to open it · tap S7 to lock it again
Status: locked — 0 of 4 entered
Parts bin
One counter, a handful of buttons and a transistor to do the heavy lifting. Test with an LED first and only fit the solenoid once the sequence behaves.
Operating principle
The clever part isn't the chip. It's that each key is wired to the one moment it's allowed to work.
A CD4017 keeps exactly one output high and steps to the next on every clock pulse. Normally the outputs are treated as results. Here they're treated as permissions: each correct key sits between the output for its position and the clock input.
So key 3 only does something while Q0 is high — that is, only as the first press. Push it later and the output feeding it is low, so closing that contact connects one dead wire to another and the counter doesn't move. The order is enforced by the wiring, not by any decision being made.
The wrong keys don't need to be clever either. They go straight from +V to the reset pin, which drops the counter back to Q0. Progress isn't just paused by a mistake, it's erased — someone guessing has to start over every time.
The code is the wiring. Move Q0's wire to a different key and that key becomes the new first digit. Nothing else changes.
Longer codes just use more outputs — Q0 through Q5 for a six-digit code, with the unlock taken from Q6 instead.
Repeating a digit is the one thing this design can't do. Two outputs would have to share a key, and pressing it once would clock the counter twice.
More keys make it stronger: with six keys a four-digit code is one of 1,296 — with ten keys it's one of 10,000.
Assembly
Five steps — get the counter resting reliably at Q0 before wiring a single key, or every later fault will look like a keypad problem.
Seat the counter: pin 16 to +V, pins 8 and 13 to ground. Run R1 from the clock input (pin 14) to ground and R2 from reset (pin 15) to ground so neither pin can float. Add C1 from +V to pin 15 — that brief charging pulse at power-up forces the counter to Q0 instead of a random output.
This is the whole idea. Wire Q0 to one side of key 3, Q1 to key 1, Q2 to key 5, Q3 to key 2 — and tie all four of their other sides together into the clock input. A key can only pass a signal through if the output feeding it happens to be high, which means only the right key at the right moment advances the counter.
Take the remaining keys — 4 and 6 here — and run them from +V straight to the reset pin. Pressing one clears the counter to Q0 instantly, so a wrong key doesn't just fail to advance, it throws away whatever progress had been made.
Q4 goes high only after all four correct keys have landed in order. Run it through R5 to the base of Q1, put the solenoid or relay coil between +V and the collector, and the emitter to ground. D1 sits across the coil, cathode to +V, to absorb the reverse spike when the coil switches off.
Wire S7 from +V to the reset pin as well — that's your lock button. Now test slowly: press 3, 1, 5, 2 and the lock should open. Press 3, 1, 4 and it should be back at square one. Try the sequence in the wrong order and confirm nothing happens.
If it misbehaves
Floating pins cause the first problem and missing gate wires cause the second. Check both before suspecting the chip.