Mini Piano With Arduino 101

by TechMartian in Circuits > Arduino

4258 Views, 17 Favorites, 0 Comments

Mini Piano With Arduino 101

YDZL1perSriluOJRRnUV3w_thumb_74a.jpg
Happy Birthday!

This is a mini piano board with only 4 customizable buttons allowing you to play any frequency and tone you want. It is a simple yet fun toy to build especially for kids!

Here's also a recording of my happy birthday-twinkle twinkle Arduino remix!

Materials and Tools

GtdgcYrfT9au%rNJYxZivw_thumb_744.jpg

  • Arduino
  • 4x Push button switches
  • 4x 10kΩ resisitor
  • 6x jumper wires
  • Breadboard wires
  • Breadboard

Connecting to Ground

h7gnVcX9SNmA7sm89YBXyQ_thumb_743.jpg

  • Connect one of the pins of each of the switches to ground.
  • Connect one of the buzzer pins to ground.

It doesn't matter which one you connect since the remaining pin will be the signal pin.

Connecting the Resistors

tKYNZnr2Qs+P+QzfiKOeMg_thumb_745.jpg

  • Connect each of the 10kΩ resistor between power (red power rail) to one of the pins of each switch, this is also known as the signal pin.
  • Connect this power rail to 3.3V.

Connecting the Signal

z4CwJ+31T3WIqU6Wtj60FA_thumb_747.jpg
dtVdxPY%T%ugK75JahlLFw_thumb_746.jpg

  • Connect the signal pin of each switch to pins 2-5 on the Arduino.

Coding and Uploading

Upload the following code to your Arduino, once you have selected the appropriate board and port under tools.

const int yellow = 2;
const int green = 3; const int blue = 4; const int red = 5; const int buzz = 6;
int notes[] = {262,294,330,349};
void setup() {
  pinMode (yellow, INPUT);
  pinMode (green, INPUT);
  pinMode (blue, INPUT);
  pinMode (red, INPUT);
  pinMode (buzz, OUTPUT);
  tone (buzz, 2000);
  Serial.begin(9600);
}
void loop() {
  if (digitalRead(yellow) == LOW)
    {tone(buzz, notes[0], 50);
    delay (50);
    noTone(buzz);
    Serial.println(digitalRead(yellow));}
  else if (digitalRead(green) == LOW)
    {tone (buzz, notes[1], 50);
    delay (50);
    noTone(buzz);}
  else if (digitalRead(blue) == LOW)
    {tone (buzz, notes[2], 50);
    delay (50);
    noTone(buzz);}
  else if (digitalRead(red) == LOW)
   {tone (buzz, notes[3],50);
    delay (50);
    noTone(buzz);}
  else 
    noTone (buzz);
}

Downloads

Demo

YDZL1perSriluOJRRnUV3w_thumb_74a.jpg
Mini Piano Demo
Screen Shot 2017-08-18 at 11.14.37 PM.png