8-Button Piano With Raspberry Pi Pico 2W

by zoerijnders in Circuits > Raspberry Pi

52 Views, 0 Favorites, 0 Comments

8-Button Piano With Raspberry Pi Pico 2W

Afbeelding van WhatsApp op 2025-05-27 om 11.09.19_6b345254.jpg

Have you ever wanted to create your own mini musical instrument? In this project, we’ll build a simple 8-button piano using the Raspberry Pi Pico W and a passive buzzer. Each button will play a different musical note, allowing you to compose simple melodies and explore sound generation with code.

This is a perfect beginner-friendly project for learning about:

  1. GPIO input with push buttons
  2. Generating tones with PWM and a passive buzzer
  3. Basic MicroPython programming
  4. Using a breadboard and reading circuit diagrams

Whether you're new to electronics or looking for a fun Pico W project, this piano is a great way to combine hardware and coding in a hands-on way.

Let’s get started!

Supplies

✅ What You Need

Hardware:

  1. 1× Raspberry Pi Pico W (Pico 2W)
  2. 1× Passive buzzer
  3. 8× Push buttons
  4. Jumper wires
  5. Breadboard
  6. Optional: 8× 10kΩ pull-down resistors (if not using internal pull-ups)

Software:

  1. Thonny IDE
  2. MicroPython firmware for Raspberry Pi Pico W
  3. KiCAD (if you also want to make a PCB design

Flash MicroPython on Your Pico W

  1. Connect your Pico W to your PC via USB while holding the BOOTSEL button.
  2. It will appear as a USB drive named RPI-RP2.
  3. Download the latest MicroPython .uf2 file from https://micropython.org/download/rp2-pico-w/
  4. Drag and drop the .uf2 file onto the Pico's USB drive.
  5. Pico will reboot and is now ready for MicroPython.

Install and Set Up Thonny

  1. Go to the Thonny.org web site: https://thonny.org/ .
  2. Click on the link at the top right-hand side of the screen to install Thonny
  3. You should see an icon on the Desktop of your PC. Double click on this icon to start Thonny.
  4. The start-up screen of Thonny on your PC is shown in the left figure below.
  5. You are now ready to write your programs.

Building the Circuit on a Breadboard

Afbeelding van WhatsApp op 2025-05-20 om 09.45.55_8c4f9623.jpg
Afbeelding van WhatsApp op 2025-05-27 om 11.21.51_d0227c6c.jpg
Afbeelding van WhatsApp op 2025-05-27 om 11.09.19_795b8af3.jpg

We are now going to build our circuit on a breadboard. To do this effectively, it helps to understand the pinout and layout of the Raspberry Pi Pico W (2W). This knowledge will make it easier to identify which GPIO pins to use and how to wire your components properly.

I recommend you take some time to study the provided diagrams and pinout images, as well as refer to the official Raspberry Pi Pico W datasheet, which includes detailed technical information about the board, its pin functions, and electrical characteristics.

📄 Official Raspberry Pi Pico W Datasheet:

👉 Download the PDF from Raspberry Pi Foundation

Understanding the physical pin numbers vs. GPIO numbers is especially important when connecting buttons, buzzers, and other peripherals to your project. This preparation will help avoid common mistakes and ensure a smoother building process.

Connect the Push Buttons

Afbeelding van WhatsApp op 2025-05-27 om 11.41.18_ac54ba9a.jpg

Connect each button between a GPIO pin and GND. We'll use internal pull-up resistors in code, so no need for external ones.

Since I cannot upload the Table please refer to the picture of the table.

Also note that I have choosen these certain PGIO pins but in theory you can use every GPIO.

If you do change the pins, make sure you also change this in your Thonny Code later on.

Each button:

  1. One leg → GPIO pin
  2. One leg → GND

Connect the Buzzer

Use a passive buzzer (not active).

Connect:

  1. one pin of the buzzer → GP18 (physical pin 24)
  2. other pin of the buzzer → GND
  3. Optional: Place a 100–220Ω resistor between GP18 and the buzzer for safety.

I have placed a 220Ω Resistor between my GPIO an buzzer for safety, but if you do not have one the circuit will also work without.

Write and Upload the Code

  1. Open a new file in Thonny.
  2. Paste this working code:
from machine import Pin, PWM
import time

button_pins = [2, 3, 4, 5, 6, 7, 8, 9] # GPIO pins for 8 buttons
notes = [262, 294, 330, 349, 392, 440, 494, 523] # C4 to C5 frequencies

buttons = [Pin(pin, Pin.IN, Pin.PULL_UP) for pin in button_pins]

buzzer = PWM(Pin(18)) # Buzzer on GP18
buzzer.duty_u16(0) # Start silent

def play_note(freq, duration=0.2):
buzzer.freq(freq)
buzzer.duty_u16(2000)
time.sleep(duration)
buzzer.duty_u16(0)

while True:
for i in range(8):
if not buttons[i].value(): # Button pressed (active LOW)
play_note(notes[i])
time.sleep(0.1)
  1. Save the file as .py file on the Raspberry Pi Pico.

I have clarified what the functions of the lines using a # and it should display as light grey. Otherwise It might mess up the code.

Test Your Piano

Press a button — you should hear the buzzer play a note.

Each button corresponds to a different pitch (C4 to C5).

If nothing happens:

  1. Check your wiring.
  2. Confirm you’re using a passive buzzer.
  3. Ensure MicroPython is installed correctly.


Optional Add-Ons

Add an RGB NeoPixel for light feedback.

Display note names on an OLED screen.

Add an amplifier and speaker for louder sound.

Optional: Make a BCP Design

Afbeelding van WhatsApp op 2025-05-27 om 12.53.16_c959a35e.jpg

Connect the Right Lines

Schermafbeelding 2025-06-11 134335.png
Schermafbeelding 2025-06-11 133549.png

Have Some Fun

Schermafbeelding 2025-06-11 133639.png
Schermafbeelding 2025-06-11 133613.png
Schermafbeelding 2025-06-11 133349.png
Schermafbeelding 2025-06-11 133232.png

Have some fun and make it your own.

You can put nice text and pictures on the silkscreen.

Pictures can be imperted in a DXF or SVG file.