This activity is designed as part of a workshop offered by our outreach team. We recommend you finish the Remote Control Challenge first.
For this challenge you will be working in pairs with a BBC Micro:Bit. As there are a limited number of the Maqueen robots, please try to be considerate during testing.
Open a New Project on Makecode called 'line following'.
You will then need to go to 'Extensions' in the block menu, then search for 'maqueen' and click on the "DFRobot_MaqueenPlus_v20" option.
Now, you have all the blocks necessary for this activity.
Can you program a Maqueen robot to successfully follow a line?
This activity will take you through each step of making your own program.
The robot you'll be using has 5 line-following sensors underneath - as shown in the below image.
We'll only be using the sensors labelled 'R1', 'M', and 'L1' for this challenge as we want the robot to try and stay central on the line.
These sensors are digital - this means they have two options: 0 (does not see black) and 1 (sees black).
For this activity you will need:
Here is an example of a possible starting point for your if statement.
This looks quite complicated, so let's break it down:
Remember: Higher speeds = lower accuracy.
You will then need to add an else if statement for when the robot starts leaving the line towards the right. This will then correct by moving left.
More else if statements may be needed for any other sensor reading possibilities - depending on the width of the line.
The else statement created will need to use motor stop blocks for both the left and right motors.
We've added red boxes inside each empty statement with the directions you need to program the motors for.
Remember: The program works down the blocks in order. With a multiple else-if statement, it will stop the first time the conditions are met.
SAFETY: Please keep long hair tied back to reduce the risk of it getting trapped in any wheels.
There are several different black lines provided to test your program on.
The best program is the one that works on all of them, without having to change the program.
Please start with the level one line and do not move up a level until your robot has completed it.
To test your program, you will need to plug your Micro:Bit into the computer and download the program onto it.
Place the Maqueen robot on your chosen track, insert the Micro:Bit, turn it on and watch. Be ready to carefully pick it up if it risks going too far / crashing - if the wheels are still turning, switch off the robot.
SAFETY: Do not touch or stop the wheels from turning as this may cause injury and will damage the motors.
Congratulations on completing the challenge!
There are still a couple of things we could add to this program:
The only ultrasonic block available in the Maqueen Plus menu is a value block (rounded ends).
This means you will need to create a new variable (called 'distance') to store the reading in and then use it at the start of your line following if statement.
Here is an example of setting variable:
This needs to be at the very start of your forever loop to keep it updated.
You can then use it in an if statement:
The # will need to be replaced by how far away an object is in cm to start being detected.
You could also help other people in the class if they want you to.
We hope you've enjoyed this workshop!