You’ve probably seen postcards where you open them and it starts playing “Happy Birthday” tune. This is really easy when you know how. Embedded lab shows how to do this with PIC16F628A microcontroller and buzzer. Buzzer is connected via transistor switch and this is all setup needed.
The idea of generating sound here is simple. All you need is to have note frequencies that are stored in array. And for note duration there are another array. According to that data microcontroller simply generates square wave and so you hear a sound. As Christmas not far away you can start putting “Merry Christmas” song.