Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
roshan-baig
Published © GPL3+

Arduino Piano

This is an Arduino Piano which plays the notes from middle C to upper C.

IntermediateShowcase (no instructions)669
Arduino Piano

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
If you want it smaller, a Nano, Micro, or Mini might be better
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
I used a 0.5 Watt, 8 Ohm speaker
×1
Resistor 100 ohm
Resistor 100 ohm
For the speaker, but a linear amplifier might be better
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×8
Resistor 1k ohm
Resistor 1k ohm
×8
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to B Cable
USB-A to B Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

This is the circuit diagram

Code

This is the Code.

C/C++
To download the Piano library, go to the link in the description.
#include <Piano.h>
Piano piano(13);
int b1 = 2;
int b2 = 3;
int b3 = 4;
int b4 = 5;
int b5 = 6;
int b6 = 7;
int b7 = 8;
int b8 = 9;
void setup() {
  // put your setup code here, to run once:
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);
  pinMode(b3, INPUT);
  pinMode(b4, INPUT);
  pinMode(b5, INPUT);
  pinMode(b6, INPUT);
  pinMode(b7, INPUT);
  pinMode(b8, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  b1 = digitalRead(2);
  b2 = digitalRead(3);
  b3 = digitalRead(4);
  b4 = digitalRead(5);
  b5 = digitalRead(6);
  b6 = digitalRead(7);
  b7 = digitalRead(8);
  b8 = digitalRead(9);
  if(b1 == HIGH)
  {
    piano.play_Middle_c();
  }
  if(b2 == HIGH)
  {
    piano.play_Treble_d();
  }
  if(b3 == HIGH)
  {
    piano.play_Treble_e();
  }
  if(b4 == HIGH)
  {
    piano.play_Treble_f();
  }
  if(b5 == HIGH)
  {
    piano.play_Treble_g();
  }
  if(b6 == HIGH)
  {
    piano.play_Treble_a();
  }
  if(b7 == HIGH)
  {
    piano.play_Treble_b();
  }
  if(b8 == HIGH)
  {
    piano.play_Upper_C();
  }
}

Credits

roshan-baig
5 projects • 7 followers
Contact

Comments

Please log in or sign up to comment.