top of page

Button Activated Lock Box

Your Mission:
Make your own digital safe, powered by Raspberry Pico


Someone keeps stealing your precious money and cookies. You need to construct a concept lock box to keep your valuables safe from intruders.

The box needs to open and close with the push of a button. It needs to run on only one source of power, everything must be contained inside the box except for the button.


A simple servo can prevent a lid from opening and closing.

A simple pushbutton can tell a programmed chip to rotate that servo. The servo is small and needs at least 3v of power while the programmable chip you will be using can also run on 3v. Program a pin on the board for the pushbutton and another to control the servo using electrical pulses to rotate it clockwise and counterclockwise. See details below.


Good luck!


Learn how to code in the MicroPython language

Code a servo to lock/unlock this box with the push of a button

Everything you need

  • Raspberry Pico

  • CR2032 3V Lithium Cell Battery

  • Dupont style reusable wires

  • Soldering Iron (630°C & Solder)

  • Pushbutton

  • TowerPro Micro Servo (9g)

  • 3D Printed Case, Lid, Hinge Caps, CR2032 Case

  • Small paperclip or similar size solid wire

  • Breadboard (for testing)

I Need These Materials

Wiring and test on a breadboard:


Pro tip: Notice the servo, Pico and battery all share a common GROUND (GND) connection. This is so the Pico and the Servo can agree upon what 0v is.

from machine import Pin, PWM
import utime

MID = 1500000 
MIN = 1000000
MAX = 2000000

pwm = PWM(Pin(15))
button = Pin(16, Pin.OUT)


while True:      
    button_state = button.value() 
    if button_state == True:  
        if lock_state == False:

        if lock_state == True:

        lock_state = not lock_state
        print("Button Pressed " +str(bool(button_state))) 
        print("Lock State " + str(lock_state)) 

Need more?
Follow these three for the next mission.


bottom of page