Everybody loves a good tune, even CodeBug! You can program CodeBug to play music using a buzzer or speakers. Musical notes are generated on CodeBug by turning an output leg on and off very quickly at different frequencies depending on the note. You can control what note is played and for how long. By putting notes together, you can create tunes, make your own synthesisers or even make sounds for games.
|Micro USB cable|
|10k ohm potentiometer||(optional)|
Writing your program
Attaching your noise maker
Look out!The noise produced by your headphones when connected to CodeBug could be loud enough to damage your ears. Do not put headphones in your ears when they are connected to CodeBug.
Be carefulUse cheap headphones when connecting them to CodeBug as misuse could damage the headphones.
You can make music with CodeBug using a sounder or headphones/speakers and crocclips. First connect a black crocclip to the GND leg on CodeBug and a coloured crocclip to leg 0 on CodeBug.
To play the music through headphones or a speaker, clip the black crocclip that is connected to the GND leg, to the metal part of the headphone plug that is closest to the plastic cover. Now connect the coloured crocclip to the tip of the headphone plug. There should be a middle metal part of the plug that is not touching either crocclip.
Warning: This will be very loud, do not put the headphones into your ears.
To play music through a sounder, connect the black crocclip to one leg of the sounder and the coloured crocclip to the other leg of the sounder.
You will find that the volume of the music will be too loud when using headphones. You can change the volume by adding a resistor in series between leg 0 and the headphone tip. Larger resistor values will make the music quieter.
If you want to be able to vary the volume, you can add a potentiometer. Make sure you have followed this activity on using potentiometers. Disconnect your coloured crocclip from your headphones/buzzer and connect it to the power leg of the potentiometer. Now connect another crocclip from the output leg of the potentiometer to the tip of the headphone plug (or free leg of the buzzer). Finally connect the ground leg of the potentiometer to the GND leg on CodeBug.