[video_player id=鈥漐BdMibMd鈥 access_level=鈥漞veryone鈥漖
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鈥檚 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鈥 鈥渧cc鈥 legs to the micro:bit鈥檚 3v pin and the 鈥済nd鈥 legs to ground (you might need jumper wires with a 鈥渟ocket鈥 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鈥檚 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鈥檚 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 鈥淟oops鈥 menu and grab a 鈥渨hile <true> do鈥 block then snap it into 鈥渇orever鈥. Next, take a 鈥0 = 0鈥 comparison from 鈥淟ogic鈥 and a 鈥渄igital read pin鈥 block from 鈥淧ins鈥. Make a line that says 鈥渨hile digital read pin p6 = 0鈥. This handles what the bot should do when it can鈥檛 see the line on its left. We want it to turn right. So nestle two 鈥渟ervo write pin鈥 blocks inside your 鈥渨hile鈥, one to stop the right wheel and another to move the left wheel forward. Underneath, we need a second 鈥渨hile <true> do鈥 block, this time for when the bot can鈥檛 see the line on its right. Put 鈥渄igital read pin p7 = 0鈥 in the second 鈥渨hile鈥, then add two more servo blocks inside it with the correct values to turn right.
Download the code and attach the micro:bit鈥檚 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鈥檚 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