Did you know that you can play any song with an arduino passive buzzer?
For instance I played 'Hey Jude' by The Beatles
The two things you have to keep in mind when giving the inputs to play a song are the notes and the duration of each one of them. In the code below everything is explained but if something still confuses you i'll be more than happy to help you, just write a message on instagram to @brambiiiii.
The Digital Composer: Passive Buzzer Songs
Building on the "Happy Birthday" project, the Play Any Song framework provides you with a massive library of notes (a header file full of definitions like #define NOTE_C4 262) allowing you to transcribe actual sheet music into C++ code.

The "pitches.h" Framework
The secret to this project is utilizing an external header file called pitches.h.
- This file contains the exact frequency mapping for nearly 90 notes across 8 octaves.
- Instead of typing
tone(pin, 440), you can writetone(pin, NOTE_A4), which makes your code infinitely easier to read and debug. - You handle the tempo by defining a global variable (e.g.,
int tempo = 120) and using math to calculate the millisecond duration of whole notes, half notes, and 16th notes dynamically.
Hardware List
- Arduino Uno/Nano: The conductor.
- Passive Piezo Buzzer: The speaker.
- Potentiometer (Optional): Can be wired to analog input 0 to act as a live tempo dial, speeding up or slowing down the song while it plays!
Why This is Powerful
By separating the "data" (the notes and durations) from the "engine" (the for loop playing the tones), you learn a critical concept in software architecture. You can easily swap out the song arrays without ever touching the playback logic.