Playing popular songs with Arduino and a buzzer

Popular songs and melodies generated with a buzzer

Nov 19, 2022

201945 views

8 respects

Components and supplies

1

Arduino Nano

1

Buzzer

1

Dupont cables

1

Mini Breadboard

Apps and platforms

1

Arduino IDE

Project description

Code

HiBit - Buzzer

Official HiBit repository for buzzer: wiring, schema and Arduino code (including libraries).

Latest commit to the master branch on 02-02-2025

Downloadable files

Buzzer

Wiring schema for buzzer and Arduino Nano

Buzzer

Comments

Only logged in users can leave comments

jreyes223

14 days ago

what is the main website???

jan_92

20 days ago

Can you please add theme song from squid game? It would be awesome.

kayaaki

a month ago

How did you guy's get the code to the different songs?

drklein

2 months ago

Please Space taxi from "Raumschiff suprise" i need it for school!

cdmanbg

3 months ago

# Karateka 1984 - Final Song #include "pitches.h" // notes in the melody: int melody[] = { NOTE_A3,NOTE_C4,NOTE_E3,NOTE_B3, NOTE_C3,NOTE_A3,NOTE_E3,NOTE_B3, NOTE_D3,NOTE_A3,NOTE_B3,NOTE_F4, NOTE_E3,NOTE_GS3,NOTE_B3,NOTE_D4, NOTE_CS3,NOTE_CS4,NOTE_GS3,NOTE_B3, NOTE_FS3,NOTE_A3,NOTE_D3,NOTE_FS4, NOTE_E3,NOTE_A3,NOTE_B3,NOTE_E4, NOTE_E3,NOTE_GS3,NOTE_E4,NOTE_D4, NOTE_CS4,NOTE_A3,NOTE_D4,NOTE_B3, NOTE_E4,NOTE_CS4,NOTE_A3,NOTE_E3, NOTE_CS3,NOTE_F3,NOTE_A3,NOTE_CS4, NOTE_B3,NOTE_GS3,NOTE_F3,NOTE_B2, NOTE_A2,NOTE_CS3,NOTE_FS3,NOTE_A3, NOTE_D3,NOTE_FS3,NOTE_B3,NOTE_D4, NOTE_E3,NOTE_A3,NOTE_D4,NOTE_CS4, NOTE_E3,NOTE_GS3,NOTE_C4,NOTE_B3 }; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }; void setup() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 64; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; tone(8, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(8); } }

muhackl

3 months ago

Good job! Well now it's getting Xmas already. I found "Jingle Bells" in your folders. But how about "Santa Clause is coming to town" and "We wish you a merry christmas"? Can't wait to build this into a Christmas decoration and surprise my son.

muhackl

3 months ago

Alternatively: Is there some sort of generator or can you promt some AI tool to generate the song?

ninja_plys

4 months ago

Can you add Bad Boys by Innercircle?

ninja_plys

2 months ago

int melody[] = { NOTE_A4, NOTE_A4, NOTE_A4, NOTE_E4, REST, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_C4, REST, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, REST, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_A4, NOTE_C4, REST, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_A4, NOTE_A4 }; int noteDurations[] = { 4, 4, 4, 4, 4, 8, 8, 8, 8, 4, 4, 8, 8, 8, 8, 4, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 4, 2, 8, 8, 8, 8, 4, 8, 8, 4, 4, 4 };

viktor596

5 months ago

Can you please add the flawless wings of yatagaratsu by stingingmeat

samiuwu

5 months ago

can u do jeniffer's boddy- ken carson? thx for the code and the other songs<3333

georgewalk

7 months ago

