This file contains the code to play the "Pirates of the Caribbean" Theme Song on a Arduino via a Buzzer
Youtube in action: https://www.youtube.com/watch?v=sjPAj1lXgtk
-
Download
Pirates_of_the_Caribbean_-_Theme_Song.ino -
Connect
Pin 10of the Arduino to thepositive sideof a buzzer or a microphone -
Connect any
resistor(220 ohms for example) to thenegative sideof a buzzer and to theground pinof the Arduino -
Upload the sketch and enjoy!
Don't have an Arduino with you right now? No worry. You can test it virtually on my simulated TinkerCAD circuit.
-
Click
Simulate -
Click
Start Simulationand enjoy!
Want to learn more about the science behind sound, buzzer, Arduino tone library? Check out my learning note on TipStory where I share a step by step walkthrough of the science and how I made this. I would appreciate a helpful upvote and an interesting upvote from you on TipStory.
πHappy engineering and designing!
This project was first created in 2016. It is recently updated on 2021.03.25, 5 years later. I know, sorry, I lost track of it, lol. There are a couple of improvements that can be made and have been made with this update:
-
You can remove the paper seal on the buzzer to make it sound better (Thanks Ricardo Moreno for the suggestion)
-
songSpeedandwaitare converted tofloattype (Thanks Andrew Lalis for catching the bug) -
noToneis used to handle malperformance of some Arduinos (Thanks Anthony Pelletier for bringing up this issue) -
In my previous comment, I said you can only use PWM pins for the buzzer. That is not true and has been corrected. You can use any digital pin
pin 0-13. The tone library uses a hardware timer and a timer interrupt to generate a square wave with different frequency, so it works on any digital pin. Beware that this might interfere with PWM when you useanalogWritebecause PWM also uses a timer. -
Better coding style, format, variable names... (I have learned a lot more about coding since I first exposed to C++ 5 years ago)