Arduino Digital Piano

by sethhsiemens in Circuits > Arduino

925 Views, 10 Favorites, 0 Comments

Arduino Digital Piano

Complete project.jpg
F8L1WYFLVZ9D5N7.png
Arduino Digital Piano Demo

I made a digital piano keyboard using a Mega 2560, some buttons, a digital amplifier, and a 2" speaker. I though it would be fun to construct a little instrument that I could make music on! The buttons are arrayed the same way piano keys would be, and there is also a knob for volume control. Pushing the yellow button changes the tone that is played through the speaker. Note that there is some high-frequency signal that the speaker picks up, so it can sound a little whiny if no sound is being played. This problem could be fixed with some low-pass filtering of the audio signal before it hits the amplifier. I had a lot of fun building this project, and there is much more that could be experiment with in this setup!

Supplies

1x Mega 2560 (I used one from Elegoo, but any would do)

1x PAM8403 Digital Amplifer Module

1x 2" Gikfun 4Ohm 3W speaker (any 4Ohm 3W speaker would do)

17x tactile push button switches

1x larger tactile push button switch

1x full size solderable breadboard (mine is from ElectroCookie. If using a different brand check the dimensions)

1x 10 kOhm potentiometer

3x 330 kOhm resistor

2x 5/32" screws that are 1/4" long

2x spacers that are ~3.4 mm tall and can fit a 5/32" screw

1x small soldering board for easy resistor soldering

Jumper wires and tools for soldering

Solder Amp and Speaker

Amp.jpg
Speaker&Amp.jpg

The first step involves soldering wires to the amplifier. I used the standard braided jumper wires that come with most Arduino kits, and I cut the DuPont connectors off the ends as needed.

You should leave the DuPont connectors on the other end of the L input (blue wire in picture) and the 5V/GND power wires (bottom right in picture), because these three wires will need to be connected to the Mega pins.

After the Amp has been soldered, solder the wires that are attached to the L + - of the amp to the speaker terminals. The order does not matter, connect them however you please!

Solder Potentiometer and Voltage Divider

Wiring.jpg

The potentiometer and voltage divider should be soldered according to the schematic. For the 660 Ohm resistor, I used two 330 Ohm resistors in series. I used a small soldering board to assist in soldering the resistors and wires together. In the picture, it is a green board that has been repurposed from an earlier project, and so it has some irrelevant components included. The relevant resistors and wires are towards the top of the board in the picture.

Solder Buttons to Breadboard

Top board.jpg
Back side board.jpg

This is the most solder-intensive step. You must solder all 18 buttons to the solderable breadboard. Consult the picture for where you should place the buttons on the board. All buttons are using the built-in input pullup of the Mega, so each will have its own digital pin while the other terminal will be connected to ground. On my breadboard, I routed all buttons to one of the Mega's digital grounds using a DuPont connector. Check the circuit schematic to be sure the buttons are wired properly.

Connect Wiring to the Mega

Circuit.png

Consult the above circuit diagram for proper wiring to the Mega 2560.

3D Print Enclosure and Assemble

FWD9AF7LVZ9D7PR.jpg

There are two parts that need 3D printed: the main enclosure and the cover. After printing, you can start assembly.

First, you will want to attach the potentiometer and the speaker to the cover. The potentiometer will need to be turned into its slot using its threads. I found it easiest to turn the cover relative to the potentiometer to screw it in. After that, attach the speaker. There are four holes for the speaker, but you only need to use two of them. Use the screws with spacers between the screw head and speaker to attach the speaker.

The Mega should sit on its pegs nicely with the power/data port fitting in its slot. If it doesn't, you may need to clip some of the pegs and cut out some of the material around the port slot.

The breadboard (should be "buttoned-up" at this point) should fit nicely in its place. Mine ended up press-fitting nicely and I ended up not needing anything to hold it down.

Finally, you can place the cover over the main enclosure. There is a slot at the bottom of the enclosure that the cover fits in. You may want to tape the top part of the enclosure to make sure it stays closed.

Download, Compile, and Upload Relevant Code

Download the following code and upload it to your Arduino! I used the PlatformIO plugin for Visual Studio Code to compile and upload. Note that you will have to install the libraries NoodleSynth and SensorToButton by nathanramanoodles (available on GitHub). I made one change to the library code: in line 250 of NoodleSynth/src/MusicWithoutDelay.cpp, change the 2nd argument of the function from "set" to "55". This change shortens the notes every time you press a button so that it doesn't last so long.

Downloads

Enjoy Making Music!

After uploading, the device should be functional! I chose to use a wall outlet plugin to power the device so that I don't have to use my computer. Now you can have fun and bug your friends about this awesome music-making project you made!