Arduino Buzzer Music Tutorial (Play Do-Re-Mi with Arduino)
Yo squad! ๐ In this project, we’re gonna make our Arduino sing like a baby piano using a buzzer. Yup, we’re coding some simple notes (Do-Re-Mi-Fa-Sol-La-Si-Do) so your Arduino can vibe with you
Stuff You’ll Need
-
1x Arduino UNO
-
1x Active Buzzer / Piezo Buzzer ๐
-
Jumper Wires
-
USB Cable to connect Arduino to PC
Wiring Guide
Check the wiring on the diagram ๐
-
Buzzer (+) → Pin 9 on Arduino
-
Buzzer (–) → GND
That’s it. Super simple. EZ clap ๐
The Code
Here’s the full sketch. Copy-paste into Arduino IDE and upload ⬇️
const int buzzerPin = 9; // Pin for the buzzer
// Frequency for each musical note
const int NOTE_C = 261;
const int NOTE_D = 294;
const int NOTE_E = 329;
const int NOTE_F = 349;
const int NOTE_G = 392;
const int NOTE_A = 440;
const int NOTE_B = 493;
const int NOTE_C_HIGH = 523;
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
}
void loop() {
playTone(NOTE_C); // Do
playTone(NOTE_D); // Re
playTone(NOTE_E); // Mi
playTone(NOTE_F); // Fa
playTone(NOTE_G); // Sol
playTone(NOTE_A); // La
playTone(NOTE_B); // Si
playTone(NOTE_C_HIGH); // High Do
delay(1000); // Wait before repeating
}
void playTone(int frequency) {
tone(buzzerPin, frequency); // Play note
delay(500); // Hold for 0.5s
noTone(buzzerPin); // Stop sound
delay(100); // Small pause
}
What’s Happening
-
The tone() function makes the buzzer produce sound at a given frequency.
-
Each frequency corresponds to a musical note ๐ถ
-
We made the Arduino play Do → Re → Mi → Fa → Sol → La → Si → Do in order.
-
It’s basically a mini xylophone coded with C++ vibes
Wrap-Up
And boom ๐ฅ now you’ve got yourself an Arduino that sings. You can:
-
Change frequencies for different tunes
-
Add more delays for rhythm ๐ฅ
-
Even try coding full songs (Mario theme anyone? ๐ฎ)
Flex this project to your friends and be like:
“Yeah, my Arduino’s basically a DJ now.” ๐
Komentar
Posting Komentar