Our friends at DFROBOT made a small, MicroBit compatible robot. But don’t underestimate it by its size! This small robot has a bunch of options for controlling the distance sensor to avoid obstacles to being able to follow a line. We built our own extension for it and this post is a guide on how to use it in Microsoft MakeCode.

How to use

Add the extension

If you have not installed an extension before, check out this post about how to install extensions.

Otherwise, enter the following link when prompted. https://github.com/brainpad-board/DFROBOT-Maqueen


Let’s start with the basics by controlling the motors. In the following example, we set the robot to go forward for 2 seconds, backward for 2 seconds and then stop. Check out the code below.

Headlights and Underglow

Another simple task is controlling the headlights (the two orange bulbs on the front) and the underglow (the 4 white squares in each corner). The underglow, in this case, is being controlled by the Neopixel extension. The following program flashes each headlight and gives a breathing light effect to the underglow. Check out the code below.

Distance Sensor

Something a little more advanced would be interacting with the distance sensor on the front of the robot.

In this example, we want the robot to avoid all obstacles within 30 centimeters in front of it by going backward and to the right when an object is within that range. If you look carefully, this is the same thing the robot is doing in the image at the top! Check out the code below and try changing it to avoid things at a farther distance or to turn a different way.

Line Sensor

Line sensing is probably the trickiest of them all since the robot is always correct itself to stay on the line.

As you can see, the line sensors are pretty small but are pretty accurate in detecting a line. The robot also gives you two handy blue LEDs that will turn off when there is no line and will turn on when it detects a line!

The following code is pretty long but it will start to make sense after seeing it in action. To sum it up, as long as both sensors don’t see a line, it will go forward, but if one side sees a line, the opposite motor will stop causing the robot to turn and to get back on track. Check out the code below to see the full example!