codeBuglogo.pngIntroducing CodeBug!

  What is CodeBug

  10 CodeBug Projects in 10 Days

  Are You a STEM Educator?


Getting Started:

flashing an LED.png

We start the project by visiting the CodeBug website and creating an account. It only takes a few minutes. While logged in, clock on Create to start a new project. Don't forget to save your work!


The interface for CodeBug contains an area to the right of the screen with is the primary programming interface. There are a series of menus that are used to store the blocks with can be dragged from the menus into the coding area. Good blocks are made to connect together, and that is what we intend to do!


Now that you have familiarized yourself with the interface, let's get started on an intermediate project Thomas Macpherson-Pope pulled together from



What you need:


Micro USB CableMicro USB Cable

CR2032 BatteryCR2032 Battery

Crocodile  Clips




The Project


CodeBug’s legs can be used to turn LEDs (and other things!) on or off. In this mode the legs are called Outputs.

Before we get into how to Flash an LED, lets talk a little bit about  how LEDs work

LED stands for light emitting diode, they are essentially really small light bulbs. So firstly, what is a diode? A diode is simply something that lets electricity flow in one direction and not the other.

LEDs create light because they are made of two different materials. One of the materials requires the electrons to have less energy so they lose their extra energy in the form of light.

Now that we have  basic understanding of how an LED works, lets get to work on how to flash one using the CodeBug!

We will start by connecting a red croc-clip to the power leg (PWR) of CodeBug and another croc-clip to leg 0.

LEDs have two leads and one is longer than the other. The longer lead is the positive one, so connect this to the red croc-clip that is attached to the PWR leg on CodeBug. The shorter lead is the negative one, so connect this to the croc-clip attached to leg 0. LEDs will also sometimes have a flat edge on the plastic casing, this indicates the negative side.

Now that the LED is hooked up to the bug, let's set up the program.


First we will need to set up the Legs in the Emulator. To set the Legs of the CodeBug we will need to first configure the Emulator. To do this we will need to open the emulator configuration via the settings cog on the emulator. Tick the Show Leg Controls box. Click on the Configure Emulator button to complete the settings change. The Emulator will now show the status of the CodeBug's legs with blue arrows. The arrow pointing to the legs is the Input, away from the legs is the Output. When the background of the leg is red, the leg is at Power, when the leg is at black, it is Ground.



Now that the Emulator has been configured, we can begin programming the legs. To do this we will need to click on the Cog of the Start block. From the popup we can drag the Leg Input/Output block into the Start block on the right. Because we want to control an LED we will need to tell CodeBug to use Leg 0 as Output for the purposes of this project we will set the Leg at "0" as "output".






Now we want to set Leg 0 to Ground so the current flows from CodeBug's power leg, through the LED, and to 0. To do this we will need to drag in a Set Leg block from the Inputs/Outputs menu and snap it to our Start block.




To flash an LED we will need to turn it on and off with a pause in between. From the Basic Menu drag in a Pause block and snap it beneath your Set Leg block. From the Inputs/Outputs menu drag in another Set Leg block and snap it beneath your Pause block. Set this new Set Leg block's second number box to 1. Because we will want this LED to continuously flash, lets add a Loop. We will go to the Loops menu and drag in a Repeat While True block onto the work space. Next we will snap in the Loop block to the Start block and move the code into the Loop.  From the Basics menu we drag in another Pause block, moving that inside the While loop, underneath the second Set Leg block.



Now it's time to see if it works via the Emulator...



With the program working we can now send that over to the CodeBug...


With the code working, click on Download, it's just under the simulator controls. When the code downloads, plug in a USB to micro USB into your computer. While holding Button A of your CodeBug also insert the micro USB to the CodeBug. The top left LED in the matrix on the CodeBug will flash. Your computer should also recognize the CodeBug as a USB drive on your computer. Copy the code downloaded from the CodeBug website to the USB drive and run the program by pressing Button B.





See more CodeBug projects and learn how you can get one of your own by visiting: 10 CodeBug Projects in 10