EngineeringMaker Lab

Build guide

Featured project

Password Lock

Combine a 4x4 matrix keypad, status LED, and servo into a complete input-process-output system. You will scan rows and columns, store user input, compare a passcode, and control a physical lock mechanism.

Last updated

Build Time
90-120 minutes
Estimated Cost
$20-$35
Skill Level
Advanced
Raspberry Pi PicoRaspberry Pi PicoKeypadServoSecurity

Project overview

What You Will Build

1. Test the keypad by itself

Wire the four row and four column pins. Run a small scan test or print each detected key before connecting the servo.

2. Add status feedback

Connect the green LED to GP15 through a 220 ohm resistor. Confirm it lights independently when GP15 is high.

3. Connect the servo safely

Power the servo from regulated 5 V, connect the grounds, and connect only the servo signal to GP16. Test open and closed angles before attaching a latch.

4. Run the lock program

Enter 2580 followed by #. The LED should light and the servo should unlock for three seconds. Press * to clear a partial entry.

5. Tune the mechanism

Mount the servo horn so neither locked nor unlocked position forces it against a mechanical stop. Treat this as a learning model, not a security device.

Skills

What You Will Learn

  • Scan a matrix keypad without a dedicated interface module
  • Build and compare a multi-digit input string
  • Coordinate status feedback and servo movement
  • Separate logic errors from wiring and power faults

Preparation

Parts Used

Gather these components before starting the build.

  • Qty: 1Raspberry Pi PicoMicroPython installed
  • Qty: 14x4 matrix keypadEight-pin membrane type
  • Qty: 1SG90 micro servoLock actuator
  • Qty: 1Green LEDAccess feedback
  • Qty: 1220 ohm resistorLED current limiting
  • Qty: 1Regulated 5 V supplyServo power
  • Qty: 12Jumper wiresKeypad and outputs

Verified resource

Complete Official Build Guide

An exact official build guide for this project is still being verified.

Original preparation

Original Code and Preparation Notes

This independently written example summarizes the programming concept used by the project. Compare wiring and pin choices with the verified official guide, when available, before running password-lock.py.

password-lock.pypython
from machine import Pin, PWM
from time import sleep

keys = (("1","2","3","A"), ("4","5","6","B"),
        ("7","8","9","C"), ("*","0","#","D"))
rows = [Pin(p, Pin.OUT) for p in (2, 3, 4, 5)]
cols = [Pin(p, Pin.IN, Pin.PULL_DOWN) for p in (6, 7, 8, 9)]
servo = PWM(Pin(16)); servo.freq(50)
status = Pin(15, Pin.OUT)
entered = ""; password = "2580"

def angle(degrees):
    pulse = 500 + degrees / 180 * 2000
    servo.duty_u16(int(pulse * 65535 / 20000))

while True:
    for r, row in enumerate(rows):
        row.high()
        for c, col in enumerate(cols):
            if col.value():
                key = keys[r][c]
                if key == "#":
                    if entered == password:
                        status.high(); angle(90); sleep(3); angle(0)
                    status.low(); entered = ""
                elif key == "*": entered = ""
                else: entered = (entered + key)[-4:]
                while col.value(): sleep(0.02)
        row.low()

Problem solving

Common Beginner Mistakes

Keys produce the wrong characters

Check the keypad pin order and adjust row or column pin lists to match its datasheet.

The servo resets the Pico

Power the servo from a separate regulated 5 V source and connect the supply ground to Pico GND.

One key registers several times

Keep the release-wait loop and add a short debounce delay after each accepted press.

Common questions

Frequently Asked Questions

Is this suitable for real security?

No. It is an educational prototype; the passcode is visible in source code and the mechanism is not hardened.

How do I change the password?

Replace the password string and save the updated program to the Pico.

Can I add a display?

Yes. An I2C LCD can show masked input

Project complete

Ready for LED Night Light?

Build an automatic LED night light that turns on when the room gets dark.