Musical Bug

Introduction

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.

You will need
CodeBug CodeBug
Micro USB cable
Computer
Crocclips
OR Headphones
Buzzer
10k ohm potentiometer (optional)

1 Question
  • Which kind of buzzers fit to this project? Gábor Terék @ Dec. 28, 2016, 11:10 a.m.


    Answer this question:

  • Ask a new question:

Writing your program

To turn CodeBug into a music maker, you are going to program it to play notes from one of its legs. Follow the tutorial below to write your program.


  • Ask a new question:

Attaching your noise maker

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.


2 Questions
  • We have a black crock clip to GND, and colored to leg 0 with the metal plug in end of a speaker (not touching each other). We are not getting any sound after transferring the programming to the CodeBug and clicking B button. We get sound through the emulator though. What are we missing? piersonalp @ Dec. 21, 2016, 2:57 a.m.

    • We had the same problem and after a lot of fumbling about I found that 8 out of 10 gator clips we got with the Codebug were faulty with zero (or close to zero) conductivity. I don't know if those clips were shipped with the CodeBug or if they are from some random manufacturer. After finding two good gator clips the CodeBug was playing audio at a deafening volume as it is supposed to. :) — Aðalsteinn Guðmundsson @ Feb. 2, 2017, 12:53 p.m.


    You probably connected the noise maker incorrectly. LuisVM @ Aug. 6, 2017, 2:08 a.m.

    Answer this question:

  • We are also having trouble with playing audio with the codebug. We do get audio but one can only hear it extremely faintly with the speaker firmly pressed against one's ear. I thought it could be caused by the USB port used not sending enough power, but now I've tried all ports on the computer and even tried multiple computers. Even with battery installed the problem remains. I've even tried hooking the bug to an amplified speaker and then managed to hear the notes faintly in a sea of static with the volume turned all the way up. We are not using any resistors. Aðalsteinn Guðmundsson @ Feb. 2, 2017, 9:48 a.m.


    Answer this question:

  • Ask a new question:

Controlling volume

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.


  • Ask a new question:

What next

Try some of these other simple tunes such as Happy Birthday, Twinkle Twinkle Little Star or Swan Lake.


  • Ask a new question:

Back to top