Box with a Music Lock
6 Steps
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:

Remove these ads by Signing Up

## 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.
rams666 says: May 2, 2012. 7:49 AM
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
rams666 says: May 2, 2012. 7:49 AM
oh and awesome tutorial btw..
florinc says: Apr 17, 2012. 4:21 PM
The schematic and board files seem to be corrupted, unless they aren't Eagle files.
basil.shikin (author) says: Apr 17, 2012. 11:12 PM
That's odd: I just downloaded them and it opened fine. I am using Eagle 6.1 on OS X.
h951560 says: Apr 22, 2012. 10:08 AM
I was unable to open these in Eagle 5.7, so I updated to Eagle 6.2 and still had the same error.

"Error:

line 6, column 6: This is not an EAGLE file."

I opened and read the html of the files. They are Eagle files alright.
I've tried this on few machines now, all with an updated Eagle, all fresh downloads with the same results.

I'm new to Eagle, so perhaps I've overlooked something?
florinc says: Apr 18, 2012. 11:29 AM
Thanks. They don't open in Eagle 5.3.0 which I am currently using.
florinc says: Apr 17, 2012. 4:22 PM
What software did you use to design the laser-cut parts?
basil.shikin (author) says: Apr 17, 2012. 11:10 PM
Inkscape. It is a pain to use on OS X, but I found it to be the only free alternative.
florinc says: Apr 18, 2012. 11:30 AM
Thanks again. I heard of Inkscape, I was going to use it too (after I learn how).
xFyrios says: Apr 15, 2012. 6:21 PM
That's a really cool idea! Never saw a song lock before! Would be really cool if the lock use a whistle recording, then you can open it up without any other tools such as the piano.

Nice work and congrats on your inventive idea!
basil.shikin (author) says: Apr 15, 2012. 9:10 PM
Theoretically one could whistle the right tune to open the lock. It detects a frequency, not a recording.

Unfortunately, I am not a very good whistler, so not matter how I hard I tried I couldn't get all notes correctly. Hence the piano.
xFyrios says: Apr 18, 2012. 3:17 AM
Well then I guess I will just have to try it out :)
yoyology says: Apr 16, 2012. 11:01 AM
I love this!

I could see it being used as a tuning aid. Tune your instrument correctly, and get a reward! :-)

As for the whistling question, could you get it to recognize the same tune in a different octave?
basil.shikin (author) says: Apr 16, 2012. 8:56 PM
No, it won't recognize different octave: it is configured to detect exact note frequencies, not relative ones.
gertog says: Apr 16, 2012. 12:02 PM
Cant see the video here at work, but reminds me of the door lock in Willie Wonka.
Kiteman says: Apr 15, 2012. 12:18 PM
That's cool.

Will it work if you play the same tune on another instrument, or maybe whistle it?
basil.shikin (author) says: Apr 15, 2012. 12:33 PM
Oh yeah, it should. It detects a frequency. As long as the instrument can produce the same one as the key tune, the box will open.
mmartins-1 says: Apr 15, 2012. 9:26 PM
including voice? (singing?)
basil.shikin (author) says: Apr 15, 2012. 9:37 PM
Well, in theory, yes. You would have to be really good at it: a lock will open only if exact notes are produces. If relative note relationship is correct, but starting note is not D5, the lock would not open.

In other words, if something sings or whistles D5-A4-D5-A4-B4-D5 it would open. If he produces D4-A3-D4-A3-B3-D4 the box wouldn't open.
mikeasaurus says: Apr 15, 2012. 8:18 PM
Cool project, and +10 awesome-points for having Prelude of Light as the lock song
basil.shikin (author) says: Apr 15, 2012. 9:25 PM
Yep, that is correct. I got the idea for the tune from jigarbov, who built something resampling such lock in Minecraft.