Concept:
The Digital Piano with Percussion Effects is an innovative musical instrument that blends traditional piano elements with modern sensor technology to create a unique and interactive musical experience. This project uses an array of digital push buttons connected to an Arduino board to simulate a piano keyboard, where 8 different buttons trigger 8 distinct musical notes (‘C D E F G A B C#’ or ‘Sa Re Ga Ma Pa Dha Ni Sa’). In addition to the keyboard, the instrument incorporates an ultrasonic distance sensor, which introduces a dynamic layer of percussion sounds. These sounds vary depending on the distance of the player’s hand. Furthermore, a potentiometer is integrated to alter the pitch of the notes dynamically, offering the ability to manipulate the sound palette expressively.
Components Used:
- Arduino Uno
- Breadboard (x2)
- Jumper Wires
- Piezo Buzzer (x2)
- Push Buttons (x8)
- Potentiometer
- 10k ohm resistors (x8)
- Ultrasonic Sensor
Video:
Code:
int buzzerPin = 12; int buzzer2 = 13; int potPin = A0; int keys[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Frequencies for notes (C4 to C5) int notes[] = {262, 294, 330, 349, 392, 440, 494, 523}; int trigPin = 10; int echoPin = 11; int bassDrum = 200; int snare = 250; int hiHat = 300; void setup() { pinMode(buzzerPin, OUTPUT); pinMode(buzzer2,OUTPUT); pinMode(2,INPUT); pinMode(3,INPUT); pinMode(4,INPUT); pinMode(5,INPUT); pinMode(6,INPUT); pinMode(7,INPUT); pinMode(8,INPUT); pinMode(9,INPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); } void loop() { int potValue = analogRead(potPin); int volume = map(potValue, 0, 1023, 0, 255); // Map the potentiometer value to a volume range // Measure distance using the ultrasonic sensor digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); int distance = duration * 0.034 / 2; // Calculate the distance Serial.print(distance); Serial.println(" cm"); bool isAnyButtonPressed = false; for (int i = 0; i < 8; i++) { int modifiedNote = map(potValue, 0, 1023, notes[i] / 2, notes[i] * 2); if (digitalRead(keys[i]) == HIGH) { tone(buzzerPin, modifiedNote, 100); isAnyButtonPressed = true; break; // Stop the loop once a button is found pressed } } if (!isAnyButtonPressed) { noTone(buzzerPin); } if (distance < 10) { tone(buzzer2, bassDrum, 100); } else if (distance >= 10 && distance < 20) { tone(buzzer2, snare, 100); } else if (distance >= 20 && distance < 30) { tone(buzzer2, hiHat, 100); } else { noTone(buzzer2); } delay(100); }
In the loop, the program first reads the potentiometer value and uses it to modify the frequency of the piano notes. Depending on the button pressed, it plays a modified note frequency. If no buttons are pressed, it stops any ongoing tone. Depending on the distance detected, it chooses a percussion sound to play, simulating a drum kit with different sounds for different ranges.
Work Process and Challenges:
For this assignment I was paired up with Snehil. We both worked together to brainstorm the primary idea. First we only had the concept to build the digital piano with push buttons and then we combined the ultrasonic sensor to measure distance and make the percussion sounds to level up the musical instrument. For further improvement Snehil made the potentiometer work to change the pitch of the notes. We were first having trouble to make the ‘for loop’ work for the push buttons to make sound. We were also at first using only one piezzo for the whole instrument and the piano wasn’t working then. So we had to troubleshoot many times to fix those problems.
Final instrument with the potentiometer working: