Play polyphony "Happy birthday" theme on Arduino Nano with three buzzers on a single mini breadboard.

First of all - demonstration

Plug this thing into any USB power source (not only a computer) and it will play "Happy birthday" melody indefinitely... like almost... until you get really sick of it =]

BTW, the lights are blinking in tact with every note change in a corresponding channel/buzzer.

Schematics

The idea was to make a super compact device with (almost) no soldering.

Actually, you CAN connect typical LEDs directly to Arduino boards WITHOUT any resistors - so it would be literally no-soldering-at-all project here. I've tried doing this way myself... really... it works... BUT! ... Doing this you can sometimes damage your Arduino board (it mostly depends on the particular board type and manufacturer) or burn your LED down... or both. So I wouldn't recommend doing this unless you've got a spare Arduino ;)

Eventually I've managed to fit everything needed on a tiny breadboard like this:

Holes are interconnected inside the breadboard in this way:

The trick here is that Arduino Nano board fits in such a breadboard just PERFECTLY allowing us to connect some additional components on both sides of the breadboard.

Sorry, guys... I'm too lazy to draw any diagrams here but this 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 analogue will do. The buzzers and the LEDs here are VERY ordinary ones. They don't have to match any special parameters actually.

The resistors here are 100 Ohm ones... although common "standard" for LED overload protection is 220 Ohm... but who cares... ¯\_(ツ)_/¯

The only thing that is probably not so obvious here on these photos is that the buzzers' pins are inserted into the breadboard this way:

Also note that the center one is bigger than the others - that's because this one is used for the "bass" music channel ☝🏻

... just kidding! ^__^ They all squeak like a crazy mouse choir with totally no difference in their sound capabilities =]

So you can use three identical buzzers if you wish with no problem, however you'll have to place them in a little different positions on the breadboard and also to change output pin numbers in the program code according to your new buzzers placement.

Also, note another little "hack" here... anyway are we on Hackster here or what? =] So I'm using several Arduino's I/O pins here as a ground pins for buzzers and LEDs 😱😱 . Yes... that's right. Actually, if you set a "LOW" state for any Arduino I/O pin in your program, then you can use these pins in the very same way you use standard GND pins on Arduino boards. Cool, right? ;)

About the program...

The full listing of the Arduino IDE sketch is provided below. However, you'll have to install an additional "Tone" library to be able compile the sketch which you can download here:

https://www.dropbox.com/s/q1udxg4yi47emeo/Tone.zip?dl=0

(if there is a pop-up window with а registration "proposal" just close it with "x" button in the corner)

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... еasy ¯\_(ツ)_/¯

This library is necessary to perform simultaneous generation of several tones on a single controller (it uses some additional hardware timers and hardware interrupts "under the hood" to achieve this goal). Simply put, it's some kind of "redneck-multitasking" on a single processor core without any OS =]

BTW, here is the author of the library (thanks bro! =] ):

http://playground.arduino.cc/Profiles/Bhagman

... and the GitHub page of the library:

https://github.com/bhagman/Tone

WARNING: I would STRONGLY NOT recommend using the latest version of "Tone" library from the GitHub page for this project as I've used MUCH older version here, so I can't guarantee that the project code below is compatible with the latest version of the library. You'd better use the one from the zip-archive I provided above. Anyway... feel free to try the last version if you want to and if you know what you are doing.

DISCLAIMER 🙂 :

Frankly speaking, my program code here is rather bulky and hard to read. That's mostly because of this need to "juggle" with three "independent" melody threads simultaneously from only one linear command flow. I was really thinking to refactor the code later to be able to separate the melodies from each other and to use it in the future for playing different songs... but I probably won't =]

So good luck. Any feedback is appreciated.

Thanks for reading to the end =]