Arduino Piano

by Jonluca29 in Circuits > Arduino

438 Views, 4 Favorites, 0 Comments

Arduino Piano

thumbnail_20230121_195453.jpg

Hello! I've created an electronic piano using an Arduino Uno board. It is capable of playing all 7 notes that a piano has. I did some research on project ideas and I came across the idea of a piano using an Arduino. I made this because I've started to get into music and I thought that this would be a fun and interesting project for me to take on.

Supplies

  • Arduino Uno Board
  • wires
  • Push buttons (7x)
  • 10k ohm resistors (7x)
  • 330 ohm resistor
  • Led
  • slide switch
  • buzzer
  • OLED 12C Display
  • breadboard

Put the Components on Your Breadboard

thumbnail_20230121_202017.jpg

Place all your buttons side-by-side along the dip of the breadboard just like in the image shown. Connect one leg of a button with a wire to the positive rail and the other leg using a 10k ohm resistor to the negative rail then do the same thing with the other buttons. Place your OLED Display into the breadboard and connect the VCC pin to the positive rail and GND to the negative rail. Place a slide switch and connect the middle pin to the negative rail. The slide switch will act as an on-and-off switch for the circuit. Now, place your buzzer and LED, and connect both anode pins to one of the other pins of the slide switch. Don't forget to connect the cathode pin of the LED to the positive rail with the 330-ohm resistor! Lastly, connect both positive rails and negative rails on the breadboard.

Arduino Connections

thumbnail_20230121_202424.jpg
Screenshot 2023-01-22 110045.png

First, you're going to connect one of your push buttons to pin 12, then another to pin 11, and so on. Connect the cathode leg of the buzzer to pin 3. The SCL pin on the OLED display must be connected to the A4 pin and the SDA pin must be connected to the A5 pin. Connect the 5V pin and the GND pin on the Arduino to the positive and negative rail on the breadboard. (The digital circuit image doesn't contain the OLED because Tinkercad does not have the OLED display.)

Writing the Code

To sum up the code, the libraries being used are SPI.h, Wire.h, Adafruit_GFX.h, and Adafruit_SSD1306.h. You will need to install the Adafruit_GFX library and the Adafruit_SSD1306 library. Each note for each button is then defined and we apply variables containing the pin number for each button that is then labeled with what note the button will play. In the void setup() all the buttons are set as input and the display.begin function is called. In the void loop() while loops are used to check for button presses and if there are, the note is played according to the button pressed, and the note letter is displayed on the OLED display.

Downloads