Paying polyphony Happy birthday theme on Arduino Nano with three buzzers on a single mini breadboard.
Plug this thing to any USB power source (not only computer) and it will play Happy birthday song infinitely... almost... until you get really sick of it.
BTW light are blinking in tact with note change in every corresponding buzzer.
The idea was to make a compact device with (almost) no soldering.
Actually you can use LEDs with Arduino WITHOUT any resistors - so it will be NO soldering at all... I tried it myself... really... it works... BUT in such a way you can damage your Arduino board (it also depends on board manufacturer) or burn 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 thing is that Arduino Nano fits in such a breadboard perfectly, allowing to connect some components on both sides.
Sorry, guys, I'm so lazy that I won't draw any diagrams, but it's all very simple and I hope that these close-ups will be 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.
Resistors are 100 Ohm... although classics for LEDs are 220 Ohm resistors... but who cares ¯\_(ツ)_/¯
Maybe the only thing that is not obvious here is that buzzers are inserted into breadboard like this:
Note that the center one is bigger than others - this is because its used for "bass" music channel.
They all squeak like a mouse with almost no difference in sound capabilities.
So you can use three identical buzzers, however you'll have to place them a little differently on a board and change output pin numbers in program according to your placement.
Also you can see that I'm using several I/O pins as ground pins for buzzers and LEDs. Yes, that's right. You can set a LOW state for any Arduino I/O pin in your program and then use this pin like you use standard GND pin. Cool hack, right?
Full listing of Arduino IDE sketch is provided below.
However you'll need to install additional Tone library to compile the sketch, which you can get here:
The easiest way to install this library is the following: in Arduino IDE main menu choose Sketch - Include Library - Add .ZIP Library... and select the downloaded zip-file.
This library is needed to perform simultaneous generation of several tones on a single controller and it uses several additional hardware timers and hardware interrupts to achieve this goal. Shortly speaking it's some kind of redneck multitasking without OS.
Here is the author of the library...
... and GitHub page of the library...
WARNING: I would STRONGLY not recommend to use the latest version of the library from GitHub as I used older version in my project and I can't guarantee that it's compatible with the latest version of library. You should better use the one from the zip-archive I provided before. But feel free to try the last one if you want and know what you are doing.
Frankly speaking my program is rather bulky and hard to read. This is because you need to juggle three melody threads simultaneously from one linear command flow. I was thinking to optimize the code to be able to separate 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.