Music Locked Box
My main project is a music locked box, in which a certain melody must be played on a piano for the box to unlock and open. Each time a note is played correctly, an LED lights up. When the box is unlocked, the speaker inside plays music.
Area of Interest
Lowell High School
Starting out in this program, I expected to learn how to apply my prior knowledge in programming to more tangible projects. I wanted to expand into working with hardware and build technology that can help people and make an impact on society. Not only did I learn more about engineering, but I also experienced working independently and pushing through to achieve my final product.
For my project, I found the idea off of basil.shikin’s Instructables webpage. I did not, however, have the privilege of working directly off of the website. The original webpage’s had no clear schematic or directions as to how the project was built. The materials list was incomplete, and the source code was not supported on my computer’s programs. As a result, I researched for two full weeks for an alternative approach towards building my box. Eventually, I came across an underlying source code and started the project from scratch.
In the future, I would like to have my project recognize chords, which is a sound created by several music notes, and I would also like to add a better quality speaker. I would also like to add other components into my box, such as a mirror or having an RGB matrix on the inside.
There were times where parts of my project, such as my microphone and my servo, did not function properly for days on end and my frustration would get the best of me. However, I learned to be persistent and to appreciate the challenge I chose. With much encouragement from my instructors and fellow engineers, I was able to complete my project, as well as add my own modifications to it, such as the LEDs and the speaker. My time at BlueStamp reminded me why I enjoy working with technology and why I want to major in computer science and engineering when I attend college next year.
Bill of Materials and Build Plan
For my second milestone, I finished the main components of the project by adding the locking mechanism, as well as putting all of the parts inside of the box.
Since my first milestone, I wrote different code to tell the microcontroller to listen for five different frequencies in a certain order, which creates the melody needed to unlock the box.
Next, I added five LEDs. I wrote code to have an LED turn on each time I played a note correctly, letting me know that the microphone picked up the correct frequency and that I may continue on to play the next note. I first wired the circuit on a breadboard, and once it functioned correctly, I soldered all of the wires and LEDs onto a ProtoBoard.
The locking mechanism consists of a servo and a wood screw. The wood screw is placed perpendicular to the servo gear, and if I play the melody correctly, then the servo will turns 90 degrees, becoming parallel to the wood screw and therefore unlocking the box. I also created an option to re-lock the box. In this code, if I play Middle C, then the servo rotates back to its original position.
Before attaching all of the parts to the inside of my box, I drilled five smalls holes – one for each LED light – as well as a hole for the microphone and the charger cable to power the Arduino. The project can be powered from any power source with a USB port.
For my first milestone, I programmed the AtMega microcontroller on the Arduino to recognize 4 different piano notes. If the correct piano notes are played on my iPhone, the note’s name will appear on the serial monitor on my computer.
Sound appears in different sized waveforms, with higher pitches having steeper slopes and shorter periods, while lower pitches have flatter slopes and longer periods. The source code I used takes sound from the microphone and measures the slope and period of the waveform the sound creates. It then converts those values into Hertz, which is a measurement of frequency.
I first tried to get the AtMega to recognize the most common note: Middle C. I played the note on my iPhone, and saw that the frequency readings on my serial monitor were fluctuating greatly. Middle C has a frequency of about 261.6 Hz, and the serial monitor was printing values from 13 Hz up to as high as 5000 Hz. I fixed the higher frequency readings by changing the tolerance variables in the source code so the waveforms would be steadier. As for the lower frequency readings, I placed my iPhone further away from the microphone after learning that if an audio source is too close to the microphone, it detects low frequencies. This is called the Proximity Effect. The resulting frequencies still fluctuated slightly, but it was accurate enough to determine the difference between piano notes.
Once the readings were more consistent, I recorded the different values that the AtMega read for Middle C to determine a range. I, then, wrote an if-statement in the code, which translates into, “If the AtMega reads a frequency between 260 Hz and 265 Hz, print C5 onto the serial monitor.” I repeated these steps for 3 more notes: E4, G4, and C5.
I assembled the miniPOV (Persistence of Vision) for my Starter Project. The miniPOV uses 8 LEDs (light emitting diodes) to create or “paint” an image in the air.
- The miniPOV runs on 3 AAA batteries, which supply about 4.5 volts of power.
- Two electrolytic capacitors stabilize the input and output voltage and filter out any low frequency noise.
- A ceramic capacitor also stabilizes the output voltage and filters out high frequency noise.
- The potentiometer, also known as a variable resistor, changes the resistance of the input into the microcontroller, which tells the LEDs how fast to blink.
- The microcontroller is then followed by 2.2k ohm resistors.
- The microcontroller is not strong enough to power the LEDs, so 3 transistors are used to amplify the current.
- Each LED also has a 47 ohm resistor.
- A ceramic resonator acts as a metronome that keeps time of how fast the LED lights blink.
- Zener diodes keeps the current moving in only one direction, and prevents any short circuiting when the miniPOV is connected to a computer.
- A USB connector allows the miniPOV to connect to the computer and change the image that the LEDs display.
Some issues I ran into while building the miniPOV were desoldering one of the LEDs because it was placed in the wrong orientation and reconnecting broken wires from the battery pack back onto the circuit board. To prevent a short circuit, I also cut the wires shorter to prevent them from making contact with each other. After finishing my starter project, I was able to program the miniPOV to display a new Minecraft themed image.