05 – Programming the Bot120 Picaxe Microbot as a line follower

The Bot120 Microbot comes with a Line Traker module. The Line Tracker module is fitted in the centre of the Microbot between the two bumper sensors. The module has a red LED that illuminates the surface and right next to it is a phototransistor to detect the reflected LED light. The phototransistor is used as an analogue sensor on Pin C.2 which is also analogue channel 8 to determine the amount of light reflected back from the surface. The analogue reading give a measure of how dark or light the surface is. The sensor is read with the ‘readadc’ command on analogue channel 8. A low reading indicates a lot of reflected light, in other words a white surface. A high reading indicates very little reflected light, in other words a black or dark surface.

You will need a track with a line for the Microbot to follow and black insulation tape on a light surface works very well. You can even construct a portable track on MDF wood, you can use the wood for the background and you don’t need to paint it white.

A simple procedure to follow a line would be to measure the reflected light continuously to determine when the Microbot leaves the black line. When it leaves the black line it will move forward and turn towards the black line again. Once back on the black line it will then turn in the opposite direction and move forward until it is off the black line. So it will actually follow the edge of the black line and it will zig-zag across it. 


Calibrating the Line Follower sensor 
You need to calibrate your Line Follower sensor for your track. This is necessary to get the best discrimination between the background and the black line. How do I calibrate my Line Follower? The process is very simple get an analogue reading of the background of the track and a analogue reading of the black line. For the best discrimination between the black line and the background you need a reference value between the two readings. This reference value will be used to make decision on a reading to determine if the Microbot is on the background or on the black line. The reference value can be calculated using the following formula:

Reference Value = Background Reading + (Black Line Reading – Background Reading)/2

You may ask yourself how do I read and display the analogue value of the Line Follower sensor? Reading is easy but how do I display it? The answer is by using the ‘Debug’ command in your calibration program to display the variable assigned to the sensor reading with the ’readadc’ command. The following program can be used to calibrate the Line Follower sensor:

As soon as the program is downloaded to the Bot120 the debug window will open displaying a list of the variables. Move the Line Follower sensor over the background and take the b0 reading in the Debug window. Move the Line Follower sensor over the black line and take the b0 reading for the black line. Using these two readings the Reference Value or Mid Level value can be calculated for the best discrimination.

Line Follower Program
We have calibrated the Line Following sensor and now we can program the Bot120 as a line follower. A simple line follower can be programmed with the following code:

You can download the program file, Bot120 Line Follower by right clicking on it and selecting ‘save link as’ from the popup menu.