How to make a piano with an arduino uno board: STEM activities for kids and adults
Hi my friends,
Summer is about to be finished but we still have this joy to share more with you even by knowing that the fall is coming.
The project we want to make today is nothing else but "How to make a piano with an arduino uno board".
This project will be simple as the number of components we use and also the notes ( I mean the primary musical notes: A, B, C, D, E, F, G).
Frequency
To make the main notes, we usually use instrument that are already pre-made (Like a flute, a guitar, etc). In our case, we will use a computer and electronics. To do so, we will use frequency. Each primary note has a frequency. They can easily be found on internet but you can also find them right below to save you some time. There they are for basic notes.
A: 440Hz
B: 493 Hz
C: 262 Hz
D: 294 Hz
E :330 Hz
F: 349 Hz
G: 392 Hz
1) Components for the projects
To start making this project we need to gather the following:
1 speaker
7 push-buttons
A couple of wires
1 breadboard
1 USB cable
Wiring
You assemble the project, you can follow this schematic that shows you the connection between the electronic components.
2) Code
The follwoing code can be uploaded to the arduino uno board using the Arduino IDE.
The main function used to make the sound in this project is Tone. It allows you to make sound at the desired frequency.
//Arduino Piano
#define A_freq 440 #define B_freq 493 #define C_freq 262 #define D_freq 294 #define E_freq 330 #define F_freq 349 #define G_freq 392
const int B = 4; const int C = 10; const int D = 9; const int E = 8; const int F = 7; const int G = 6; const int A = 5;
const int Speaker = 11;
void setup() { pinMode(C, INPUT); digitalWrite(C,HIGH); pinMode(D, INPUT); digitalWrite(D,HIGH); pinMode(E, INPUT); digitalWrite(E,HIGH); pinMode(F, INPUT); digitalWrite(F,HIGH); pinMode(G, INPUT); digitalWrite(G,HIGH); pinMode(A, INPUT); digitalWrite(A,HIGH); pinMode(B, INPUT); digitalWrite(B,HIGH);
}
void loop() {
while(digitalRead(A) == LOW) { tone(Speaker,A_freq); }
while(digitalRead(B) == LOW) { tone(Speaker,B_freq); }
while(digitalRead(C) == LOW) { tone(Speaker,C_freq); }
while(digitalRead(D) == LOW) { tone(Speaker,D_freq); }
while(digitalRead(E) == LOW) { tone(Speaker,E_freq); }
while(digitalRead(F) == LOW) { tone(Speaker,F_freq); }
while(digitalRead(G) == LOW) { tone(Speaker,G_freq); }
noTone(Speaker);
}
3) Improve the project
You can improve this project in so many ways. We are all makers and the sky is the only limit. One way you can improve this project is by adding more touchpads. It can be done is with the Arduino Mega. It has more pins meaning more place for the half note in between.
4) Video
You can find a nice video of how the electronics schematic works with the arduino uno board. You can make your own project and share it with us if you desire.
Don't forget to subscribe to the youtube channel.
5) Maker newsletter and social medias
If you are a connected maker, like projects and maybe live in Washington DC, Maryland and Virginia, you can subscribe to our newsletter( at the bottom of our website : www.makersgeneration.net) and social medias (Facebook, Twitter, Google+, Instragram, Youtube). You will be aware of all our STEM after-school programs in Washington DC, Maryland and Virginia ( on 3D printing, robotics, electronics, coding, video game and more).
See you soon for more STEM videos, tutorial, articles and events in Washington DC. ;-)