Luxurious Low-budget Piano Set (Ross and Alex)

Want to practice your favourite piano piece at home? Too broke to buy an actual piano? Worry not! Introducing the Luxurious Low-budget Piano Set (LLPS)! With only$9999.99, you will have this amazing piano in your home tomorrow! Order now we will give you a metronome FOR FREE!! Call at 54-320-7668 now and get the piano set of your dream!

#include <Tone.h>
const int buttonC = 2;
const int buttonD = 3;
const int buttonE = 4;
const int buttonF = 5;
const int buttonG = 6;
const int buttonA = 7;
const int buttonB = 8;
const int buttonC2 = 9;

const int soundPin = 11;
bool buttonStateC = LOW;
bool buttonStateD = LOW;
bool buttonStateE = LOW;
bool buttonStateF = LOW;
bool buttonStateG = LOW;
bool buttonStateA = LOW;
bool buttonStateB = LOW;
bool buttonStateC2 = LOW;

Tone player;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonC,INPUT);
pinMode(buttonD,INPUT);
pinMode(buttonE,INPUT);
pinMode(buttonF,INPUT);
pinMode(buttonG,INPUT);
pinMode(buttonA,INPUT);
pinMode(buttonB,INPUT);
pinMode(buttonC2,INPUT);
pinMode(soundPin,OUTPUT);
player.begin(soundPin);
}

void loop() {
// put your main code here, to run repeatedly:
buttonStateC = digitalRead(buttonC);
buttonStateD = digitalRead(buttonD);
buttonStateE = digitalRead(buttonE);
buttonStateF = digitalRead(buttonF);
buttonStateG = digitalRead(buttonG);
buttonStateA = digitalRead(buttonA);
buttonStateB = digitalRead(buttonB);
buttonStateC2 = digitalRead(buttonC2);

if (buttonStateC == HIGH){
player.play(NOTE_C4, 100);
}else if (buttonStateD == HIGH){
player.play(NOTE_D4, 100);
}else if (buttonStateE == HIGH){
player.play(NOTE_E4, 100);
}else if (buttonStateF == HIGH){
player.play(NOTE_F4, 100);
}else if (buttonStateG == HIGH){
player.play(NOTE_G4, 100);
}else if (buttonStateA == HIGH){
player.play(NOTE_A4, 100);
}else if (buttonStateB == HIGH){
player.play(NOTE_B4, 100);
}else if (buttonStateC2 == HIGH){
player.play(NOTE_C5, 100);
}

Serial.print(buttonStateC);
Serial.print(” “);
Serial.print(buttonStateD);
Serial.print(” “);
Serial.print(buttonStateE);
Serial.print(” “);
Serial.print(buttonStateF);
Serial.print(” “);
Serial.print(buttonStateG);
Serial.print(” “);
Serial.print(buttonStateA);
Serial.print(” “);
Serial.print(buttonStateB);
Serial.print(” “);
Serial.println(buttonStateC2);
Serial.print(” “);
}


Our idea is simple: make a piano with each key correspond to a different tone. So we have eight buttons and one buzzer that produces the tone.  We were quite frustrated in the beginning because the buzzer would beep non-stop without any input. After making sure that our code was bug-free, we discovered that there are two reasons that could cause this problem:

  1. the power is not connected properly. In our case, we were not aware that for the long breadboard, the bottom part and the top part of the busbar are not connected. The power was connected to the top and one of our buttons was connected to the bottom.
  2. the output wire has to be parallel to ground. We soldered a button another way around so that the input was always on.

#include <Servo.h>

Servo myservo; // create servo object to control a servo

//const int potpin = A0; // analog pin used to connect the potentiometer
const int metronome = 6;
const int soundPin = 11;
//int val; // variable to read the value from the analog pin
int BPM = 60;

void setup() {
pinMode (soundPin, OUTPUT);
myservo.attach(metronome); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}

void loop() {
// val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
// val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)

myservo.write (105 + 30);
tone (soundPin, 500);
delay (50);
noTone (soundPin);
delay ((60/BPM)*1000);
myservo.write (105 – 40);
tone (soundPin, 500);
delay (50);
noTone (soundPin);
delay ((60/BPM)*1000);
// myservo.write(val); // sets the servo position according to the scaled value
// delay(15); // waits for the servo to get there
}


We created the metronome by looping a back and forth motion on the servo motor. The rate at which the metronome operated is determined by the length of the delay between every beat. The hand (connected to the motor) will tick once while the buzzer will also sound once for every beat. The metronome will be particularly helpful for beginners who have trouble keeping their songs in tempo.

Leave a Reply

Your email address will not be published. Required fields are marked *