That piggy bank is looking mighty low-tech these days, and you have to bash it open to get your cash. One piggy, one withdrawal. And then there are those cheesy, tin ”Wild West” lock boxes with the red combination dial. Not only do they lack wow factor, your granny could crack one in 30 seconds.

But stick an Arduino in a wooden box, along with a finger-operated sensor and small motor, and you’ve made a 21st-century treasure chest that’s suitable for a daily diary, petty cash, or even those special Rice Krispies recipes that your snoopy neighbor wants to steal.

There’s no key in this keyless electronic combination lock box; you just move your finger across a small optical window, and it’s “open sesame.” The combination to the lock is a secret movement pattern only you know.

How It Works

The keyless lock box uses a unique optical finger navigation (OFN) sensor as a combination decoder. The OFN sensor works much like an optical mouse, except it’s intended to be used in direct contact with your finger. They are used in handheld devices where a trackpad would be too large, but because they are more expensive than trackballs, they’re not common in consumer products.

Movement across the small surface of the sensor is converted to X and Y distance measurements — up, down, left, and right. Sequences of these movements make up the combination of the lock.

For this project I’m using the Parallax OFN module, which puts a commercial OFN sensor on a breakout board that provides connectors for power (3.3V to 5V), ground, and 6 signal lines. The OFN module uses 2-wire I2C to communicate with a microcontroller, and has additional I/O pins for such things as the momentary pushbutton switch that engages when you push the optical sensor down.

The locking mechanism uses a standard-size R/C servomotor that’s glued into the bottom of the box. To lock the box, the turning servo engages a metal arm attached inside the box’s lid. Turning the other way, it frees the bar, letting you open the lid.

An Arduino microcontroller works as the main brain of the lock box, handling all the communications with the OFN module, controlling the servo, and even making musical tones on a small piezo speaker.

For my box, I used a plain 8″ square cigar box from a craft store — no need to smoke a bunch of stogies. The wood is unfinished; stain or paint to suit. You don’t get Fort Knox with these boxes, but they’ll keep out the casual thief.

Project Steps

Prepare the box.

To make cutting and drilling easier, detach the box lid by removing the top screws in the 2 hinges on the back. Use a hacksaw or razor saw to cut out a small chunk on the left side of the box for the OFN module, just wide enough to fit. Gently pry loose the knockout piece, being careful not to crack the bottom of the box.

Drill 1/8″ mounting holes for the OFN module. To prevent the bit from pushing through and splintering the wood, press or clamp a piece of wood behind the hole while drilling.

Measure and mark the center of a 1/2″ hole in the rear of the box, positioned so you can insert a barrel plug through the hole and into the Arduino’s power jack. First drill a pilot hole with a 1/8″ bit. Follow that with a 1/4″ bit, and finish with a step bit, stopping at the 1/2″ mark.

Referring to Image 2, temporarily position the Arduino in the rear left of the box, on top of 1/8″ nylon spacers. Make sure the Arduino power jack is in line with the rear hole you just drilled. Use a small nail or sharp pencil to mark the location for the 2 mounting holes indicated. Remove the Arduino and set aside.

Make the locking mechanism.

Alignment of the locking parts is critical, so take this step slowly. Use a hacksaw to carefully remove the mounting flanges on both sides of the servo. Thread a 4-40×3/4″ machine screw near the end of the included single-arm servo horn and use a 4-40 self-locking (nylon insert) nut to tightly secure the screw in place.

Attach the horn to the servo and slowly rotate the motor shaft to the center of movement. You’ll make fine-tune adjustments later, so leave off the screw that holds the horn to the servo shaft. Use a hot glue gun to mount the servo in the front left corner of the box.

To avoid unsightly screws on the top of the box, fasten the locking bar to a mounting block made of 1/4″ aircraft-grade plywood or PVC inside the lid. The large surface area of the flat block will enable a strong glue joint.

Follow Image 1 to cut and drill a length of 1/2″-wide × 0.064″-thick brass strip, then cut the block to size, and drill holes matching those in the strip. Fasten the brass strip and block together with 4-40 flat-head machine screws. Bend down the front of the strip at a 15°–20° angle. You can adjust the angle later to achieve better locking action.

Stick a single 1/2″ square piece of florist tape (putty) to the top of the block, and using your best guess, line up the locking bar so it engages with the screw attached to the servo horn. The putty keeps the mounting block in place until you can test the best placement on the lid. Reattach the lid to its hinges.

Calibrate the servo.

Wiring makes or breaks a project. I used pre-crimped male/male and male/female jumpers, 1×1 header shells, and double-long breakaway header pins for robust and easily pluggable connections.

You could theoretically use the pin sides of 3 male/female jumpers to connect to the servo extension cable, but the double-long headers make a stronger friction-fit connection. Snap shells onto the jumpers to make 9 male/male jumpers with shells at one end, and 3 male/female jumpers with shells on both ends.

I needed to add a bypass capacitor to reduce electrical noise from the servo that caused the Arduino to keep resetting itself. Solder a 47µF tantalum capacitor between the middle and one side pin of a 3-pin double-long header.

Be absolutely sure that the + lead of the capacitor is connected to the center pin! These will connect to the servo’s voltage (V+) and ground (Gnd) pins.

To calibrate the servo so that it points in the desired direction, download and unpack the project code, then verify (compile) and upload the ServoCalibrate sketch to your Arduino. Visit the same link for instructions on how to upload programs to an Arduino.

