A line-following robot, as its name suggest, is a robot that move by following a line. It is a simple robot that could explain the concept of Autonomous Guided Vehicle (AGV) to newbie robot makers. Cytron offer two types of line sensor to aid makers in the process of building this robot:
In this tutorial, I am going to use the advanced thing with Arduino Uno board to show you how to build a simple yet an amazing robot.
There are couples of thing we need to prepare before we can start the project.
Arduino IDE – an open source Integrated Development Environment used to program Arduino board. You can download it here.
Alright, so we have all those stuff, and now we could actually get our hand dirty.
The working principle of line-following robot is pretty simple, detect the line, and follow the line. Consider situation below:
You can see that the robot is misaligned to the right of black line, thus sensor 2 detected the line and we have to move our robot to the left so that the black line is positioned at the middle of sensor array, which is in between sensor 3 and sensor 4.
In short, the overall processes of line-following are: detect position of the line, adjust motor speed to align the line at the center, and repeat~
So, the first thing to start with is to get a robot base. Unfortunately, I can’t find any unused robot base, so I have to build one (((sweat. Whatever, just make sure that your base (length x width) must be longer than 20cm x 20cm.
Then, mount all the parts on it so that it looks like a robot. I am not going to talk about this in detail as everyone will have their own design, and this is mine. Basically, just put everything (brackets, motors, wheels, castor, Arduino board, motor driver board, and also the sensor board) on top of it – and don’t forget to leave some space for your battery.
The next step is to solder wires to your motors and connect it to motor driver’s output. Also connect your sensor board to the main circuit using rainbow cable. In my case, I am using a box header and pin header to make my board a little bit more organized, this is really optional as you can connect rainbow cable to Arduino board using male-to-male jumper wire straight away. Be sure to connect to Port B of line sensor as we are going to use digital mode.
Now, connecting Arduino board to MDD10A, notice that I did not connect 5V pin on MDD10A because there is no such pin on my real board, you have to connect it to 5V pin on your Arduino board if such pin exist.
A switch is highly recommended to avoid your robot running away once you connect the battery =P.
In the end, your connection should looks like the one at left.
(Click the image for larger view)
Referring to user manual from Cytron product page, connect LSA08 to Arduino board as below:
LSA08 – Arduino
Vin – Vin
GND – GND
O0 – pin 0
O1 – pin 1
O2 – pin2
and so on, until…
O7 – pin 7
*NOTE: please make sure that you connect to the PORTB on LSA08
(Click the image for larger view)
You can download the source code at the attachment section below.
However, in order for the source code to work properly, we MUST calibrate the LSA08 sensor first.
Here I am going to explain about two (should be three) settings that is available for LSA08 which we will be using in this tutorial.
The first mode is the line mode (LINEMODE) which makes the sensor to give HIGH output when it detects white or black lines. In our case, we will be using Dark-On mode, where the sensor will output HIGH when it detects black line.
Power up your LSA08. Then press MODE button on LSA08, it will bring you to the setting menu, pressing MODE twice to choose the LINEMODE option, and press SEL button to access the option. In the window, you could choose either White-On or Dark-On, using the SEL button to select Dark-On, and press MODE to confirm and exit to main setting menu.
At the menu, keep pressing MODE to loop through the menu until you find CALB (calibration), pressing SEL will put your LSA08 into calibration mode, and you have to start moving sensors across the black line like there is no tomorrow =P.
In case you accidentally pressed MODE, you can loop through the menu to find an EXIT option, and press SEL to exit the menu, or press and hold MODE in setting menu will also bring you back to line display screen.
These three options should be enough for LSA08 to operate in digital mode, if you are interested on the other setting menu options, you can always refer to the user manual.
The last thing is to upload the sketch to Arduino board, and run the program. If your robot moving in a wrong way, try changing the polarities of your motor, or changing the state values where I mentioned in the source code.
Finally, if you have any question, feel free to ask in our technical forum as we seldom check the tutorial’s comment section.