For this project we will include a dip switch which will allow you to select which of the 4 tunes you'd like to play. Also included on board is the programming jack and circuit so that you can program and re-program the PICAXE at will.
Once you have this circuit built you could also write a program to use the "tune" and "sound" commands. You could also write a program to use the Tune Wizard and import a cellphone ring tone. For now I will only include the program and set up to play the four pre-canned tunes and will leave it to the reader to experiment with other programs.
I'd estimate that you can build and program this project in about 2 hours if you have all the parts ready and already have the programming software and interface cable drivers set up on your PC. The estimated cost is about $10 using the approximate prices I paid - PICAXE $2.50, Speaker $4, Jack $1.50, vector board $1, resistors & wire $1 and assumes you already have a 5V power source such as a wall wart or bench top supply, tools, solder etc. 3 AA batteries in a clip to give 4.5 V is a good power supply too.
For this project a prerequisite is that you have the PICAXE Programming Editor set up on your PC as well as the programming cable drivers and programming cable and that you know how to use them.
Step 1: PICAXE Project Parts List
1 - 8 ohm speaker or 40 ohm speaker and omit the 33 ohm resistor when using 40 ohms.
1 - 8 pin IC Socket
1 - 3mm stereo jack
1 - 22K ohm resistor
1 - 33 ohm resistor
3 - 10K ohm resistors
1 - two position dip switch or equivalent switches
1 - 5V power source - wall wart, bench top supply or 3 AA batteries in a battery clip.
1 - 9V battery connector (optional if using clip)
1 - small vector board approximately 1.5" x 2.5"
1 - 22 gauge solid core and stranded wire
Step 2: PICAXE Tune Player Circuit Diagram
First you see the programming jack attached to the serial in/out pins and ground as per the PICAXE specifications.
The C.3 and C.4 pins are connected to +5V via 10K resistor which normally holds them high. The dip switches are also connected to the C.3 and C.4 pins and this will pull them to ground when the switches are closed. By this means, we will tell the PICAXE which of the 4 internal tunes to play. With just two switches we have 4 states 0,0 or 0,1 or 1,0 or 1,1 where 1 is +5V on the pin and 0 is ground on the pin.
The loudspeaker, which in this case is an 8 ohm speaker, is connected through a 33 ohm resistor as the PICAXE specification recommends that Pin 5 is driving into 40 ohms. As there is no 32 ohm resistor readily available, use 33 ohms. For other speaker impedances, use an appropriate resistor value.
Each pin of the 08M2 has other functions but here the pins are labelled only with the pin function of interest for this project. Note that with the 8 Pin PICAXE only Pin 5, the C.2 pin can be used to output music to the speaker.
Step 3: PICAXE Project - Programming Jack Connections
Step 4: PICAXE Tune Player Program
Here we have set the com port on the computer to com port 3 using the directive #com 3. If you have trouble communicating with the PICAXE, select View > Options > Serial Port in the Program Editor and see which Com port says "Ready for use AXE027 PICAXE USB". Next change the directive in the program to the com port you are using on you PC. For example if you are using com port 4, then set the directive to #com 4, not #com 3 as we have here. Next save the program and check syntax to make sure you are good to go and then program your PICAXE.
' =============== Play.bas ===============
' This program runs on a PICAXE-08M2.
' It plays the pre-canned tunes in an 08M2
' === Constants ===
symbol SWCH1 = pinC.3 ' Programming Switch 1
symbol SWCH2 = pinC.4 ' Programming Switch 2
' === Directives ===
#com 3 ' specify serial port
#picaxe 08M2 ' specify processor
' ============= Begin Main Program =============
if SWCH1 = 0 and SWCH2 = 0 then Play 0, C.2 endif ' Play Happy Birthday
if SWCH1 = 1 and SWCH2 = 0 then Play 1, C.2 endif ' Play Jingle Bells
if SWCH1 = 0 and SWCH2 = 1 then Play 2, C.2 endif ' Play Silent Night
if SWCH1 = 1 and SWCH2 = 1 then Play 3, C.2 endif ' Play Rudolph the Res Nosed Reindeer
Step 5: PICAXE Tune Player Files and Attachments
1. 08M2 Player Program.bas
2. Circuit diagram
3. Programming Jack Connections
4. PICAXE Manuals