
[video_player id=āZBdMibMdā access_level=āeveryoneā]
New stuff you need
Line sensors
Advertisement
micro:bit edge connector (optional)
YOU have battled batteries, mastered motors and conquered coding. Now, far from the humble reading light you made in week 2, you should be able to build an autonomous line-following robot to bring the biscuits when your hands are full with mugs of tea.
Letās start with the wheels. Wire your servos to power and ground on the breadboard, and pins 0 and 1 of your micro:bit. Connect ground on the breadboard to ground on the micro:bit, then add the battery pack. You can use the same robot body as last week.
Next, the line sensors. Most have two domed parts that look like LEDs ā one emits infrared light, the other detects the reflection. Black reflects less infrared than white, so the sensors know which colour they can see, letting our robot follow a darker line on a lighter background.
Connect the sensorsā āvccā legs to the micro:bitās 3v pin and the āgndā legs to ground (you might need jumper wires with a āsocketā end). Link the sensorsā outputs to micro:bit pins 6 and 7, the slivers to the left of pin 1. Like last week, you will need conductive paint or a micro:bit edge connector to do this. Attach the sensors to your biscuit botās front so the emitters and receivers point down.
Now, we code. The sensors read 0 when they point at white, so if the biscuit botās left sensor reading is 0, it has veered off the line to the left, and if the right sensor reads 0, it has veered right. In each case, the biscuit bot should turn until it is back on the line.
In the code editor, enter the āLoopsā menu and grab a āwhile <true> doā block then snap it into āforeverā. Next, take a ā0 = 0ā comparison from āLogicā and a ādigital read pinā block from āPinsā. Make a line that says āwhile digital read pin p6 = 0ā³. This handles what the bot should do when it canāt see the line on its left. We want it to turn right. So nestle two āservo write pinā blocks inside your āwhileā, one to stop the right wheel and another to move the left wheel forward. Underneath, we need a second āwhile <true> doā block, this time for when the bot canāt see the line on its right. Put ādigital read pin p7 = 0ā³ in the second āwhileā, then add two more servo blocks inside it with the correct values to turn right.
Download the code and attach the micro:bitās battery. Finally, draw a thick black line on some white paper with tape or a pen and lay it along your route. If your bot misbehaves, adjust its sensitivity by turning the dials on the sensor boards with a screwdriver.
Congratulations ā you have completed our first maker series. I will be back next week with a fresh set of projects focusing on the outdoors. In the meantime, make a cup of tea and put your feet up ā the biscuits are on their way.
Thanks to Imperial College Advanced Hackspace for use of their facilities
To download a printable version of this page click here
Starting next week: How to be a maker 2
You have learned the basics ā now itās time to show your skills to the outside world.
From next week, a new 10-part series will focus on making gadgets and gizmos for the great outdoors, from a rain alarm to a tweeting wildlife camera. Stay tuned to make some more!
You will need
BBC micro:bit starter kit
Capacitive soil moisture sensor
Crocodile clips
Jumper wires
Everything you have already learned