We often get asked questions about how to use the line follower with the Crumble, so we thought that we’d provide some updated examples on how to use it.
For those of you that aren’t familiar with it, the ‘Crumble Line Follower Widget‘ is a small board with two infra-red sensors in. Their resistance changes depending on the colour/ amount of light they sense. This means we can use the analogue values on the Crumble, along with some motors, to make a buggy follow a line!
There are many different ways to program a line-following buggy, and we are going to have a look at these. It is worth noting before we go any further, that there are many factors that can influence how successful your line-following adventure will be. Everything from how white your surface is, how reflective it is (for infra-red), how close the line follower is to the surface, to how charged your batteries are.
First of all, we need to wire up our Crumble and line follower. If you look at the back of your buggy, the right motor needs to connect to the motor two pads (red + and black -). The left motor connects to the motor 1 pads, but because the motor is flipped, we need to reverse the wiring so that the ‘forwards’ block still makes the motor move forwards. So we will connect the black to + and the red to – . The line follower then needs connecting. The power (+ and -) connects to the corresponding pads on the Crumble or battery box and then the ‘left’ and ‘right’ pads need connecting to two of the I/O pads e.g. A and B.
Note: This may be different depending on your motor configuration/set up. If you are in doubt, have a play and find out!
Method One: The Simple One
We will first look at the shortest and simplest way of getting the line follower to work. This method links the analogue values with the corresponding motor speeds.
There are occasions when this technique doesn’t work so well – it will depend on the materials you are using and how tight the ‘track’ you are following is!
Method Two: Treating Them Digitally
The next method treats the inputs digitally – so that the readings are either HI or LO. If the left or right are reading low, we only want the opposite motor running. Or when a side is on white, we want that motor to keep running.
Method Three: Analogue Alternative
When the digital method doesn’t work correctly, whether it is the surfaces you are using, or the height of the line follower from the floor, we can use analogue values instead, to achieve exactly the same effect.
Method Four: Comparing Left & Right
The other methods we are going to look at rely on comparing the left and right values to one another. This one works as follows: If the left analogue value is less than the right one, gradually turn left- else gradually turn right. The motor speeds can be adjusted depending on the complexity of your course.
Method Five: Joseph’s Brainchild
The other comparison method we are going to look at is the brain-child of Joseph, the Crumble’s creator. It involves finding the difference between the left and right values, and then adding/subtracting from the relevant motors.
These five different programs are just a snapshot of the vast number of ways you can program a line follower. If you wanted to use a white line on a dark surface then it is just a case of inverting the motors, or the comparisons.