A Mini Cardboard Piano

by ruehi in Circuits > Arduino

156 Views, 2 Favorites, 0 Comments

A Mini Cardboard Piano

IMG_1328.jpg

For this project I made a mini cardboard piano. I've always loved making music but I don't have a lot of experience in it and most instruments are expensive. For school we got an assignment to work with an Arduino, I knew almost immediately that I wanted to do something with music. I looked up different tutorials and quickly came to the idea of making a piano using Arduino buttons and a Piezo buzzer. There's seven different buttons with different frequencies, only I also wanted to be able to let the piano play songs I made, so with the knowledge of the different tutorials I'd watched, I added an eighth button with which you can play your own songs.


Reflection

During this project I learned how to solder (although I didn't have the tools for that at home so instead I had to use a breadboard), I also learned how to program buttons and how to work with tone() function. I'm really inexperienced when it comes to making things like this by hand so that was also really fun to have to figure out.


Tutorials I used


Arduino Electronic Piano Keyboard with Preset Songs

Learn how to play sound with Arduino

Easy Arduino Piano



Supplies

Circuits


8x Buttons
2x Breadboard
3x Battery Holder (AAA)


Exterior


  • Cardboard (one big cardboard box should be enough)
  • Glue Gun
  • Box cutter
  • Spray Paint Primer
  • Acrylic Paint

Circuit Assembly

Shiny Snaget(4).png
Shiny Snaget(1).png
WhatsApp Image 2023-07-17 at 20.40.23.jpeg
WhatsApp Image 2023-07-19 at 22.00.46.jpeg

To start with I created a virtual circuit in Tinkercad to see how I wanted to set it up. In the second picture you see my first iteration, I decided to add another breadboard for extra space and a battery holder for convenience. In the third picture you see how it looked after I added the extra breadboard. After that I simply spaced the buttons further apart as you can see in the final picture. I also added a video that shows me testing it!

Code

//For this code you need to have the tone library installed, which you can find in the library manager on the side.


//Here you define the frequency of the notes (in Hz).
#define NOTE_C 262
#define NOTE_D 294
#define NOTE_E 330
#define NOTE_F 349
#define NOTE_G 392
#define NOTE_A 440
#define NOTE_B 493


#define ACTIVATED LOW


//This is where you indicate which pin is connected to which button, you can also give them a name here.
const int PIEZO = 11;
const int LED = 13;


const int BUTTON_C = 10;
const int BUTTON_D = 9;
const int BUTTON_E = 8;
const int BUTTON_F = 7;
const int BUTTON_G = 6;
const int BUTTON_A = 5;
const int BUTTON_B = 4;
int buttonSong = 3;


void setup()
{
//This is for the Serial.println function.
  Serial.begin(9600);

//Here you set up the button input and LED output.
//The pinMode function configures the specified pin to behave either as an input or an output.
//digitalWrite writes a HIGH or a LOW value to a digital pin.
//HIGH means enabled while LOW means disabled. We want it on HIGH since we want the buttons to be enabled.
  pinMode(LED, OUTPUT);
  pinMode(BUTTON_C, INPUT);
  digitalWrite(BUTTON_C,HIGH);
  pinMode(BUTTON_D, INPUT);
  digitalWrite(BUTTON_D,HIGH);
  pinMode(BUTTON_E, INPUT);
  digitalWrite(BUTTON_E,HIGH);
  pinMode(BUTTON_F, INPUT);
  digitalWrite(BUTTON_F,HIGH);
  pinMode(BUTTON_G, INPUT);
  digitalWrite(BUTTON_G,HIGH);
  pinMode(BUTTON_A, INPUT);
  digitalWrite(BUTTON_A,HIGH);
  pinMode(BUTTON_B, INPUT);
  digitalWrite(BUTTON_B,HIGH);

//Here I configured one for the eighth button, the scripted melody.
  pinMode (buttonSong, INPUT);
  digitalWrite(buttonSong, HIGH);

  digitalWrite(LED,LOW);
 
}


//This is the function for the melody, you enter which notes you wanna hear in what order.
int melody[] = {

NOTE_E, NOTE_A, NOTE_B, NOTE_C, NOTE_F,  NOTE_G, NOTE_G, NOTE_A, NOTE_G, NOTE_G, NOTE_F,

};


//This is the function for how many seconds you want the notes to last,
//They correspond with the position you gave a note in the function before this one.
int noteDurations[] = {

4.5, 2.25, 2.25, 4.5, 2.25, 2.25, 2.25, 2.25, 2.25, 4.5, 3,

};

void loop() {

//Here's what happens when the buttons are being pressed.
//So for example: while button C is being activated it plays note C on the piezo buzzer
//There's also one for the LED light (HIGH = on) on the Arduino so you can easily see if your button works/is being pressed.
  while(digitalRead(BUTTON_C) == ACTIVATED)
  {
    tone(PIEZO,NOTE_C);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_D) == ACTIVATED)
  {
    tone(PIEZO,NOTE_D);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_E) == ACTIVATED)
  {
    tone(PIEZO,NOTE_E);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_F) == ACTIVATED)
  {
    tone(PIEZO,NOTE_F);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_G) == ACTIVATED)
  {
    tone(PIEZO,NOTE_G);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_A) == ACTIVATED)
  {
    tone(PIEZO,NOTE_A);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(BUTTON_B) == ACTIVATED)
  {
    tone(PIEZO,NOTE_B);
    digitalWrite(LED,HIGH);
  }

