Music Box
This is my music box, a final project for my computer engineering course. The project itself is incomplete and has a lot of room to improve, which I will explain in the later steps. The project itself is a simple Arduino project and will only require some additional resources to complete. The music box basically acts like one of those beat boxes you can see online, where you have a large array of keys and each key plays a note. While this loses some of the functionality of those ones, there is still a lot of fun to be had with my music box. I will not be explaining basic concepts like how to wire a button, only where to wire each pin of a component.
Supplies
- Keypad x1
- LCD 16x2 x1
- Rotary Encoder x1
- Rocker Switch x1
- Push Button x1
- Arduino x1
- Breadboard x1
- Speaker x1
- 4AA Battery Holder x1
*Note: You can buy a lot of these things in a kit style to save money; often kits include an LCD display, push button, Arduino, and breadboard, which you can find on Amazon for the price of 1.5 Arduinos. Additionally, while you can do this with just the Arduino and the breadboard, if you are using a box, it makes it easier to connect to the Arduino if you don't have long wires.
Shell
The first step is to take a box or any cardboard, for that matter, that you feel is the right size and isn't too big or too small to fit all the components onto. Feel free to move the components around in a way that feels right to you, but if you're following mine, cut out holes in the exact same locations, with the big rectangular hole on top of the box for the LCD display, the small slit below it is for the keypad, the hole to the left of the LCD is for the button, the hole on the back is for the rocker switch, the one on the right side is for the rotary encoder, and the red circle at the front is for the speaker to be attached on the inside. That red circle is just cut out of cardboard.
Testing
The second step, while not the most interesting, is important: ensure all of the components work correctly, whether it be testing the button to make sure it can output or if the speaker takes in input by playing a tone on it. Ensuring all your components work can prevent confusion later down the line, when the circuit stops working, for instance.
Adding Your Components
Whether you decide to wire it first or glue it in first is your choice. I personally glued it first and then wired it in second. I know it's strange; it's just a personal preference. You can either use superglue, tape, hot glue, or even screws where applicable to attach the components in the corresponding spots. The Arduino, breadboard, and battery holder need to be able to fit inside with one another without overlapping. The keypad needs to be outside as well as the LCD display, the rotary encoder, and the rocker switch; all need to be usable from outside the box. The speaker module needs to be placed inside the box facing out behind the red circle.
Wiring Your Components
Once you've finished securely attaching all your components to the appropriate locations, it's now time to start wiring them. Follow this list below if you want to make sure the code provided later still works. This is also where it's a good idea to attach ground and power from your Arduino to your breadboard.
LCD 16x2 Display:
Connect SDA to Analog Pin 4 (A4) and SCL to Analog Pin 5 (A5).
Connect VCC to Power (5V) and GND to Ground.
Keypad:
Connect the leftmost pin when the keypad is facing up to pin 11, then connect each subsequent pin to the Arduino going left from pin 11, so the next pin attaches to pin 10 on the Arduino and so on.
Push Button:
Connect the push button input to pin 12 of the Arduino. Then connect the other two appropriate pins to ground and power, respectively, ensuring power goes to the push button through a 10K resistor.
Speaker Module:
Connect the ground side (usually the black wire) to ground and the power side (usually the red or blue wire) to the A0 pin on the Arduino.
Rotary Encoder:
Connect VCC to power (5V), GND to ground, DC to pin 3 on the Arduino, and CLK to pin 2 on the Arduino.
Rocker Switch/4AA Battery Holder:
Connect the black wire of the 4AA battery holder to ground and the red wire to the side with an O symbol on the rocker switch. Once you've connected the rocker switch to power, connect the wire side with an I symbol to the VIN pin of the Arduino to supply the Arduino with power.
Code
If you've now ensured all the components are attached, working, and wired appropriately to the Arduino/breadboard, it's now time to code. I have attached a copy and pastable code below, which you can open via Arduino Cloud or IDE. Ensure you have downloaded the Keypad library by Mark Stanley and Alexander Brevig as well as the LiquidCrystal library for the LCD display by Hans-Christoph Steiner.
Next Steps
Once you've uploaded the code to an Arduino, test the machine to ensure it works. If power is not being delivered, you most likely did not wire the power supply to the rocker switch and to the Arduino correctly. If you want to do more, feel free to tinker with the rotary encoder, as the code is simply commented out. If yours works properly, you can use it as a volume adjuster or even a secondary control mechanism for something like a menu system. I was not able to use the rotary encoder because the component itself broke down on me.