Remove the horn from the shaft and plug in the 3-pin connector you just made, orienting the bypass cap on the black or brown wire (ground) side. Use 3 male/female jumpers to connect the servo and Arduino’s 5V and ground together, and the servo’s control (white or yellow) to Arduino digital pin 8.

Briefly depress the reset switch on the Arduino. When the ServoCalibrate sketch restarts, the servo first moves to its extremes, then centers itself at its midpoint and stops. After it’s done, unplug the Arduino from the PC, then reattach the horn to the servo so that it points straight up, and secure it in position with the small included screw.

CAUTION! Warning! Whoa, Nellie! Do not cross the polarity of the wires or your servo may be permanently damaged.

Align the locking mechanism.

To align the servo horn with the brass strip, reconnect the Arduino to your PC and upload the ServoLock sketch.

Thread the servo cable through the opening in the side of the box, manually move the servo arm toward the front of the box, and close the lid.

Click the reset button to run the sketch and listen for when the servo stops moving. Then test the lock by trying to lift the lid.

Should the servo horn and screw not properly engage over the brass strip — it makes clunking or scraping noises — pop the mounting block off the lid, reposition it, and try again. When you get the position just right, unplug the servo and mark around the block with a pencil for gluing later.

Install the OFN board, speaker.

The OFN module doesn’t have any direct means for mounting, so you need to solder it to a small circuit board that you can then attach to the side of the lock box using 4-40 machine screws and nuts. Cut the board to size and drill 2 holes for mounting.

I used a board with component layout, in which long horizontal bus traces alternate with 3-hole vertical segments. This layout makes it easier for making wire connections on the backside of the board with the copper foil, which is necessary because the OFN module will take up all the space on the front.

Following the Step 7 diagram, drill a 1/8″ hole in the middle of the long trace at the top, to break the connection. This will separate the voltage and ground connections to the OFN module, which is very important.

Then solder the OFN module to the board from the top, non-foil side (the leads will poke through to the foil side). Orient it with the LED on the drilled trace side, along with voltage and ground connections, and the 6 signal lines along the opposite side.

Cut eight 1″ lengths of 1/8″-diameter heat-shrink tubing, and slip one each over 8 of your prepared male/female jumpers. Solder the bare pin end of each jumper to its corresponding connecting point on the foil side of the board 6 signal lines in a row, and the power and ground on the other side, as seen in the diagram.

The pin will poke through; cut it flush with the front of the board after soldering. After all jumpers are soldered, push the heat-shrink tubing over the metal and apply heat to shrink.

Mount the OFN module and board to the side of the box using 4-40 fasteners.

Plug in the 8 jumpers from the OFN into the Arduino digital pins D2–D7 and analog pins A4–A5 as shown in Figure K. Be absolutely sure not to swap pins D6 and D7, or you’ll reverse the power to the OFN and possibly damage it.

Cut the remaining male/male jumper in half. Strip 1/8″ of insulation from the cut ends, and solder them to the terminals of the piezo speaker. Use double-sided foam tape to mount the speaker to the bottom of the box, and attach the 2 jumpers to Arduino pins D11 and D12. The innards of your lock box should look like the 2nd image.

Program it.

Reconnect your Arduino and then verify and upload the LockBox sketch. It includes several files in the same folder; make sure they remain in the folder or the sketch won’t work. You need version 1.0 (or later) of the Arduino IDE, or the sketch will not compile.

For now, keep the lid open so you can see what happens when the box locks and unlocks. Keep the Arduino connected to the computer and open the Serial Monitor window (Tools menu) so you can review the debugging messages.

On Arduino startup or reset, the servo should go into lock (straight up) position, and you should see “Device ready” in the Serial Monitor window. If instead it reads, “Device not found,” it means the Arduino can’t find the OFN module, and you should recheck the wiring.

Swipe your finger across the sensor of the OFN module sensor, then press it down. You’ll hear a series of tones indicating a bad combination entry.

Move your finger across the sensor again, this time using the pre-stored combination: Left-Right-Left. Click down the sensor, and this time the lock opens. After 7 seconds the lock automatically closes.

See the comments in the LockBox sketch on where to change the combination. It can be any length sequence of swipes up, down, left, and right. Once the lock is reprogrammed, unplug the Arduino from your computer. Reattach the Arduino to the bottom of the lock box.

Now’s a good time to glue the locking bar mounting plate permanently to the lid. Hot glue or wood glue works best. After the glue sets, stash your best secrets in your new keyless combination box. Whenever you need access, let your fingers unlock the mysteries within.

Conclusion

Lock Box Power!

The Keyless Lock Box is designed to use external power for unlocking, but it can sit in a locked state for indefinite periods without any power. To power the lock and open it, insert the plug into the hole in the back, enter the combination, then lift the lid.

The box will automatically relock after 7 seconds. If the lid is still open, you can relock the box by manually pushing the servo arm toward the front of the box, pressing the Arduino’s reset button, and closing the lid. When the sketch restarts, it automatically moves the servo to its lock position. You may then remove the power plug.

If you forget the combination or can’t get it to work, here’s a “secret” override procedure that will briefly unlock the box:

Unplug power to the Arduino. Press and hold down the OFN sensor while you plug the Arduino back in. Quickly open the lid when you hear the servo move to its unlock position. You’ll have only 1.5 seconds before the servo relocks the box.

You can remove or comment out the override code in LockBox.ino if you don’t want this behavior.

Keep the box looking good by applying paint or finish to the bare wood, starting with a base coat. For a cleaner look, remove the clasp in front of the cigar box, and fill in the holes with wood putty. Sand for a smooth finish. Or replace the clasp with something fancier.

This project first appeared in MAKE Volume 32, page 110.