//This is an if-statement to start playing the melody.
  if(digitalRead(buttonSong) == ACTIVATED) {
   
    //A for loop for playing the melody.
    //thisNote indicates how long the melody should last (so here it's 13 seconds).
    for (int thisNote=0; thisNote <13; thisNote++) {

      int noteDuration = 600 / noteDurations[thisNote];

      //The tone function is used the same way as above except the noteDuration is added.
      tone(PIEZO, melody[thisNote], noteDuration);

      int pauseBetweenNotes = noteDuration * 1.50;

      delay(pauseBetweenNotes);

      noTone(PIEZO);

    }

  }

//The following code is purely so I can see what notes I'm playing when I have the piano hooked up to my pc!
  if (digitalRead(BUTTON_C) == ACTIVATED) {
  Serial.println("C");
  }
  if(digitalRead(BUTTON_D) == ACTIVATED) {
  Serial.println("D");
  }
  if(digitalRead(BUTTON_E) == ACTIVATED) {
  Serial.println("E");
  }
  if(digitalRead(BUTTON_F) == ACTIVATED) {
  Serial.println("F");
  }
  if(digitalRead(BUTTON_G) == ACTIVATED) {
  Serial.println("G");
  }
  if(digitalRead(BUTTON_A) == ACTIVATED) {
  Serial.println("A");
  }
  if(digitalRead(BUTTON_B) == ACTIVATED) {
  Serial.println("B");
  }

//This is so the Piezo buzzer and led light go off once you stop pressing any buttons.
  noTone(PIEZO);
  digitalWrite(LED,LOW);

}


Making the Exterior

WhatsApp Image 2023-07-18 at 00.22.42.jpeg
WhatsApp Image 2023-07-18 at 00.22.42(1).jpeg
WhatsApp Image 2023-07-17 at 20.40.20.jpeg
WhatsApp Image 2023-07-19 at 22.00.59.jpeg
WhatsApp Image 2023-07-19 at 22.00.54.jpeg
WhatsApp Image 2023-07-19 at 22.01.01.jpeg
WhatsApp Image 2023-07-19 at 22.01.11.jpeg
WhatsApp Image 2023-07-19 at 22.52.15.jpeg

First you make a sketch for what you want your piano or instrument to look like, as you can see I had different ideas for it but ultimately decided on a classic piano shape. You sketch out the shape you want on a piece of paper and cut it out from cardboard. You do this twice and you'll have the bottom and topside of the piano. It helps to put your circuit assembly on the cardboard to see how much space you need.

After that you can cut out a long piece of cardboard, the length depending on your piano shape, and bend it to fit around the bottom and top side. Next, I made a panel to separate the wires from the buttons and hide the rest of the electronics behind it.

The piano keys are pretty easy to make (see fourth picture), you have to bend the end in a zigzag shape so that the key always bounces back up once you've pressed it. I made seven of these. For the eighth button I made a different design since I wanted this to be my button for playing melodies. I cut out a small round shape and a small thin strip that I bent into a zigzag shape. Glue them together and you have another button that bounces back!

Lastly I made a bunch of small boxes to hide the breadboard and any other Arduino components you weren't supposed to see.


Detailed description (length, height, width):

