Have you always wanted to add sound or music to you Arduino projects? It's easier than you think!
In this project I will show you how to play a song using a buzzer. We are going to let the Arduino Father Jacob play by adjusting the hertz of the buzzer. By adjusting the frequency we can play higher and lower tones.
The way a buzzer makes this frequency is as follows. There is a magnet in the buzzer that goes back and forth through electrical pulses. This magnet then hits a thin plate or sheet, which then vibrates at a certain frequency, creating sound.
- Level - Beginner 30%
- Duration - 10/15 Min 30%
- Costs - € 35,84 euros complete 30%
Step 1: Requirements
1X Arduino UNO
1X breadboard
2X M / M jumper wires
1X piezo buzzer
Step 2: Building and Wiring
Step 3: Programming
To make the Buzzer Father Jacob play, we make a simple code.
You just need to define pin 9 and give the tones the correct frequency and rhythm.
Then you put the frequency values in succession with a rhythm of 120 bpm (beats per minute).
When you have done that and you upload the code to your Arduino, he will play father Jacob. It is also possible to play other songs with a buzzer. If you want, you just need to change the notes and their frequency.
// definition of the pin where the buzzer is
const int buzzer = 9;
// here we define pin 9 as output
void setup () {
pinMode (buzzer, OUTPUT);
}
// here we make our song
void loop () {
tone (buzzer, 2093);
delay (500);
tone (buzzer, 2349);
delay (500);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 0);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 2349);
delay (500);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2794);
delay (500);
tone (buzzer, 3136);
delay (1000);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2794);
delay (500);
tone (buzzer, 3136);
delay (1000);
tone (buzzer, 0);
tone (buzzer, 3136);
delay (250);
tone (buzzer, 3520);
delay (250);
tone (buzzer, 3136);
delay (250);
tone (buzzer, 2794);
delay (250);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 3136);
delay (250);
tone (buzzer, 3520);
delay (250);
tone (buzzer, 3136);
delay (250);
tone (buzzer, 2794);
delay (250);
tone (buzzer, 2637);
delay (500);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 0);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 1568);
delay (500);
tone (buzzer, 2093);
delay (1000);
tone (buzzer, 0);
tone (buzzer, 2093);
delay (500);
tone (buzzer, 1568);
delay (500);
tone (buzzer, 2093);
delay (1000);
tone (buzzer, 0);
}
How can you enter a 6/8 measure in Arduino?
Father Jacob is 4/4
hey roel,
You can adjust the tempo by changing the delay.