codeBuglogo.pngIntroducing CodeBug!

  What is CodeBug

  10 CodeBug Projects in 10 Days

  Are You a STEM Educator?


Getting Started:


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 beginner 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 also detect electrical currents. In this mode they are called Inputs.

Before we get into how to use a button with CodeBug, we should first talk a little bit about what a button is.

Buttons work by controlling whether two contacts are connected or not. When the button is pushed the two sides are connected and electricity can flow. In the off state (not-pressed) no electricity will flow. The button diagram to the right shows how the two CodeBug's button legs are connected. The two legs on the left are always connected together, and the two legs on the right are always connected together. While you press the button, the left side and the right side are connected.

Now that we have a basic understanding of how a button works, let's get to work on how to use one on the CodeBug!

Connect a black croc-clip to the ground leg (GND) on CodeBug and attach the other end of the croc-clip to a leg on the button. Now connect another croc-clip to Leg 1 of CodeBug and the other end to the opposite leg on the button (diagonally across from the Leg you have already connected to).

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

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 into the legs denotes that it's set as an Input; away from the legs is an Output. When the background of the leg is red, the leg is at Power, when the leg is 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 the Leg to sense a button, we will need to tell CodeBug to use Leg 1 as an Input. .


We want CodeBug to run different code depending on whether a button is pressed. In order to do this we will need an If block and a block that checks to see if the Leg is connected to Ground via the button.  We will start by dragging in an If Else block and placing it in an empty space on the workstation. From the Input/Output menu we will drag a Leg Grounded block.

We will need different code to run when the button is pressed. If it is pressed we should get a Set Pixel block to turn the LED display on, and a Set Pixel block to turn it off. To do this we we need to take two Set Pixel blocks from the 5X5 Display menu. Next we will snap them both inside the If Else block, one under If and the other under Else. We will set the Else section to 0. We will want this code to repeat so we will need to add a Repeat While True loop and snap it into the Start block. Finally we will drag in the code into the Repeat While True loop.


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 emulator controls. When the code downloads, plug a USB to micro USB cable into your computer. While holding Button A of your CodeBug also insert the micro USB into 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 downloaded code from the CodeBug website to the USB drive and run the program by pressing Button B. If your CodeBug is on battery power, you can now disconnect the USB cable.




CodeBug’s legs are also touch sensitive, so we don’t have to use switches -- we can just use our hands!

  • Leave the program on CodeBug from the above project and make sure CodeBug is powered on.
  • Disconnect the button from the croc-clips, but we're going to leave the croc-clips connected to CodeBug’s Legs (1 and GND).
  • Hold the metal end of one croc-clip in one hand and touch the end of the other croc-clip with the other hand.
  • While touching the clip, CodeBug senses it and runs the blocks of code we told it to.

This works because everything containing a lot of water will conduct a small amount of electricity. This is not enough electricity to power something like an LED, but it is enough for CodeBug’s legs to sense contact. Since the human body is about 70% water WE conduct this small amount of electricity too!

Try holding a friend’s hand and get them to touch the other croc-clip.

Gather some more friends and see how many how people can be in the chain before CodeBug can’t sense the electricity anymore. Each extra person adds some resistance to the electricity in the chain. Each person in the chain adds more resistance which makes it harder for the electricity to flow.


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