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:
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.
For more Detail: Box with a Music Lock using ATMega328P Microcontroller