Waving Codebug


Give CodeBug moving arms and legs using servos – small electric motors.

Jumper cables come in three main types as shown below. This activity assumes your servos have female sockets to connect to, and therefore we will use male to male jumper cables (but you can use male to female cables if your servo has male pins).

A servo is a precise motor that can rotate a certain number of degrees (usually 180°). Servos are great for making robot arms, cranes or even robots.

You will need
CodeBug CodeBug
Servo motor
Jumper cables
OR Card
Thick paper
Single-sided tape

  • Ask a new question:

Wiring up the servo

You may need to check the information sheet of your servo, however they usually have three wires. The brown wire is negative (GND), red is positive (PWR) and orange is data input.

Plug in one male to male jumper wire into each hole in your servo’s socket. Plug the jumper connected to the brown wire into the socket labeled GND on CodeBug’s expansion port. Plug the jumper connected to the red wire into the socket labeled VCC on CodeBug’s expansion port. Finally plug the jumper connected to the orange wire into the socket labeled SDO on CodeBug’s expansion port.

3 Questions
  • Don't you mean male to male instead of female to female jumper wires? — veryalien @ May 13, 2016, 9:11 p.m.

    • oops, thanks have corrected that now — Thomas Macpherson-Pope @ May 23, 2016, 9:26 a.m.

    Answer this question:

  • How do I connect 2 servos to the Codebug? — claire @ May 31, 2016, 9:52 a.m.

    Tom, thanks, I'm nearly there. I get the second servo to work now but not both together. Do I need something in between my 2 servo blocks. They've both got different numbers btw :) — claire @ May 31, 2016, 1:10 p.m.
    • All sorted now, thank you. Great instructions :) — claire @ May 31, 2016, 3:48 p.m.

    Hi Claire, you would connect orange wire from the other servo to either one of the other expansion pins (CS, SCL, SDI/A) or to one of the legs 0-3. You then just need to connect the black/brown and red to GND and PWR/VCC respectively, set that pin/leg to digital output and add another set servo block with that number to your code. Hope that helps :) Thomas Macpherson-Pope @ May 31, 2016, 12:12 p.m.

    Answer this question:

  • I have connected my servo and it have got it to work when the codebug is connected to my computer. When I unplug the codebug from the computer and try to run the program with a battery in the codebug it will not work. Have you found a servo that will work when the code bug is powered by battery rather than by the computer? Thanks. Sue Sue Price @ June 9, 2016, 3:21 a.m.

    Hi Sue, we have not seen any 3 volt servos, but if we come across any we will let you know. Thanks, Tom Thomas Macpherson-Pope @ June 13, 2016, 9:22 a.m.

    Answer this question:

  • Ask a new question:

Writing your program

We need to set up one of CodeBug’s legs as a servo controller and move it back and forth. Follow the tutorial below to write your code.

1 Question
  • The Blockly menu for this tutorial does not seem to have a Servo section. Is this a mistake? I went back to the 'create' section and found what I needed to get the servo going, which it did perfectly. Crispin @ May 24, 2016, 3:27 p.m.

    Yes sorry, thank you for reporting this bug, the Servo section is now on the tutorial :) Thomas Macpherson-Pope @ May 25, 2016, 8:23 a.m.

    Answer this question:

  • Ask a new question:

Testing your servo

Plug the single beam connector onto your servo, this is what we will stick the arm to. Download your project onto your CodeBug and give it a spin! Your servo’s shaft should spin one way and then the opposite way again and again.

  • Ask a new question:

Creating your arm

Once you are sure your servo is waving properly, stick the servo to the back of your CodeBug, with the shaft facing forwards.

Print these arm templates on thick paper or thin card and carefully cut out your favourite arm (making sure it is the left arm). Attach the arm to the plastic arm connector on your servo with some sticky tape. Plug in your CodeBug and wave hello, for the first time ever CodeBug will wave back!

  • Ask a new question:

What next

Take a video of your waving CodeBug and share it with us on Twitter.

You could add three more servos to give CodeBug another waving arm and two waggling legs from the print out. When using more than two servos, you will need to connect them up to a separate power supply.

Have a go as designing your own arms and legs for CodeBug and Tweet us the pictures.

Back to top