Button Piano

by Gurneel in Circuits > Arduino

92 Views, 1 Favorites, 0 Comments

Button Piano

20230124_124016.jpg

In this project I made a piano, that show you the note you are playing. This could be helpful if you don't know much about the piano and want to learn the notes.

Supplies

3 LEDS

1 Arduino

1 LCD display

6 10k resistors

3 330ohm resistors

6 Buttons

1 Buzzer

Many Wires

Reasearch

First thing I did was research of what I should do for my project. I hadn't done much work with buzzers, and thought it could be fun and interesting to try something new. I found out that I could make specific sounds and pitches. I made the idea to make a piano and decided to look onto the rubric to see how could add on to it. I first found the tone() command and tested on how it worked. Then I looked onto the level 4 components, and decided to add the LCD display. I had experience with using it, and thought it could add to the project.

Wiring

20230119_141127.jpg
20230124_124016.jpg
image_2023-01-25_212510486.png

First thing to do is add your 6 buttons to the breadboard. You want to connect each to power and ground, with a 10k resistor. Next you want to set up the LEDS. Connect all 3 to ground with a 330ohms resistor. Next you want to set up the buzzer. You can plug it into the breadboard then connect the cathode to ground for now. Next you want to get a Arduino and connect the breadboard to power and ground. With my diagram above you can clearly see which components get plugged into where.

Code

image_2023-01-25_212919279.png
image_2023-01-25_213442526.png

Now finally the code. It is fairly simple. First I define all the variables to be used in the project. This being all the buttons, LEDS, and the buzzer. The reason we don't have any variables for the LCD is because the code is already pre loaded onto A5 and A4.


Next would be to define each variable is a OUTPUT or INPUT (void setup();). Every button would be a OUTPUT. Now every other other component, being the LEDS, and buzzer, would be a INPUT. You also need to do Serialbegin(9600); to start the serial monitor. Lastly you need to do some commands for the LCD screen.


Lastly is the void loop(); function. This last step is fairly simple. All I do here is first make each button variable equal to a smaller letter, so it is easier to right later on. Now next I test each button to see if it is being pressed. If it is it gives commands to play the right frequency to the buzzer, write the text onto the LCD screen to tell you what note it is, turn on a LED, and finally print what note it is to the serial monitor. After doing this for each button, the code is complete. Below I have the download to the code so you can examine it more closely and use it for your self in this project.