Easy Arduino PIANO ( Including a Preset Song )

So first off , I am a student and wanted to pick an instrument , but the problem was that

I was not sure that “would I be able to do it ?”.

So, I thought to clear my base first and got an Idea to make a Piano using Arduino.

This piano is a simple and easy to make device , you can code any piano notes you want.

I have use these notes : G4, A4, A#4 and C5.

 It’s too bad, but only one note can be played at the time. The fifth button is coded for a melody,

when you press the 5th button a melody starts. I used a song from Tokyo Ghoul a Popular Anime.

you can code any song you like.

now if you have any doubt post a comment and if you made this project, pls share with us .

You can also follow me on YouTube

Supplies

COMPONENTS AND SUPPLIES

  • SparkFun pushbutton switch 12mm : 5* , 4 for notes and 1 for melody.
  • Jumper wires (generic) : 8* , 5 for buttons, 2 for the speaker and 1 to close the circuit.
  • Buzzer : 1* For the sound.
  • Arduino UNO : 1*
  • Breadboard (generic) :1*
  • 1K Ohm Resistor : 5* , For every button

APPS AND ONLINE SERVICES

Step 1: Buttons

First off, attach the buttons to the breadboard. One pair of legs of the button extending towards the + rail of the breadboard and the other pair of legs extending towards the – rail of the breadboard.

Step 2: Resistors

Connect a resistor (1k Ohm) each per button. Connect one leg of the resistors towards the blue line of the breadboard in extension of a leg of a button. Connect the other leg of every resistor to the – side of the power rail. (See above picture)

Step 3: Buzzer

Attach the buzzer in the 5th mounting hole next to the last button. One side of the buzzer attached towards the + rail of the breadboard and the other to the – side.

Step 4: Jumper Cables Into the Arduino

Attach a jumper cable to a button each. Connect it to the other leg of the button on towards the + side of the breadboard. Attach 2 jumper cables to the buzzer: one towards the + side and one towards the -, both in row 29. Connect the last jumper cable to the – side of the power rail like the resistors.

Connect the jumper cables of the buttons to the pins 2, 3, 4, 6, 8 from left to right as shown in the picture with the arduino and connect the jumper cable of the buzzer pointing towards the + and – both to pin 11 and 13 respectively.

Lastly, connect the jumper cable from the – power rail to GND so you have a closed electric circuit and your hardware is good to go 🙂

Step 5: The Code

  •  Basics

You start off with including the pitches.h tab, which you can download here. The pitches.h tab contains over 8 octaves of notes, which will give you enough variety to play around with. After that comes naming what button is called and is using which pin and the void setup. The void loop contains the code which note will be played when you press the button. The note will play for as long as you press the button. For the melody you can see how the sequence of the notes work, no explanations needed except for if you want a pause/silence in your song, the ‘note’ is 0, while the noteduration is not. You’ll have include in the code how long the pause is the same way as a normal note.

Step 6: Personalizing

You can change the tone of a button in the loop to whatever note you’d like. This way you can change the note intervals between them and change it to your liking. Don’t forget to also change the code at the beginning if you change the name of the button accordingly to the note.

The song in the code is Unravel, but you can put a song of your own in it by changing the notes. You can look up the notes using piano sheets and change the code along with the note durations accordingly to the song you want the arduino to play. The duration of a note in this code is 600ms/ the note duration you used as stated in the code in the void loop. You can change the speed of the song by changing this. E.g. change 600 to 1000 to make it play slower or to 500 to make it play faster.

Step 7: CODE

#include "pitches.h"

#define ACTIVATED LOW





const int PIEZO = 11;

const int LED = 13;



int buttonSong = 8;

const int BUTTON_C = 6;

const int BUTTON_AS = 4;

const int BUTTON_A = 3;

const int BUTTON_G = 2;

Step 8: Circuit Diagram

Here’s the circuit diagram, the piezo buzzer’s black wire is the +side and the red one is the – side of the buzzer. Those two wires represent the spot where the pins of the buzzer are attached to the breadboard.

Step 9: Ready and Play!

You’ve got the hardware, you’ve got the code and adjusted it to your liking, all what’s left is to play!

Source: Easy Arduino PIANO ( Including a Preset Song )

Leave a Comment

Your email address will not be published.

*
= 4 + 9

(Spamcheck Enabled)

Scroll to Top