Mini Piano

by hrvrdkeryann in Circuits > Arduino

18 Views, 0 Favorites, 0 Comments

Mini Piano

1C9844DF-E770-4A2E-89CF-3DD59E78F2C2.png
IMG_2334.jpeg

As part of my learning in electronics and Arduino programming, I created an interactive mini piano. This project is built using 7 push buttons, an Arduino Uno, and a passive buzzer. Each button is assigned to a musical note (Do, Re, Mi, Fa, Sol, La, Si): when a button is pressed, the Arduino sends a specific frequency to the buzzer, producing the corresponding note. At the end of this project we will be able to play famous songs with those basic notes.


Supplies

As mentioned, for this project we will need :

-1 arduino uno

-7 push buttons

-1 passive buzzer

Circuit

IMG_1286.jpeg

-buttons ~~ pmw 3 to 9

-buzzer ~~ pmw 10

Code

image.jpg

const int buttons[] = {3, 4,5, 6, 7, 8, 9};

const int notes[] = {262, 294,330,349,392,440,494};

const int buzzer = 10;


void setup() {

for (int i =0; i < 7; i++) {

pinMode (buttons[i], INPUT);

}

pinMode (buzzer, OUTPUT);

}

void loop () {

bool notePlayed = false;

for (int i = 0; i < 7; i++) {

if (digitalRead(buttons[i]) == HIGH) {

tone (buzzer, notes[i]);

notePlayed = true;

break; // une seule note à la fois

}

}

if (!notePlayed) {

noTone (buzzer);

}

}

Play Famous Songs

We can now manually play famous songs with the notes (do, re, mi, fa, sol, la). For example:


Super mario bros : Mi – Mi – Mi | Do – Mi – Sol | Sol – Do – Mi – Sol – La

Au clair de la lune : Do – Do – Do – Ré – Mi – Ré – Do – Mi – Ré – Ré – Do

Frère jacques :

Do – Ré – Mi – Do

Do – Ré – Mi – Do

Mi – Fa – Sol

Mi – Fa – Sol