This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)
This instructable documents how I designed and built a music box that is run with an Arduino( a micro controller).
Step 1: Design the Physical Components
When designing your music box, you need to first think about how you are going to run your music box, and how you are going to control it. For me I started out by designing the parts, and deciding which mechanical components I needed. I realized that there were 4 key elements to my music box, I needed a "music wheel", which is a cylinder, with protrusions on it that are positioned based on the music I wanted to replicate, to spin, and as it spins it should strike another key element, which I called keys. To spin the music wheel, I needed a motor, which is another key element, and the other key element is the support structure for everything.
One of those key elements I had was a stepper motor, and the other mechanical components I ended up using were the Arduino micro controller,a breadboard, four buttons, 3 LED's and 3 220 resistors and all the corresponding jumper wires. The first 5 pictures are of my set up, using all of those components.
The other elements I had to design and 3d print, they are the rest of the pictures, and the stl files are included. The most important and incidentally most complicated part is the music wheel.To design this part I looked at sheet music for the song that I wanted to play, and I looked at 2 different numbers, one is how many beats are in the song, mine had 48, and the number of different notes you want to play, mine had 6. It is important to chose a simple song because the longer a song is the wider the cylinder part of the music wheel will be, the more notes the longer the music wheel is, also I would not chose a song where more than 2 notes are being played at once, because it takes a higher torque, and a typical stepper motor has problems creating that much torque. But if you are set on a certain song, you just have to make a music wheel that is large, and you can simplify a song, like taking out some insignificant pieces, or repetitive pieces, and change the chords to just single notes. Any ways whenever you design the music wheel, you start out by drawing a circle, and dividing that circle by drawing a radius and copying that radius around the center of the circle and copying it as many number of beats that are in the song times.You may want to add a few beats to your song, that way there is space at the beginning f your music wheel. Then you look at the music, and find every beat that the first note is played at, and draw a protrusion, I used a trapezoidal shape but you could use other shapes, like a semicircle , where that note should be using the guidelines you just created (the lines you drew). It doesn't really matter how long the note is, but if the note falls evenly on the beat place the protrusion on the line that correlates with the beat that the note starts on. If the note does not fall evenly on the beat then you have to put it closer to the previous line, however closer it is to the previous beat. For example, if you have a note played on 4-and (that would be and eighth notes distance away for the fourth beat, or midway between 4 and 5) then you would place it midway between the forth and fifth line. Anyways after you have all the times the first note is played drawn, you extrude that as wide as you want to, draw another circle the same size as your first, and extrude that a smaller amount, just to give space between the notes, and repeat those steps for however many different notes you have.
The next important piece is the keys, and that piece is the one I have had the most trouble with. If I were you, I would see if I could find a music box in the same key that you want and use the keys in that, but if not just know that it's not going to sound as good as if it were metal, and that I really don't know how long each "key" should be. To start with, you just draw a rectangle as wide as the music wheel you drew and a bit longer than the length of your longest key. Each "key" is as wide as you extruded your first set of notes, and you cut out a space in between each key as long as the note requires it to be and as wide as you made the space between each note , and you go to the next key. you have as many keys as there are notes. keys should be very thin, less than.075 of an inch, so that they can be bent by the protrusions on the music wheel, and you also need a way to fasten "keys" to your frame so I put two holes in the extra space on the keys, and later just used a screw and a nut to fasten it.
A piece that you might want to add, and could even consider a key piece, is gears. You want a small gear and a larger gear, and the small gear should connect to the spinning part on the motor, and the larger gear connects to the shaft or the music wheel. You might want to add gears, to make the music box play smoother, and to generate enough torque to turn the music wheel when it is playing more than one note at a time.
The next important piece is all of the support pieces, basically the frame and a shaft that connects from the motor to the music wheel . The frame needs to hold everything up at the right height. I did this with a couple of different pieces, frame, keys support, shaft support, and motor housing, and maybe even breadboard stand. So it needs to hold it up so that the center of the cylinder in the music wheel is at the same height as the center of the thickness in keys, and is the center of where the thing on the stepper motor that spins is. Everything should be at a height where the music wheel has plenty of room to spin. I guess that the shaft isn't completely necessary if you designed the music wheel so that it connects directly to the spinning part on your motor. The end of your shaft needs a shape cut put of it that is shaped like the spinning part on the motor that way the two can connect. Also the shaft needs a support piece to hold it up so that it is centered at the same height as everything else. The breadboard stand holds the breadboard up, so that it can sit on top of the arduino.
Anything else you add is not important to the function of the music box, but could make the music box look more finished, or to add extra features, like how I added LED lights, and how I decided to control my music box by pressing buttons. I also added a circuitry housing, with holes cut out f the top for the LED's, and buttons.
Step 2: Design the Control System
So by now you should know how your music box works mechanically, and you should have an idea on what needs to be controlled, so you can start designing a control system. To do this you need to consider what you can control, and how you can control it.
In a music box you can control the speed that the music wheel turns, you can control the direction that it turns, and you can control when it starts and when it stops, so I decided that I was going to use four buttons to control all of these elements, but all that it needs is to be able to do is spin. I also added the LED lights as a component, and you can control when they flash, and which ones flash at one time.
The first five files I included is the code that I used to program my Arduino, and the last file is the same thing, but it is in a wordpad file, and it includes a little bit of information about each section. Musicbox is the main arduino file, and the other files, exlcuding the wordpad file, are functions that Musicbox calls. The arduino code works by taking in input from the buttons, and it controls how the stepper motor runs. You could also use functions from the stepper motor library, to run the motor instead of using the fwdloop, and bwdoop, and the variable they rely on like delay time.
This video explains my code https://youtu.be/k2fetxPYk34 , but there is a small difference in buttons, where when you reset the musicbox you also reset whether or not it goes backwards, and I made the pinStates array smaller by one since I just used 4 buttons, the video will still be as helpful ether way, but the comments within the code explains everything anyways.
Step 3: Build Your Music Box!
By now you should have everything designed, and once your parts are printed, your code is coded and tested, you are ready to put everything together. Here is a link to a video of my completed music box, please note that , as I said before, everything works, except that the part "keys" is not correct https://youtu.be/9aFpJVQ0P2U.
To put my parts together there are four different step that can be completed in any order.
In this step you add the breadboard with all of the circuitry components attached into the circuitry housing, then you place the breadboard stand beneath it, so that it is supported, and you put the Arduino in the remaining space, you can then attach all of the jumper wires to the Arduino, and place the circuitry housing within the frame with the six wires that control the motor placed through the hole in the side.
Simply place the motor inside the motor housing, and have the wires go through the hole in the side like in the circuitry step, place the motor housing in the frame, and connect the remaining wires. If you would like the motor to be more secure in its housing or if you would like the shaft to connect to the motor more securely, you can use a portable 3d printer ( a hot glue gun) to secure everything on site.
To attach keys you need two small screws, and two small nuts and keys support. You place key support beneath keys on the spot that is shaped like key support, and then you add the screw through both holes, and tighten the nuts to the screw. Then just slide both of the pieces into the frame,You will want to adjust the position of the keys on key support so that as music wheel turns it slightly lifts the keys.
First, place shaft support into the frame, then slide music wheel onto the shaft, and place the shaft in the frame. Turn music wheel until the first notes are directly below where the keys should be ( so that they are played first), and connect the end of the shaft to the motor.