Micro:bit Line Following Robot
In this instructable, we are going to build a line following robot using a Micro:bit and some other elements.
A line following uses infrared sensors that determine if a surface is white or black, by using multiple of these sensors arranged in a line, we can determine which of them are sensing a black surface (the line) and which of them are measuring a white surface, thus determinating the position of the line drawn on the floor, and based on that the robot decides which direction to go to follow the line.
Supplies
- 1x BBC Micro:bit V2.0 Board
- 1x Micro:bit breadboard adapter
- 1x Pololu QTR-8A Reflectance Sensor Array
- 1x 7.4V Battery
- 1x LM317 Adjustable Voltage Regulator
- 1x 240 Resistor
- 1x 390 Resistor
- 1x L293D Motor Driver
- 2x DC Gearbox motor with wheel
- These motors are rated for 3 to 6V and we are going to use a 7.4V battery to drive them. We can prevent damaging the motors by limiting the duty cycle of the PWM signal sent to the driver.
- 2x Mini breadboard (10 x 17 holes)
- Can use just 1 breadboard instead
- 2x 5mm Short LED
- We will use the LEDs as the front wheels of the car, and regular 5mm LEDs might be too long for the sensors to work correctly
- Electrical tape
- Wires
- 10x 6'' F/FJumper cables
- Hot glue
- Tape
- Double-sided tape
- Cardboard (at least 12 x 18 cm, around 2mm thickness)
Tools
- Hot glue
- Soldering iron and solder
- Needed to solder the headers of the QTR-8A Sensor array
- Cutter
- Needle
- Pliers
- Scissors
Electronics
We will start by connecting the electronic components using the 2 Mini breadboards, wires, just follow the schematics or use the tables below for the connections of each component
Start with the Voltage regulator circuit, connect the 240 Ohm resistor between the Output and Adjust pins of the LM317T, and connect the 390 Ohm resistor between the Output pin of the LM317T and ground. On the input pin connect the 7.4V of the battery.
The names of the pins of the LM317T voltage regulator are shown in page 2 of the datasheet
These connections were done using F/F Jumper cables, the sensor array generally comes without soldered headers, if that's so then solder them and then connect F/F jumper cables to them +---------------------+-------------------+ | QTR-8A Sensor array | Connect to | +---------------------+-------------------+ | VCC | 3.3 V (Regulator) | +---------------------+-------------------+ | GND | GND | +---------------------+-------------------+ | 2 | Micro:bit pin 10 | +---------------------+-------------------+ | 3 | Micro:bit pin 4 | +---------------------+-------------------+ | 4 | Micro:bit pin 3 | +---------------------+-------------------+ | 5 | Micro:bit pin 2 | +---------------------+-------------------+ | 6 | Micro:bit pin 1 | +---------------------+-------------------+ | 7 | Micro:bit pin 0 | +---------------------+-------------------+
+--------------------+-------------------+ | L293D | Connect to | +--------------------+-------------------+ | Pin 1 (1,2EN) | 3.3 V (Regulator) | | Pin 16 (VCC1) | | | Pin 9 (3,4EN) | | +--------------------+-------------------+ | Pin 8 (VCC2) | 7.4 V (Battery) | +--------------------+-------------------+ | Pins 4,5,12,13 | GND | +--------------------+-------------------+ | Pin 2 (1A) | Micro:bit pin 7 | +--------------------+-------------------+ | Pin 7 (2A) | Micro:bit pin 8 | +--------------------+-------------------+ | Pin 10 (3A) | Micro:bit pin 13 | +--------------------+-------------------+ | Pin 15 (4A) | Micro:bit pin 12 | +--------------------+-------------------+ | Pins 3,6 (1Y, 2Y) | Right Motor | +--------------------+-------------------+ | Pins 11,14 (3Y,4Y) | Left Motor | +--------------------+-------------------+
Making the Basic Structure
We are going to cut a piece of cardboard to hold our electronic components, for that draw 3 vertically centered rectangles with the dimensions shown in the picture, and then cut the whole shape.
After that, draw the rectangle that has the cross hatch pattern on the second image, and cut it out.
When that's done, we are going to make some holes to hold the LEDs which will act as some sort of front wheels of the robot, for that, use an LED with straight leads as a guide, and mark 2 points at each short side of the hole you just made (as shown in the pictures)
Now to make the holes, first put the shape on top of another piece of cardboard to not damage the surface underneath, then, with the help of the pliers and the needle, push through the marked points, then lift the cardboard shape and put the needle through each hole.
Mounting the Breadboard and Battery to the Structure
Before the continuing, connect the hot glue gun so that it's heated up when we need to use it later.
We are going to start putting the components on top of the cardboard shape.
The first thing we are going to put on the structure is the breadboards, we can use the peel and stick adhesive beneath them, or put some double-sided tape. If you don't have double sided tape just roll some short pieces of normal tape and put them beneath the breadboards. Stick the breadboards to the structure in the position shown by the first image, it doesn't have to be precise, but what we want is for them to be centered and the bottom breadboard (the blue one) to be touching the edge of the structure.
Done that, we are going to mount the battery using the same procedure, the battery goes just on the front of the breadboard on the top (the green one). Note: Don't press the battery too hard to avoid damaging it
Mounting the Sensors and Motors to the Structure
Now we are going to mount the QTR sensor array. For that cut a strip of tape, around 7CM in length, and then with the sticky side up, put it through the hole in one of the sides, then wrap it like in the picture, so that the sticky side sticks to itself a little bit (around 5mm), do this for the other side too.
Now put the sensor array on top of the hole so that the sensors go through the hole, then secure it with the strips of tape.
For the motors. we are going to use hot glue, just add hot glue to the bottom of the motors and then put them on the corner of the structure.
Mounting the Wheels
Now we add the front wheels, for that we are going to use the two short LEDs, stick them through the bottom of the structure on the holes previously made (if the leads don't seem to go through, put the needle again through the bottom and then try again). The LEDs should be touching the cardboard, afte that, on the top side, bend the leads to secure them.
For the back wheels, just put the wheel of each motor in the axle, try holding the motor while doing so instead of the whole structure to prevent ripping the motor off the structure.
Uploading the Code
The mechanical part is done, now that's left is uploading the code. for that we are using Microsoft's MakeCode for Micro:bit
The code can be found here, just connect the micro:bit through usb and upload the code
Test!
I happen to have a track to test the robot, but you can make your own with a large piece of bond paper and electrical tape.
To start the robot press the A button, and to stop it press the B button