Summary of Box with a Music Lock using ATMega328P Microcontroller
This article details a DIY music lock project where a box opens only after the correct tune is played. The author explains the theory of sound frequency detection and compares the Fourier transform with the more efficient Goertzel algorithm, which targets specific frequencies to identify notes like D or C. The project utilizes an ATMega328P microcontroller for circuit design and features a custom box enclosure to house the system.
Parts used in the Music Lock Project:
- Microphone
- ATMega328P Microcontroller
- Custom Box Enclosure

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
- How does the lock detect the correct tune?
The lock uses an algorithm to analyze microphone data and determine if specific target frequencies corresponding to musical notes are present. - What algorithm is best for identifying one target frequency?
The Goertzel algorithm is used because it efficiently identifies a single target frequency rather than analyzing all frequencies. - Does the project use a Fourier transform?
The article mentions the Fourier transform as a method to transform microphone data into frequencies but notes the Goertzel algorithm is more efficient for this specific task. - What hardware controls the logic of the music lock?
An ATMega328P microcontroller is used to handle the circuit design and processing for the project. - Can you hear a note if the nerve is tickled 130 times a second?
Yes, if the nerve is tickled 130 times a second, one hears the note "C". - Why is the Goertzel algorithm preferred over Fourier transform here?
The Goertzel algorithm is preferred because the project only needs to know if a specific note frequency exists, not the strength of all frequencies. - What triggers the box to open?
The box opens only if the correct sequence of notes is played on the piano. - Is the Goertzel algorithm used in telephones?
Yes, it is used in telephones to recognize the tones produced by buttons pushed on a keypad.
