Make music with a microcontroller

Build and code a simple musical instrument using a microcontroller, buzzer, and batteries to play melodies and explore sound, timing, and programming.

Instrument Making1 hr10 materials
Get instructionsMore activities
Make music with a microcontroller
Make music with a microcontroller
1 hrHands-on fun
15 steps →

About this activity

Build and code a simple musical instrument using a microcontroller, buzzer, and batteries to play melodies and explore sound, timing, and programming.

What you need

🧰microcontroller (Arduino Uno or compatible)🧰USB cable🧰piezo buzzer🧰220 ohm resistor🧰pushbutton🧰10k resistor🧰jumper wires🧰breadboard🔋battery pack with batteries🧰adult supervision required

Step by step

  1. 1

    Step 1

    Gather all the Materials Needed and put them on a clear workspace.

  2. 2

    Step 2

    Plug your microcontroller into the computer using the USB cable so it can get power and receive code.

  3. 3

    Step 3

    Place the breadboard next to the microcontroller and push the piezo buzzer into the breadboard rows.

  4. 4

    Step 4

    Use a jumper wire and the 220 ohm resistor to connect the buzzer’s positive lead to digital pin 8 on the microcontroller.

  5. 5

    Step 5

    Use a jumper wire to connect the buzzer’s negative lead to the GND pin on the microcontroller.

  6. 6

    Step 6

    Insert the pushbutton into the breadboard so each pair of legs sits in different rows.

  7. 7

    Step 7

    Use a jumper wire to connect one side of the pushbutton to the 5V pin on the microcontroller.

  8. 8

    Step 8

    Use a jumper wire to connect the opposite side of the pushbutton to digital pin 2 on the microcontroller.

  9. 9

    Step 9

    Put the 10k resistor between the button’s pin that goes to digital pin 2 and GND to act as a pull-down resistor.

  10. 10

    Step 10

    Open the Arduino IDE or the MakeCode editor on your computer.

  11. 11

    Step 11

    Paste the code below into the editor exactly as shown:

  12. 12

    Step 12

    Change the tempo number in the code to a new value if you want a faster or slower melody.

  13. 13

    Step 13

    Upload the sketch to your microcontroller from the editor so the code runs on the device.

  14. 14

    Step 14

    Press the pushbutton to play the melody and listen closely to how the sound and timing behave.

  15. 15

    Step 15

    Share a photo or video of your finished musical instrument and explain one thing you changed in the code on DIY.org.

Fun facts

🎵A microcontroller can make sound by switching a pin on and off at different speeds—faster switching = higher pitch!
🤖Popular hobby boards like the Arduino Uno run at 16 MHz but use built-in timers for precise musical timing.
🔋A small piezo buzzer only uses a few milliamps, so a pair of AA batteries can play lots of tunes before running out.
🧩Most simple tones are square waves; changing pulse width or timing (PWM) can create new timbres and effects.
🎶Western music uses 12 notes in an octave — mix and match them to invent endless melodies and songs!
🎵A microcontroller can make sound by switching a pin on and off at different speeds—faster switching = higher pitch!
🤖Popular hobby boards like the Arduino Uno run at 16 MHz but use built-in timers for precise musical timing.
🔋A small piezo buzzer only uses a few milliamps, so a pair of AA batteries can play lots of tunes before running out.
🧩Most simple tones are square waves; changing pulse width or timing (PWM) can create new timbres and effects.
🎶Western music uses 12 notes in an octave — mix and match them to invent endless melodies and songs!

How do I build and code a simple musical instrument using a microcontroller?

Start by wiring the buzzer to a digital output pin and ground on your microcontroller, adding a current-limiting resistor if needed. Connect power (USB or battery) and any input like buttons or sensors. Write code using tone() or equivalent to play notes and sequences, uploading with the IDE. Test simple beeps, then program melodies, adjusting timing and pitch. Encourage kids to change notes, add buttons for play modes, and debug together with adult supervision.

Go deeper

What materials do I need to build a microcontroller musical instrument?

You’ll need a microcontroller (Arduino Uno/Nano, micro:bit, or Circuit Playground), a piezo buzzer or small speaker, jumper wires and a breadboard, a 220–1kΩ resistor for the buzzer, a USB cable or battery pack with appropriate voltage, pushbuttons or touch sensors for inputs, a computer with the programming IDE, and optional tape, a case, or alligator clips. For safety add a battery holder and basic tools like wire strippers and pliers.

Go deeper

What ages is this microcontroller music activity suitable for?

This activity suits children roughly 7–14+. Younger kids (7–9) can participate with close adult help for wiring and coding basics, using block-based editors. Ages 10–14 can handle simple circuits and text or block coding with some guidance. Teens can design more complex instruments, add sensors, and learn debugging independently. Adjust difficulty, supervision, and safety rules to match each child’s motor skills, attention span, and prior experience.

Go deeper

What safety tips should I follow when making a microcontroller musical instrument?

Always power off before wiring and double-check connections to prevent short circuits. Use the correct voltage battery pack and a resistor with piezo buzzers to limit current. Supervise young children when handling small parts or tools. Keep volumes moderate—start low and increase carefully to protect ears. Secure batteries in holders and avoid loose metal touching power rails. Teach basic troubleshooting and unplug hardware before adjusting circuits.

Go deeper

Watch & Learn

Need help?

What can we use as substitutes if we can't find the piezo buzzer, breadboard, or 220 ohm resistor?

If you can't find a piezo buzzer, use a small speaker wired through a 220 Ω or 330 Ω resistor (and an NPN transistor if needed) connected to digital pin 8, and if you don't have a breadboard use alligator-clip jumper leads to recreate the same connections between the microcontroller, buzzer/speaker, resistor, and GND.

What should I check if the melody doesn't play when I press the pushbutton?

If the melody doesn't play, verify the USB power, ensure the buzzer's positive lead goes to digital pin 8 through the 220 Ω resistor and its negative to GND, confirm the pushbutton straddles the breadboard gap with one side to 5V and the other to digital pin 2, and make sure the 10k pull-down resistor is between pin 2 and GND so the input isn't floating.

How can I adapt this activity for different age groups?

For younger children, pre-wire the breadboard (piezo, 220 Ω resistor, pushbutton, 10k pull-down) and let them press the button and change only the tempo number in the editor, while older kids can write new note sequences, add extra buttons or sensors, and upload their own sketches to the microcontroller.

What are simple ways to extend or personalize the musical microcontroller project?

Extend the project by adding a potentiometer to an analog pin to control tempo in code, wiring extra pushbuttons each with a 10k pull-down to trigger different melodies, or mounting the circuit in a decorated enclosure before sharing a photo and explaining the code change on DIY.org.

Your first game is on us.

Describe a game below - no sign-up needed to try.

Make me

KidsGPT has moved!

Log into ChatDino to access your chats

Powered by AstroSafe

3,127Devs Online
1,284Games Made
1,415,800Total Plays

Make real games - not just chat

DIY.org

Kid-safe AI for discovery and learning. Ask anything, explore everything, learn with confidence.

Product

  • Pricing
  • App
  • All Apps

Resources

  • Blog
  • Kids Wikipedia
  • Worksheets
  • Activities for Kids
  • Build a Hacker Simulator
  • SafeTube

Company

  • About
  • Terms & Conditions
  • Privacy Policy
  • AstroSafe
TwitterInstagramYouTube

© 2026 DIY.org. All rights reserved. · Powered by AstroSafe