#define a3f 208 // 208 Hz #define b3f 233 // 233 Hz #define b3 247 // 247 Hz #define c4 261 // 261 Hz MIDDLE C #define c4s 277 // 277 Hz #define e4f 311 // 311 Hz #define f4 349 // 349 Hz #define a4f 415 // 415 Hz #define b4f 466 // 466 Hz #define b4 493 // 493 Hz #define c5 523 // 523 Hz #define c5s 554 // 554 Hz #define e5f 622 // 622 Hz #define f5 698 // 698 Hz #define f5s 740 // 740 Hz #define a5f 831 // 831 Hz #define rest -1 int piezo = 7; // Connect your piezo buzzer to this pin or change it to match your circuit! int led = LED_BUILTIN; volatile int beatlength = 100; // determines tempo float beatseparationconstant = 0.3; int threshold; int a; // part index int b; // song index int c; // lyric index boolean flag; // Parts 1 and 2 (Intro) int song1_intro_melody[] = {c5s, e5f, e5f, f5, a5f, f5s, f5, e5f, c5s, e5f, rest, a4f, a4f}; int song1_intro_rhythmn[] = {6, 10, 6, 6, 1, 1, 1, 1, 6, 10, 4, 2, 10}; // Parts 3 or 5 (Verse 1) int song1_verse1_melody[] = { rest, c4s, c4s, c4s, c4s, e4f, rest, c4, b3f, a3f, rest, b3f, b3f, c4, c4s, a3f, a4f, a4f, e4f, rest, b3f, b3f, c4, c4s, b3f, c4s, e4f, rest, c4, b3f, b3f, a3f, rest, b3f, b3f, c4, c4s, a3f, a3f, e4f, e4f, e4f, f4, e4f, c4s, e4f, f4, c4s, e4f, e4f, e4f, f4, e4f, a3f, rest, b3f, c4, c4s, a3f, rest, e4f, f4, e4f }; int song1_verse1_rhythmn[] = { 2, 1, 1, 1, 1, 2, 1, 1, 1, 5, 1, 1, 1, 1, 3, 1, 2, 1, 5, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 5, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 3, 1, 1, 1, 3 }; const char* lyrics_verse1[] = { "We're ", "no ", "strangers ", "", "to ", "love ", "", "\ \ ", "You ", "know ", "the ", "rules ", "and ", "so ", "do ", "I\ \ ", "A ", "full ", "commitment's ", "", "", "what ", "I'm ", "thinking ", "", "of", "\ \ ", "You ", "wouldn't ", "", "get ", "this ", "from ", "any ", "", "other ", "", "guy\ \ ", "I ", "just ", "wanna ", "", "tell ", "you ", "how ", "I'm ", "feeling", "\ \ ", "Gotta ", "", "make ", "you ", "understand", "", "\ \ " }; // Parts 4 or 6 (Chorus) int song1_chorus_melody[] = { b4f, b4f, a4f, a4f, f5, f5, e5f, b4f, b4f, a4f, a4f, e5f, e5f, c5s, c5, b4f, c5s, c5s, c5s, c5s, c5s, e5f, c5, b4f, a4f, a4f, a4f, e5f, c5s, b4f, b4f, a4f, a4f, f5, f5, e5f, b4f, b4f, a4f, a4f, a5f, c5, c5s, c5, b4f, c5s, c5s, c5s, c5s, c5s, e5f, c5, b4f, a4f, rest, a4f, e5f, c5s, rest }; int song1_chorus_rhythmn[] = { 1, 1, 1, 1, 3, 3, 6, 1, 1, 1, 1, 3, 3, 3, 1, 2, 1, 1, 1, 1, 3, 3, 3, 1, 2, 2, 2, 4, 8, 1, 1, 1, 1, 3, 3, 6, 1, 1, 1, 1, 3, 3, 3, 1, 2, 1, 1, 1, 1, 3, 3, 3, 1, 2, 2, 2, 4, 8, 4 }; const char* lyrics_chorus[] = { "Never ", "", "gonna ", "", "give ", "you ", "up\ \ ", "Never ", "", "gonna ", "", "let ", "you ", "down", "", "\ \ ", "Never ", "", "gonna ", "", "run ", "around ", "", "", "", "and ", "desert ", "", "you\ \ ", "Never ", "", "gonna ", "", "make ", "you ", "cry\ \ ", "Never ", "", "gonna ", "", "say ", "goodbye ", "", "", "\ \ ", "Never ", "", "gonna ", "", "tell ", "a ", "lie ", "", "", "and ", "hurt ", "you\ \ " }; void setup() { pinMode(piezo, OUTPUT); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(9600); flag = true; a = 4; b = 0; c = 0; } void loop() { // play next step in song if (flag == true) { play(); } } void play() { int notelength; if (a == 1 || a == 2) { // intro notelength = beatlength * song1_intro_rhythmn[b]; if (song1_intro_melody[b] > 0) { digitalWrite(led, HIGH); tone(piezo, song1_intro_melody[b], notelength); } b++; if (b >= sizeof(song1_intro_melody) / sizeof(int)) { a++; b = 0; c = 0; } } else if (a == 3 || a == 5) { // verse notelength = beatlength * 2 * song1_verse1_rhythmn[b]; if (song1_verse1_melody[b] > 0) { digitalWrite(led, HIGH); Serial.print(lyrics_verse1[c]); tone(piezo, song1_verse1_melody[b], notelength); c++; } b++; if (b >= sizeof(song1_verse1_melody) / sizeof(int)) { a++; b = 0; c = 0; } } else if (a == 4 || a == 6) { // chorus notelength = beatlength * song1_chorus_rhythmn[b]; if (song1_chorus_melody[b] > 0) { digitalWrite(led, HIGH); Serial.print(lyrics_chorus[c]); tone(piezo, song1_chorus_melody[b], notelength); c++; } b++; if (b >= sizeof(song1_chorus_melody) / sizeof(int)) { Serial.println(""); a++; b = 0; c = 0; } } delay(notelength); noTone(piezo); digitalWrite(led, LOW); delay(notelength * beatseparationconstant); if (a == 7) { // loop back around to beginning of song a = 1; } } //rickroll your friends and say Gdubs sent you

