Build a Line Follower Arduino Robot
Over all the things you can do with a mobile robot, line following is one of the most common task. In this article, we will see how to do exactly that with an Arduino based mobile robot. We will see how to choose the chassis for your mobile robot, how to program it, and finally how to test the line follower robot. Let's dive in!
What You'll Need
| Component | Qty | |
|---|---|---|
| DFRobot MiniQ 2 wheels v2.0 robot chassis | 1 | |
| AA 1.2V rechargeable batteries | 4 |
Step by Step
Hardware & Software Requirements
<p>There are many Arduino-compatible robot chassis out there that we could use for a line following project, but for this project I decided to simplify things and use the latest version of the DFRobot MiniQ 2 wheels robot chassis. This chassis already comes with an onboard Arduino system, so out of the box you can make the robot move around without any other components required.</p><p>This chassis also has many sensors on board, especially 5 infrared sensors on the bottom of the robot, which is perfect for our project as we won't have any other components to add. We will use these sensors to know if we are following the line correctly, and adjust the speed of the motors if needed.</p><p>The only other thing that you will need is a set of 4 AA batteries to power the robot. I chose a set of 4 AA rechargeable batteries for this project.</p>
Hardware Configuration
<p>The hardware configuration for this project is very simple, thanks to the sensors that are already installed on the robot chassis. All you need to do is to install the AA batteries on the robot. You will end up with a similar result:</p>
Motor Pin Configuration
<p>We are now going to build the sketch for this project. It starts by declaring on which pins the motors are connected:</p>
Sensor Reading Function
<p>Let's first see the details of the read_value() function. It basically reads data from all the infrared sensors, and store these measurements into the data array. We can now see the details of the line_follow() function. It basically tests the different measurements of the sensors, and adjust the speed of the motors if needed.</p>
Testing the Line Follower Robot
<p>It's now time to test our line follower robot. First, make sure it is in safe place, like sitting on top of a little box so the wheels don't touch the ground. Otherwise you can have some issues as the robot will start moving forward immediately.</p><p>Also prepare some line on the ground that the robot will have to follow. Note that depending on the surface you are using, you might need to adjust the values inside the code a bit. For example, I use a black tape put on a wooden surface, so I had to adjust the detection thresholds in the code to work with a non-white surface.</p><p>You can now upload the code to the robot via the Arduino IDE. Then, remove the USB cable, and put the robot on the line. You should see that the robot is following the line and adjusting its course if needed.</p>
Wrapping Up
There are many things you can do now to improve this project. You can for example refine the code to have a more complex behavior with the readings coming from the sensors. We used a very basic behavior here, but you could for example use a PID controlled to adjust more precisely the speed of the robot. Have you ever built a line follower robot based on Arduino? Thinking about building one? Please share in the comments!