ChickBot Arduino dance & sing

So, let’s put it all together so we can get our ChickBot moving & grooving at your command.

This is the starter program that your ChickBot came programmed as and it adds in some little extras to make it super simple for you to say how far it should move or turn. And we give you all the notes we know about so you can get any tune you like playing!

As the program is a bit longer than the others and has more detailed parts to it, it’s best to download it from here and we can concentrate on how you can make changes.

It will only take a second or so to download. On Windows you will need to right-click the file and Extract All to unzip it. Mac does this automagically.

Open up the program in the Arduino software (either from the Open command on the File menu, or double click the ChickBot_starter_v1.1.ino file). Now take a look at the loop section and you’ll see how we’ve made it almost like English to command your ChickBot. The commands you can use are picked out below in orange.

We start out with a SoundAndLEDAlert command that plays a tone and flashes the on-board LED.

We’ve got a WaitForButtonPress command that, well, as you’d expect, waits for the button to be pressed.

As we have set some calculations and definitions in the top section, we can tell ChickBot how far to move in the units of your choice, mm, cm or inches.

This gives us a super useful command of GoForward() – inside the brackets we tell the command how many steps to go, and by using cm or mm or inches, we can say how far to go. Here’s some examples:

  • GoForward( 10 * cm ) = move forward 10 cm
  • GoForward( 5 * mm ) = move forward 5 mm
  • GoForward( 3 * inches ) = move forward 3 inches

I bet you can guess what the backwards command is??? Yup, it’s GoBackwards() with exactly the same options.

Want your ChickBot to stop? That’s what the AllStop() command does. I don’t want to use the word Stop as ‘stop’ is a part of the programming language and if someone forgets the upper case S, the program won’t work as expected.

We have two ways of turning:

The simplest one is the HardTurn() with whether you want it to go Left or Right and how many steps. A hard turn is a turn that’s on the spot – one wheel goes forward and one wheel goes backwards, so ChickBot pivots around its front axle.

The second moves in an arc and is called SoftTurn(), again, you say if you want it to turn Right or Left and how many steps. A soft turn keeps one wheel stopped and the other wheel drives forward. This means it is a bigger turn than a hard turn, something to remember when planning your movements.

The program calculates the number of steps that are needed for various turn sizes, so you have some pre-prepared values of hardTurn360, hardTurn90, softTurn360 and softTurn90. The number in the name refers to the number of degrees of turn. As they are numbers, you can use maths to get different values – so if you want to turn around, a 180° turn, you could use hardTurn360 / 2  or  hardTurn90 + hardTurn90. Using softTurn values with the hardTurn() command and vice versa won’t do any harm but won’t make any sense as the calculations can’t be mixed together.

Last but not least, we have an improved tune command so that you can setup as many tunes as you like and play which ever one you want. The tune (or music) definition is the same but with the option of calling it something more memorable:

int PuppyPower[] = { NOTE_F3, 8, NOTE_G3, 8, NOTE_A3, 8, NOTE_C4, 4, NOTE_A3, 8, NOTE_C4, 4, 0, 0 };

You then run the command PlayTune() with your tune name inside the brackets, like this PlayTune(PuppyPower);

Don’t forget you’ve also got the built in delay() command if you want your ChickBot to pause. It needs a number, 1000 = 1 second, 500 = half a second, 10000 = ten seconds.

There is no harm in trying stuff out. Using these commands can’t do any damage to your ChickBot unless you drive it off the edge of a table and it falls on the floor. So this isn’t much of a warning really, I just wanted to get your attention.

So, make changes, one at a time, to the loop section and see how you can get your ChickBot moving and singing to your command.

Quick Reference chart

Click here to download a PDF of this.

ChickBot commands

Action Command to use
Beep & flash the LED SoundAndLEDAlert();
Wait for the button to be pressed WaitForButtonPress();
Delay in milliSeconds delay( 1000 );
Stop all motors AllStop();
Go forward – example, 10 cm. Note the * GoForward( 10 * cm );
Go backward GoBackward( 10 * cm );
Turn on the spot – example shows 90º to the left HardTurn( hardTurn90, Left );
Turn around a wheel – example shows 90º to the right SoftTurn( softTurn90, Right );
The soft & hard turn angles can not be mixed up, only use hardTurn90 with a HardTurn. As they are just numbers, you can use maths to calculate other angles – e.g. softTurn90 / 2 would be 45º
Play a tune with a name PlayTune( DumDeDe );
Define a tune – note, duration (in beats) int PuppyPower[] = { NOTE_F3, 8, NOTE_G3, 8, NOTE_A3, 8, NOTE_C4, 4, NOTE_A3, 8, NOTE_C4, 4, 0, 0 };

Control structures:

Control type Template code Sample conditions
The IF statement if ( condition ) {

// do this

} else if ( another condition ) {

// do this

} else {

// otherwise do this


  • Variable == 10
  • Variable1 == Variable2
  • Variable > 10
The FOR loop for (

int counter = 1; // Setup a counter

counter <= 3; // Keep going whilst counter is less than or equal to the number of times required

counter = counter + 1 // Each time we do this loop, add one to the counter

) {

// do stuff

} // for – this is the bottom of the for loop

The FOR loop in short for (int c = 0; c < 3; c++) {

// do stuff


The WHILE loop while( condition ) {

// do stuff

} // while