Arduino Piano

by AE07 in Circuits > Arduino

260 Views, 3 Favorites, 0 Comments

Arduino Piano

20240118_122657.jpg

This is the completed Arduino Piano. The buzzer plays different pitches when different push buttons are pressed, and the RGB LED lights up red, green, and blue in that order. The red LED is on when any push button is pressed. All LEDs turn off when nothing is being pressed.

Supplies

Basics

20240118_120805.jpg
  1. Wire power and ground.
  2. Gather the 7 push buttons and buzzer.
  3. Wire the push buttons using the 1k ohm resistors and preferably red wires.
  4. Wire the buzzer with wires.

More Wires

20240118_122338.jpg

After completing Step 1 :

  1. Get your LED of any color and RGB LED.
  2. Wire them both using the 330 ohm resistors and wires.
  3. The LED of any color should go into pin 12.
  4. The color red for the RGB LED should go into pin 11, green pin 10, and blue pin 9.

Even More Wires

20240118_122657.jpg

After Step 2 is done :

Get some more wires to wire the push buttons.

Wiring them in order of pin number is recommended.

  1. Push button 1 should go into pin 2
  2. Push button 2 should go into pin 3
  3. Push button 3 should go into pin 4
  4. Push button 4 should go into pin 5
  5. Push button 5 should go into pin 6
  6. Push button 7 should go into pin 8


A Lot of Wires

20240118_122657.jpg

After wiring everything, it should look like this image. (Hopefully a little less messy).

Code

//Copy and paste the following code :

int but1= 2;
int but2= 3;
int but3= 4;
int but4= 5;
int but5= 6;
int but6= 7;
int but7= 8;
int REDPIN = 11;
int GREENPIN = 10;
int BLUEPIN = 9;
int pin = 12;

int buzzer=13;
void setup()
{
 pinMode(but1, INPUT);
 pinMode(but2, INPUT);
 pinMode(but3, INPUT);
 pinMode(but4, INPUT);
 pinMode(but5, INPUT);
 pinMode(but6, INPUT);
 pinMode(but7, INPUT);
 pinMode(buzzer, OUTPUT);
 
}

void setColor (int red, int green, int blue)
{
 analogWrite(REDPIN, red);
 analogWrite(GREENPIN, green);
 analogWrite(BLUEPIN, blue);
}

void loop()
{
 int b1=digitalRead(but1);
 int b2=digitalRead(but2);
 int b3=digitalRead(but3);
 int b4=digitalRead(but4);
 int b5=digitalRead(but5);
 int b6=digitalRead(but6);
 int b7=digitalRead(but7);
 if(b1==1)
 {
  tone(buzzer,300,100);
  setColor(255, 0, 255);
  digitalWrite(pin, HIGH);
 }
 if(b2==1)
 {
  tone(buzzer,400,100);
  setColor(255, 255, 0);
  digitalWrite(pin, HIGH);

 }
 if(b3==1)
 {
  tone(buzzer,500,100);
  setColor(0, 0, 255);
  digitalWrite(pin, HIGH);

 }
 if(b4==1)
 {
  tone(buzzer,600,100);
  setColor(255, 0, 255);
  digitalWrite(pin, HIGH);
 }
 if(b5==1)
 {
  tone(buzzer,700,100);
  setColor(255, 255, 0);
  digitalWrite(pin, HIGH);

 }
 if(b6==1)
 {
  tone(buzzer,800,100);
  setColor(128, 255, 0);
  digitalWrite(pin, HIGH);

 }
 if(b7==1)
 {
  tone(buzzer,900,100);
  setColor(255, 255, 0);
  digitalWrite(pin, HIGH);

 }
 delay(10);
 setColor(255, 255, 255);
 digitalWrite(pin, LOW);
}

Complete

After finishing all of these steps, you should have a complete and working Arduino Piano that does everything I have said. Please do not bring this to any talent show.