For my wedding gift to Lauren, I wanted to make something, obviously, because that’s what I do. I decided on an arduino based music box for a number of reasons. It didn’t require a lot of parts. It was something that I knew I could figure out, but hadn’t tried yet. It was something I could easily customize and make special and meaningful for us, and it was something I thought Lauren would enjoy. Read on for an explanation on how it works, pics, vids and of course, schematics and files!
what it does
The operation of the music box is pretty simple. Flipping the on/off switch sends power from four AA batteries to the Arduino UNO. Pressing the black pushbutton toggles between the three songs, which are represented by the three blue LEDs. Pressing the red pushbutton starts or stops the selected song. The potentiometer controls the volume. The red LEDs that make the heart are divided into 2 groups. When the music is stopped, the heart “beats” by fading in and out slowly. When the music is playing, half of the LEDs are brighter than the others, and they alternate with each tone played. The piezo speaker is mounted under the holes in the box that make a “U”. Check out the video below for a demo!
how it works
The functions of the box are controlled by an Arduino UNO R3. The program, which can be downloaded at the end of the post, waits for the user to press the “start” button and plays the selected song. While waiting, the red LEDs fade in and out using PWM pins on the controller. If the selector button is pressed, the song selection changes and is indicated by one of the three blue LEDs.
The pushbuttons both incorporate a pull down resistor circuit and provide a “high” signal when pressed. The potentiometer is hardwired into the piezo speaker circuit. A schematic for the system was built using Fritzing, which is a great free program that has a library of parts that includes different Arduino boards and other common electronic components.
To make the tones, I got some help from two articles (here and here). It is necessary to add the “pitches.h” library to the Arduino folder, and only then will the “tone” function work. The library and info on the tone function is linked here. Writing the music was relatively easy from that point. Each song consists of 2 arrays, one of note frequencies and one of duration of notes. To play a song, a for loop is used to cycle to each array element and play the given note for the given duration. The Arduino program is provided below.
Some improvements that I could think of right now would include a PCB rather than a prototyping bread board. I had to do this covertly and didn’t have enough time to solder everything. I would also have created a circuit to linearize the pot. Right now it is a standard logarithmic scale pot and doesn’t really start to ramp the volume until around 70-80 percent. Additionally, I would like to have better wire management within the box. Right not, it’s the bird nest of wires you would expect. Finally, I would eventually like to make the box a little bit nicer looking. Perhaps stain it and sand it down to give it a more finished look.
make your own
to make one of these, you will need to get the following parts, as well as have some rudimentary soldering skills. It also wouldn’t be a bad idea to check the circuit with a multimeter if you have one. I also used a drill to make the holes in the box for all the components.
- 5 100 Ω resistors (for the LEDs)
- 2 220 Ω resistors (for the buttons)
- 1 piezo speaker
- 1 10 KΩ potentiometer
- 1 100 μF capacitor (for speaker)
- 1 spst toggle switch
- 2 spst pushbutton switches
- 1 arduino uno R3
- 1 breadboard or pcb
- 1 4 AA battery case (and the batteries to go in it)
- 1 box to house everything
- wire, solder, heatshrink, glue (and/or velcro)
get files here!