hibit

6 months ago

Could you please submit a pull request to our repository so we can include it with the other melodies and credit you as the author?

quantun97

10 months ago

If you can do Yoshi's Island Athletic theme, please.

hibit

6 months ago

Yoshi's Island theme has been added. You can find it in our GitHub repository.

rin_katz

a year ago

superpowers daniel caesar

hibit

6 months ago

The song involves many chords, and it doesn't sound right or similar when played with a buzzer.

justmanwell

a year ago

neverever by destroy lonely

hibit

6 months ago

We weren't able to find the correct notes for this song.

milespeterson101

a year ago

Please add Never Gonna Give You Up | Rick Astley

hibit

7 months ago

Never Gonna Give You Up has been added. You can find the code on our main website.

kegx

a year ago

Never gonna give you up?

hibit

7 months ago

Never Gonna Give You Up has been added. You can find the code on our main website.

hibit

a year ago

It's a small world song has been added. You can find the code on our main website. Enjoy!

hibit

a year ago

Chevelle The Red song has been added. You can find the code on our main website. Enjoy!

hibit

a year ago

Imagine Dragons Enemy has been added. You can find the code on our main website. Enjoy!

hibit

a year ago

The Simpsons theme song has been added. You can find the code on our main website. Enjoy!

kapishv

a year ago

Hello, It would be great if there could be the song Enemy - Imagine Dragons. Thanks.

hibit

a year ago

Imagine Dragons Enemy has been added. You can find the code on our main website. Enjoy!

gibsogm

2 years ago

Hello Arduino, I would love for there to be the Simpsons them song. Thankyou.

hibit

a year ago

The Simpsons theme song has been added. You can find the code on our main website. Enjoy!

jreyes223

14 days ago

what is the main website

jreyes223

14 days ago

what is the main website