Introduction: Mini Piano With Arduino 101

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!

Step 1: Materials and Tools

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

Step 2: Connecting to Ground

  • 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.

Step 3: Connecting the Resistors

  • 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.

Step 4: Connecting the Signal

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

Step 5: 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);
}

Step 6: Demo

Comments

author
botgames made it! (author)2017-09-10

Nice tutorial. Very easy to follow.

20170910_233516.jpg

About This Instructable

410views

5favorites

License:

Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: