Lesson 9 – Line Following Robot

Tutorial –

Objective – As part of this tutorial we will learn howto get the Micro:Maqueen robot to track a line.

Setting things up – Let’s head over to the BBC MakeCode website (https://makecode.microbit.org) since we will be using the MakeCode block editor to code the Micro:Maqueen.

Before we can write any code and get our robot to do stuff for us we need to include some specific libraries (Code) that will allow the BBC Micro:Bit board to understand the different components, capabilities of the robot. We call this special code libraries.

Here’s the steps to import the library –

  1. Head over to the MakeCode website at : makecode.microbit.org using a new browser window. The first time it loads things might be a bit slow.
  2. Let’s create a new project to get started.
  3. Now go ahead and let’s import the library.
  4. Click the gear icon shown on the right hand side of your screen, click on “Extensions” and then enter the library address: https://github.com/jhlucky/maqueen
  5. Import the library by clicking on it.

Let’s Get Coding –  As part of this tutorial we will write code to control our robot and get it to follow a line.

Getting your robot to move from one point to another can be challenging. With the Micro:Maqueen we would need to make use of the line sensors (on the lower portion of the board) to get it to sense a line (black/white) and follow the track. Line following is one of the most common challenges to get started with when learning how to control a robot. Smarter robots (and obviously very expensive ones) come with other complex sensors that allow machine learning, vision processing, GPS mapping, etc. which allow for other forms of spacial recognition. In our case we will stick to using the line sensor capability on the robot to track the line and follow it.

Enter the code provided below into your MakeCode Editor where you have loaded the Micro:Maqueen libraries.

Upload the code to the micro:bit and you should be able to get your robot moving around the line.

Have a look at the sample program at – https://makecode.microbit.org/_1VzX7LLAC3im

Challenge – Can you stretch yourself with the following challenges –

  1. Write code, program a key on the IR controller to send signals that tell the robot to stop the car dead in its tracks
  2. Write code, program a key to send signals and get the robot to flash all it’s lights i.e. LED’s and neopixels
  3. Write code to sense obstacles and stop when it senses something in front of it
  4. Write code to go around slowly in circles when it looses track of the line until it comes back onto the track

The challenges listed above will help you bring together all the learning you have gained working on the tutorials this far.

Prerequisites –

  1. This development track makes extensive use of the BBC micro:bit.
  2. If you haven’t purchased a BBC micro:bit yet you might want to head over to OzToyLib and pick one up now.
  3. We would recommend that you pick up the BBC micro:bit kit which comes with a battery pack, usb cable and the real micro:bit.
  4. We will be using the official online BBC MakeCode Block editor to write code for all our tutorials. No investment required here.
  5. You will also need a Micro:Maqueen STEM robot to be able to work on this development track. You can pick up the Micro:Maqueen robot from OzToyLib.

Reference –

  1. To learn more about the BBC micro:bit please visit – <Link>
  2. To learn more about global re-sellers of the BBC micro:bit please please visit – <Link>