Digital Combination Lock in Logisim-evolution: Keypad FSM and Lockout Guide
Direct Answer: Building a Digital Combination Lock in Logisim-evolution
A Digital Combination Lock in Logisim-evolution is a sequential Finite State Machine (FSM) that validates 4-digit keypad entries one digit at a time against a stored PIN (such as 4-2-9-1). Using a 16-to-4 Priority Encoder paired with a rising-edge Key_Valid pulse detector, each button press compares the entered 4-bit digit against the expected digit for the current step (S0 → S1 → S2 → S3). All-correct sequences assert Unlocked = 1 (Green LED), while wrong entries increment a 2-bit 3-Strike Lockout Counter that triggers an Alarm LED and disables keypad input after three failed attempts.
Recommended Hardware Kits and Debug Instruments
Prototyping a physical keypad lock teaches real-world embedded security principles, including mechanical button debouncing and keypad scanning:
Elegoo Electronics Component Starter Kit
Includes tactile pushbuttons, 4×4 membrane keypad options, green/red LEDs, active alarm buzzers, and breadboards.
USB 8-Channel 24MHz Logic Analyzer
Inspect keypad row/column scan signals and verify clean single-pulse debouncing in PulseView.
State Architecture for a Secure 4-Digit Combination Lock
To prevent attackers from guessing digits individually by watching when the lock resets early, a secure design collects all 4 digits into a 4-stage shift register (or compares them silently while recording an Error_Flag) before revealing Pass/Fail at the end of the 4th digit:
| State | Operation on Key_Valid | Next State | Indicator LEDs |
|---|---|---|---|
| S0 (Digit 1) | Compare Key == PIN[0] → latch mismatch into Err_FF |
Advance to S1 | Red Locked LED On |
| S1 & S2 (Digits 2–3) | Compare Key == PIN[1/2] → OR into Err_FF |
Advance to S2 / S3 | Red Locked LED On |
| S3 (Digit 4 Check) | If Key == PIN[3] & ~Err_FF → Unlock! Else Fail++ |
S4 (Unlocked) or S0 / S5 | Evaluate Pass/Fail |
| S4 (Unlocked) | Wait for Lock_Btn (or 10s auto-relock timer) |
Return to S0, clear Fail Counter | Green Unlocked LED On |
| S5 (3-Strike Lockout) | Fail_Count == 3 → Ignore keypad until Admin_Reset |
Stay in S5 | Flashing Alarm LED |
Four Stage Digital Lock Assembly in Logisim
Phase 1: 10-Button Keypad Encoder and Pulse Detector
Place 10 Button components labeled 0 through 9 and wire them into a 16-to-4 Priority Encoder. Pass the encoder’s GS (Group Signal) output through a rising-edge detector (D Flip-Flop + GS & ~Q AND gate) to generate a crisp 1-cycle Key_Valid trigger.
Phase 2: Stored PIN Multiplexer and 4-Bit Comparator
Store your 4-digit secret code in four 4-bit Constants (or writable Registers for user-changeable PINs). Feed them into a 4-to-1 4-bit MUX selected by the 2-bit digit counter D_Idx[1:0], and compare against the keypad’s 4-bit bus using a 4-bit Comparator.
Phase 3: Silent Error Latch and Unlock Flip-Flop
Latch any mismatch (A != B) during digits 0–2 into an Error D Flip-Flop. On the 4th digit (D_Idx == 3 & Key_Valid), if both A == B and Err_FF == 0, set the Unlocked SR Flip-Flop; otherwise pulse the Fail Counter.
Phase 4: 3-Strike Lockout Counter and 7-Segment Feedback
Use a 2-bit Counter tracking failed attempts. When Fail == 3, disable Key_Valid with an AND gate and drive a flashing Red Alarm LED until an Admin_Reset key clears the counter.
Frequent Traps in Digital Combination Lock Design
Trap 1: Leaking Correct Digits Early
Problem: Resetting immediately on a wrong 1st digit lets an attacker brute-force a 4-digit PIN in 40 tries instead of 10,000.
The Fix: Always collect all 4 digits silently via Err_FF before announcing Locked/Unlocked.
Trap 2: Clocking Directly from Button Pins
Problem: Wiring keypad buttons straight into flip-flop clock pins creates combinational clock skew and race errors.
The Fix: Keep all registers on one master Clock and use Key_Valid strictly as a synchronous enable.
Trap 3: Missing Key_Valid Edge Detection
Problem: Holding key 4 across 4 clock ticks enters 4-4-4-4.
The Fix: Insert a D Flip-Flop rising-edge detector on GS.
Trap 4: Forgetting to Clear Err_FF Between Attempts
Problem: Once Err_FF latches a mistake on attempt 1, it stays 1 forever and blocks valid PINs on attempt 2.
The Fix: Clear Err_FF synchronously whenever D_Idx wraps back to 0.
Curriculum Progression from Digital Locks to Security Hardware
Frequently Asked Questions About Digital Locks
How can users change the password without rewiring gates?
Replace the 4-bit Constants with four 4-bit Registers enabled only when Unlocked == 1 and a Set_New_PIN mode switch is active.
How do I implement a 3-attempt lockout timer?
Increment a 2-bit Fail Counter on every failed 4-digit attempt; when Count == 3, disable Key_Valid until an admin reset or a 30-second countdown completes.
How do I display asterisks or entered digits on 7-segment displays?
Store each entered digit into four 4-bit display registers as D_Idx advances, or light segment g (a dash -) on each digit position to mask the PIN.
Can I use Logisim’s TTY or Keyboard component for input?
Yes. Wire a Keyboard component (Input/Output) to compare ASCII digits (0x30–0x39) directly against stored ASCII PIN bytes.
