Audrino Mini Piano - Harvir
I created a mini piano using an Arduino Uno. The piano plays different musical notes when buttons are pressed. I also added LEDs to the different types of notes being played and I included an LDR Sensor that changes the pitch of the notes based on the brightness of the environment.
Supplies
- Arduino
- Jumper wires
- Breadboard
- Buzzer
- 7 Pushbutton switches
- Red led light
- Yellow led light
- Green led light
- LDR sensor
- 3 x 330 ohms resistors
- 1 x 10k ohms resistor
Placing the Pushbuttons
Place 7 pushbuttons and connect them to ground. Each button represents a different musical note (C, D, E, F, G, A, B).
Placing LEDs and Resistors
Place 3 Led lights and connect the short leg to a 330 Ohms resistor to ground. Red LED for low notes (C and D)
Yellow LED for middle notes (E, F, and G) Green LED for high notes (A and B)
Placing the Buzzer
Place a Buzzer on the circuit and connect it to ground. The buzzer is the output device that creates sound when a button is pressed.
Placing the LDR Sensor
Place a LDR on the circuit and connect one leg to 5V and connect the other leg to a 10k Ohms resistor to ground.
Wiring the Pushbuttons and LEDS
Wire the pushbuttons to pins 2-8 And the LEDs from pins 10-12
Notes:
- C = Pin 8
- D = Pin 7
- E = Pin 6
- F = Pin 5
- G = Pin 4
- A =Pin 3
- B = Pin 2
LEDs:
- Red = Pin 10
- Yellow = Pin 11
- Green = Pin 12
Wiring the Buzzer and LDR Sensor
Wire the buzzer to Pin 9 and wire the LDR to A0
Connecting the Circuit to Power
Connect the circuit to ground and power.
Building the Code
Build your code. I created my code using thinkercad. The code allows the Arduino to read button inputs, play different notes through the buzzer, control the LEDs, and use the LDR sensor to change the pitch. I used a code from this website: https://projecthub.arduino.cc/rahulkhanna/arduino-tutorial-mini-piano-0c7ec5 But I added on to it to make sure my LDR and LED lights work.
Each pushbutton is assigned to a musical note:
- C = 262 Hz
- D = 294 Hz
- E = 330 Hz
- F = 349 Hz
- G = 392 Hz
- A = 440 Hz
- B = 493 Hz
The LEDs show what range of notes are being played:
- Red LED turns on for low notes (C and D)
- Yellow LED turns on for middle notes (E and F)
- Green LED turns on for high notes (G, A and B)
The LDR sensor reads the amount of light using the analog pin A0. The code checks the light level and changes the pitch:
- Bright light = normal pitch
- Dark light = high pitch
Testing the Piano
After uploading the code, I tested each part of the piano.
- Pressing each button played a different note.
- The correct LED turned on depending on the note range.
- The LDR detected changes in light and adjusted the pitch.
- The buzzer playing the right sound.
- Fixing any problems on the circuit