Paying polyphony Happy birthday theme on Arduino Nano with three buzzers on a single mini breadboard.
Plug this thing into any USB power source (not only a computer) and it will play "Happy birthday" song indefinitely... like almost... until you get really sick of it =]
BTW, the lights are blinking in tact with note change in every corresponding channel/buzzer.
The idea was to make a compact device with (almost) no soldering.
Actually you can use typical LEDs with Arduino WITHOUT any resistors - so it will be NO soldering at all... I've tried it myself... really... it works... BUT!... in this case you can sometimes damage your Arduino board (it mostly depends on board type and manufacturer) or burn out your LEDs... or both. So I won't recommend doing this unless you've got a spare Arduino ;)
Eventually I managed to fit everything needed on a tiny breadboard like this:
Holes are interconnected inside the breadboard like shown below:
The trick is that Arduino Nano board fits in such a breadboard just PERFECTLY allowing us to connect some components on both sides of it.
Sorry, guys, I'm too lazy to draw any diagrams here, but the case is so simple that I'm sure these close-ups will be more than enough to figure everything out =]
As you can see, I'm using Arduino Nano v3.0 board from Gravitech here, but any analog will be OK. Buzzers and LEDs are VERY ordinary ones. They don't have to match any special parameters actually.
Resistors are 100 Ohm... though common "standard" for LEDs overload protection is 220 Ohm... but who cares ¯\_(ツ)_/¯
The only thing that is probably not so obvious here on the photos is that buzzer's connectors are inserted into the breadboard this way:
Note that the center one is bigger than others - this is because its used for "bass" music channel ☝🏻
... just kidding! ^__^ They all squeak like a crazy mouse choir with obviously no difference in sound capabilities.
So you can use three identical buzzers if you wish with no problems, however you'll have to place them in a little different positions on the board and also change output pin numbers in the program code according to your new buzzers' placement.
Also, note that I'm using a number of I/O pins as a ground pins for buzzers and LEDs. Yes, that's right. You can set a LOW state for any Arduino I/O pins in your program and then use these pins in a way you use standard GND pin. Cool hack, right? ;)
The full listing of Arduino IDE sketch is provided below. However, you'll have to install additional "Tone" library to compile the sketch, which you can get here:
(if there is a pop-up window with registration "proposal" just close it first with "x" button first)
The easiest way to install this library is the following: in Arduino IDE main menu choose Sketch - Include Library - Add .ZIP Library... and then select your downloaded zip-file.
This library is necessary to perform simultaneous generation of several tones on a single controller (it uses some additional hardware timers and hardware interrupts to achieve this goal). Shortly speaking it's some kind of redneck-multitasking on a single processor core without OS =]
BTW, here is the author of the library (thanks bro! =] ):
... and a GitHub page of the library:
WARNING: I would STRONGLY NOT to recommend using the latest version of the library from GitHub with the project as I used MUCH older version and I can't guarantee that the project code below it's compatible with the latest version of the library. You should better use the one from the zip-archive I provided above. Anyway... feel free to try the last one if you want to and know what you are doing.
Frankly speaking my program is rather bulky and hard to read. That's mostly because of need to "juggle" THREE melody threads simultaneously here from ONE linear command flow. I was really thinking to refactor the code later to be able to separate the melodies from each other and use it in future for playing different songs... but I probably won't =]
So good luck. Any feedback will be appreciated.
Thanks for reading to the end =]