You will need the following parts for this project:

  • Raspberry Pi computer. Nearly any model will suffice, old or new…provided it has the camera connector. That leaves out only the Pi 400 and very early Pi Zero units.
  • Your Pi will need internet access to set up the software, so make sure you have either a wired or WiFi network connection for your Pi.
  • Raspberry Pi camera. There are several models now, and most any will do…this is not a demanding project, resolution-wise. Depending on where your camera and Raspberry Pi can be placed inside your box, you might need a longer or shorter camera cable. Pi Zero models use a smaller camera connector and require special cabling.
  • Small box that can fit the Raspberry Pi and locking mechanism inside. I found an inexpensive plain wooden box at a craft store, and finished it with wood stain and polyurethane. Look for a box that has hinges which are screwed in from the outside of the box. Although not terribly secure, it will allow you to disassemble and open the box in case the locking mechanism fails to open.
  • Small servo or lock solenoid for the locking mechanism, depending on how your box can be latched shut.
    • A servo that rotates a latch can work with most boxes that open from the top or side. The software for this project is written to use a servo.
    • A lock solenoid can work with boxes that have a door or drawer. See this locking drawer project for information on using a lock solenoid. As written, the code for this project does not work with a solenoid…this is a “learning opportunity.”
  • Momentary push button that can mount to the box. Depending on how thick your box is, you might need a smaller or larger push button. Improvise!
  • Power supply for the Raspberry Pi and servo or solenoid. Small hobby servos can be powered directly from the Pi’s GPIO header. For larger servos, a 4x AA battery pack is a simple option.
  • Wood, wood glue, and fasteners for building a latch mechanism and frame to support the Pi inside the box. The exact material will depend on your box, but you can see further below how I used 1/4" dowel and thin bass wood to build the frame and latching mechanism for my box.
  • Hookup wires to connect the switch, servo, and servo power supply. Female jumper wires work well for connecting directly to the Raspberry Pi GPIO pins, or you could use the Pi cobbler with a small breadboard.
This project is not meant to be a highly secure container…it’s more a school science project. Face recognition is not perfect and is easily circumvented with a photograph. Don't store valuables in the box!


The box you use for your project will dictate exactly how the Raspberry Pi, servo, and latching mechanism need to be mounted. Read the notes below for tips on how to construct your hardware, based on how I built mine:
Use a box which can fit the Raspberry Pi, servo, and latching mechanism.

Drill a hole in the top or side for the Raspberry Pi camera. I found a 7/16" drill bit was enough for the camera to comfortably fit. Be careful when drilling large holes--work up from smaller bits so you don't crack the box. If you do damage the box, you can generally use wood filler to hide mistakes.

If they aren't mounted there already, consider moving the hinges to be mounted from the outside of the box. This will allow you to disassemble the box in case the hardware fails in a locked position.

Drill a hole in the box to mount the push button. You can see I mounted mine on the back of the box where it can be reached while a user looks into the camera on the top.

Drill another hole to allow power cables to come into the box for both the Raspberry Pi and servo. I found a 1/2" hole was enough to fit a micro USB cable through for powering the Pi. To the left, you can see the hole I drilled in my box next to the push button.
For the latching mechanism, mount a small dowel perpendicular to the side of the box. Attach a right angle of wood to a servo horn so it can act as a latch that swings down to catch the dowel, locking the box. See the pictures to the left to see the latch mechanism and dowel I built in my box.

If possible, mount the Raspberry Pi in the top of the box or near the hole for the camera. You can see how I mounted my Pi to a small board along with the locking servo, and then attached that board to dowels glued in to form a frame in the box top.

A few screws and a smaller board can act as a clamp to hold the servo in place.


The electronics in this project are fairly simple and involve connecting a servo and push button to the Rasperry Pi. If you have never used these devices with a Raspberry Pi, read the following tutorials for a good overview of their usage:

Other than the camera (connecting to the “CAMERA” connector on the Raspberry Pi board), only four or five connections are needed…

Here’s a view of the Pi’s GPIO header (40 pins on most boards, 26 on the early Model A and B). This is with the Pi turned “the tall way,” with the two 5V pins near the top-right corner of the board.

The servo signal comes from GPIO18.

The button connects to GPIO25 and any ground pin (there are several, see diagram, any will do but there’s one conveniently right next to GPIO25).

The software is easily reconfigured to use different pins, if you have other devices wired to the Pi that would conflict.

Small micro servos often work fine powered directly off a 5V pin on the Raspberry Pi.

For larger servos, or for best performance even on small servos, a separate 6V power source is best. In the second image here, notice that there’s no 5V connection to the Pi…but it’s vital that a ground connection is made between the Pi and battery “–” terminal.

These are merely schematic representations…you might use a breadboard or not, either way, whatever approach works best. It’s the connections that are important.

Continue on to learn about how to set up the software for the project.

This guide was first published on Jan 24, 2014. It was last updated on Jan 24, 2014.

This page (Hardware) was last updated on Jan 17, 2014.

Text editor powered by tinymce.