The exterior consists of 9 main components. I made a sketch that includes all the dimensions of the parts and numbered them from 1 to 8 (see last picture):


  1. The base of the piano. The breadboard, battery holder, and Arduino Uno will be secured to this at a later point.
  2. The top of the piano.
  3. A box for the Piezo buzzer and song button.
  4. A panel that creates a barrier between the wires and the buttons.
  5. A box that hides the front of the breadboard.
  6. A long piece of cardboard that stretches alongside the sides and back of the piano.
  7. Boxes to hide the short sides of the breadboard.
  8. Boxes to hide the short sides of the breadboard.
  9. Piano keys


Paint

WhatsApp Image 2023-07-19 at 22.01.15(1).jpeg
WhatsApp Image 2023-07-19 at 22.01.15.jpeg

After having all the cardboard pieces you need, you can now start painting them. Before that, however, I sprayed them all with primer so that the paint would stick better (which explains the grey color from previous pictures). After letting them dry from that I started painting them with acrylic paint, first making a white base and then painting a light blue color over them (I mixed cobalt blue paint with white paint) I left the keys white, but you can choose to paint them any color you want.

Assembling Circuits and Exterior

WhatsApp Image 2023-07-17 at 20.40.22(1).jpeg
WhatsApp Image 2023-07-19 at 22.52.15(1).jpeg
WhatsApp Image 2023-07-19 at 22.52.15(2).jpeg
image.png
WhatsApp Image 2023-07-19 at 22.01.15(2).jpeg
WhatsApp Image 2023-07-19 at 22.01.14.jpeg
WhatsApp Image 2023-07-19 at 22.01.15(3).jpeg
WhatsApp Image 2023-07-19 at 22.01.24.jpeg
WhatsApp Image 2023-07-19 at 22.01.26.jpeg

After the paint has dried you can start properly assembling everything together. Before assembling however, I would recommend coming up with a layout of how you want to secure the electrical components onto the base of the piano, so you can also cut out holes for the Arduino Uno port and the on/off switch of the battery holder (see first picture).


For the assembly, I first secured the base (1) and the long strip of cardboard (6) to each other with hot glue. Next, I glued the boxes (5, 7 and 8) along the edges of the front of the piano base.

After this, you can secure your breadboard, Arduino and battery holder on the base of the piano. 


Before gluing your breadboard onto the base, I would recommend gluing the zigzag button onto your eight button for easier access later on (see fourth picture).


To secure the breadboard, I peeled off the layer and glued it onto the base. Next, I used tape to secure the battery holder onto the right side of the piano, making sure it aligns with the hole you cut out to access the on/off switch. And last, I hot glued the edges of the Arduino after pushing the port through the hole I made at first.

Now you can add the panel (4). The trick here is to make sure you put it right behind the buttons, so you can hide the wires while still making sure you can play your piano.

Next, you assemble the box (3) by bending each side and hot gluing them to each other. You can poke some holes on the top side of the box, to give it the look of a speaker. Once the glue's cooled off, you place it above the Piezo buzzer and the song button, and glue it on the breadboard.

Now, you can secure the top of the piano (1) onto the rest.


And last, but not least, you add the piano keys. Use glue on the part where each key is bent, and put it on the long edge of the breadboard. Make sure to test if each key can be easily pressed before moving onto the next one! Then add the long strip of cardboard used for the end of your keys and simply bend it in half and push it in, no need for glue (see last picture).

Soldering

IMG_2582.jpg
IMG_2581.jpg
IMG_2583.jpg

This is an extra step you can take if you want your project to be more permanent.

You will need:

  • Soldering Iron
  • Soldering Tin
  • Prototype or Perf Board
  • Cutting Pliers

For this step you take out the wiring and put it onto a prototype board. After that all you have to do is simply solder the wires onto the board in the same way you connect them to the breadboard. Except this time you'll have to cut some of them to be able to solder them. If you want a more comprehensive guide on the basics of soldering here's a link to a YouTube video explaining it: https://www.youtube.com/watch?v=l9Kbr8cPqOE

After you've soldered the wires onto the prototype board you can now put it back into the piano and start playing!

In the pictures and video's in this step you can see some of my process and how I've connected the wires on the back.

Play Music!

WhatsApp Image 2023-07-19 at 22.01.30.jpeg

If you've gotten this far you can finally start playing some music on your new piano (or instrument)! Thank you for reading and I hope you have as much fun making this as I did. Don't forget to decorate it!