In this tutorial I am how you can use an Arduino to make music using just with a speaker (no MP3 module required).
First watch this video tutorial
Hardware needed
1.an Arduino
2.A speaker or a buzzer
Circuit diagram
How does it work?
The Arduino in this circuit creates tones of different frequencies and plays it through the speaker connected to it. The variation of the frequency of the tone(pitch) with correct timings(rhythm) creates music. The Arduino generates a signal and outputs it through the Digital pin 8. This drives the speaker connected to the pin to create sound.In this tutorial, I have programmed the Arduino to play a song ‘astronomia coffin dance’.
Software side
pitches.h library contains all notes of all frequencies
With the help of pitches.h i created this project
How I made melody[ ] and noteDurations[ ] of this song:
If you take a look at the program, you can find two int arrays: melody[ ] and noteDurations[ ]. The first array contains the notes and the second array contains its corresponding durations. I wrote down the musical notes of this song first and then wrote the melody[ ] array with that.
Then I wrote noteDurations[ ] according to the length of each music note. Here 8 = quarter note, 4 = 8th note, etc. Higher value gives longer duration notes. The note and its corresponding duration is what is there in melody[ ] and noteDurations[ ] respectively. You can modify those and create any song according to your ideas
Leave a comment