Box With a Music Lock




There are a lot of locks out there. There are locks open with a key, with a combination of digits, with various bodily parts, or with a correct geolocation. I decided to make a lock that I have not seen yet. Since I am learning to play piano an idea for this project came quite naturally. I decided to make a box that would open only if a correct tune is played.

This instructable talks about an algorithm that I used, circuit design and box design. But first, here is a video that illustrates how it all works together:

Step 1: Music Theory

Before getting into the details of project design, allow me to give a brief 101 on the theory behind tune detection.

As you might know sound is just air pushing against nerves in our ears. An air wave pushes – a nerve tracks the irritation. What we hear as a note are actually these air pushes with a constant period. In other words, if the nerve is tickled 130 times a second one hears a "C".
Devices that detect notes try to figure out how many times a second its microphone was "tickled", what was the frequency. Figuring out what note corresponds to what frequency is simple because there are "frequency → note" tables.

There are several algorithms that transform data read from a microphone into a frequency. The most prominent is a Fourier transform. The idea is quite simple: an input to is how strong was the air pushing in any given point in time. An output is how much of each frequency was contained in the input.  I think it is best explained by a picture attached to this step.

It is obvious that you can detect a tune using this algorithm. However, a music lock project can be a little more efficient. We don't really need to know how much of each frequency the input contained. We just care if the input had a frequency of a note we are detecting. For instance, if the first note of our unlock sequence is D, we don't care how much A's or B's were in the input. We just need to know if D was there.
This is when Goertzel algorithm comes in handy. It is used to identify one target frequency. As a matter of fact, it is used in telephones to recognizes the tones produced by the buttons pushed on a telephone keypad. 

Step 2: Components

I chose following components for the project:

ATMega328P with 16Mhz crystal is device's core. I chose this part because it is very easy to work with.

Electret Microphone with OPA344 opamp. Both are sold together from Sparkfun. Output from this device could be fed directly  into the analog input of the ATMega.

Spektrum SPMAS2000L Servo  this servo opens and closes box's lock mechanism. It needs 3.3V and delivers a linear motion of about a centimeter. It uses regular servo control interface.
As far as I understand such motors are usually used in airplane models to control ailerons. More could be read on the manufacturer's website.

TPS2020 Switch is a great switch with a very low quiniscent current which is less then 10 μA when the switch is off. This switch will control power to the lock servo.

LM2936Z Regulator is a 3.3V linear regulator with low quiescent current. It is precisely what we need because the box would be battery-powered.

MAX1555 is a battery charging circuit that can turn on a little LED when the battery is full.

Step 3: Circuit Design

There is nothing especially complicated about the device itself. Full schematic could be found here. Attached to the step is a simple diagram that explains basic components.

It was not trivial to put everything into a small box. Since I wanted to manufacture everything at home, multi-layered circuit design did not quite work. So, I had to fake a multi-layered board with an Arduino shield-like circuit. Blue lines on the attached schematics represents bottom layer, red lines are connections via shield headers.

I used photoresist method to etch the actual board. 

Step 4: Box Design

Project enclosure consists of a trunk and small walls around the motor compartment. I bought an unfinished walnut trunk from amazon. I deceived to finish it myself. Walls and lock components were ordered from Ponoko: I just had to send them an SVG design of components I needed and they would laser cut it from a thing wooden board. My design could be found here. It took about three weeks to manufacture the enclosure.

I have applied two layers of Minwax wood finish and a layer of their Polyurethane to protect the surface. Although the process was quite strait forward, I must confess that I have underestimated importance of sanding the surface before applying wood finish. Spots that did not get enough sending are quite visisble.

A picture of a lock mechanism is also attached to this step.

Step 5: Software

Full source code could be found in this repository.

Program logic follows a simple flow that checks if the box is closed. If so, it attempts pattern recognition. If it takes too long to discover the pattern device goes back to sleep. If the pattern is detected the lock is opened.

If device is woken up when the lid is open it waits until the lid is actually closed. Once that happens it shuts the lock.

Step 6: Result

The circuit board fit the project enclosure without any issues.

I took the box to several friends of mine: correct tune was detected when played on different pianos: grands, uprights and digital once. Detection resolution is a halftone.

I would be happy to receive any commands or answer any questions about this project.

Make It Real Challenge

Participated in the
Make It Real Challenge



    • Beauty Tips Contest

      Beauty Tips Contest
    • Classroom Science Contest

      Classroom Science Contest
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    40 Discussions


    Question 3 months ago

    If so I would be very interested in purchasing the item from you. Also can the tune be changed over time or is it a wired in sort of thing?


    Question 3 months ago on Step 6

    Can you make this “Music Lock” in a much larger scale? Say to open a secret passage if the right set of notes were to be played on a near by piano?


    Question 5 months ago

    Hi, I am wondering how you connected the servo motor to your board to make it unlock and lock the box. I am working with a 2.9g Linear Long Throw Servo.


    Question 7 months ago

    Do you still have this box?(or willing to make another one?) I am setting up a gift for my friend and this would be ideal for it. Please contact me at


    Question 8 months ago on Step 3

    I want to build a box like this one but as I want that it can be open be anyone who know the trick and I want to put the box outside, I think it's better if the user come with a battery or powr bank. Do you think this kind of adaptation is possible ?
    Tnaks a lot for your time and your answer


    Question 11 months ago on Step 6

    Hi Basil,

    I’m new to this type of project but I am wondering if your set up can recognize a three note chord as opposed to a single note? Is it as simple as recording the three notes in unison (as a chord)?

    Thank you for sharing your project!



    Question 11 months ago on Step 6

    Hi, I found your project very well done and the result is amazing. Do you still have that music lock box? I would like to buy it or a different one still working the same way. I organize escape rooms and that tool would be perfect for them. Can you please contact me at Thank you so much!


    1 year ago

    Hello, I am actually looking to hand carve a box with carved notes on the side to play and open the Box. I really don't know anything about wiring. Im willing to buy it if you have it for sale. One think I'm not sure about, if the battery runs out how do you open the box. And if so is the solution to place a charging port on the bottom of the box.


    2 years ago

    Hi, is there someone, who can remake this code for Arduino?

    1 reply

    2 years ago

    So quick question, I don't know my head from my rearend when it comes to stuff like this. How realistic is it for me to actually try and build this thing? Is there a lot I would have to learn first? Where would I start?


    2 years ago

    Any chance you could provide the software again, and perhaps an
    updated list of necessary components? A lot of those items are
    discontinued. I've never made anything like this before, but I really
    want to give it a try!


    4 years ago

    Any chance I could buy the circuit board for this? Or the completed circuits? We are designing an escape room and a box that opened by music notes would be amazing! We have been looking for something like this, but it just doesn't exist commercially. We would pay you for you time. Thanks in advance.

    2 replies

    Reply 3 years ago

    Did you have any luck finding someone to sell you one of these? I too would be interested in building one


    Reply 3 years ago on Introduction

    cool i did one of those escape rooms the other day! where is yours? and were u able to build this box ? was it hard. teaching my niece piano, wanted to make/get something like this for her.

    I made the box :L (:L is someone eating noodles with a noodle hanging from his mouth)


    5 years ago

    Hi basil. This is awesome. What board board would you recommend if we didn't want to etch it ourselves?


    7 years ago on Introduction

    if i played that tune on my ocarina not only will the box open but i can travel time. now i want to make a box like this for a mini replica of the master sword