How to build an Arduino Line Following Robot using Cardboard

Arduino Line Following Robot

Arduino Line Following Robot

Arduino Line Following Robot is one of the easiest and most well-known projects that anyone can make to learn the basics of programming, electronics, and mechanics all in one project. It’s known that this project is common for most of the makers and tech students and today I am going to give it a revisit but with a completely new innovative methodology, using phone’s camera instead of the IR sensors!


Thanks to 1Sheeld, there is a shield called Color Detector Shield that uses the phone’s camera to capture continuous frames and let you call a certain function that returns the current color camera is seeing.


The 3rd project of the robotic series

I have started this robotics series with a simple Arduino Bluetooth RC Car from cardboard which allows you to control it with the 1Sheeld App within 3 different ways; Gamepad, Accelerometer, and Voice-recognition. Then, I made the second tutorial which is adding obstacle avoiding functionality to the car to make it an Arduino Obstacle Avoiding Robot. In this tutorial, I will make the 3rd project of this series which is an Arduino Line Following Robot that uses the phone’s camera for color detection.

“4th one is coming .. stay tuned for it …”


How it works

The color detector shield opens a preview to show you what color it’s seeing at this moment. It has some modes and color configurations that you can control through code, like:

Note: This code is for idea demonstration only, don’t copy-paste it as the full Arduino code is below

Which adjusts the color detection shield to divide the screen to 9 boxes .. like 3 x 3 rows & columns and each box detects a different color. Just like as you have 9 IR sensors!


So, I will use only box number 1 (the topmost left) & box number 3 (the topmost right) to act like 2 right & left line color sensors and will do the following code logic:

  • If both boxes detected white, then move the robot forward


  • In case box number 1 detected white but box number 3 didn’t, then turn the robot left


  • If box number 3 detected white but box number 1 didn’t, then turn the robot right


Moreover, you can return back to the manual control mode “manual” or obstacle avoiding mode “Auto” anytime. Thanks to the amazing GLCD Shield which enables you to create radio buttons on your phone’s screen via coding their names, places on the screen and triggering the selection of each so that your car know when to go manually, autonomously, line follower.


Build it

If you are just getting your 1Sheeld out of the box then go ahead with this 1Sheeld getting started tutorial or simply check the 1Sheeld User’s Manual.

You won’t need any materials, components or even tools to build this project as long as you are following this robotics tutorial series from the beginning. All you have to do is to upload the new code and you are ready to go!

But if you aren’t following this series, then you should:

Then go ahead for the code.


Here’s the full code you are going to upload to the Arduino Mega inside your robot :


Code uploading

  • Connect the Arduino Mega via your PC.
  • Then, switch the 1Sheeld power to operate on 5v (Not the 3.3v):
  • 1Sheeld has 2 modes: Uploading mode and Operating mode. You can switch between them using the switch close to the Digital pins and is called “SERIAL SWITCH”.

As you will use Serial pins RX3 & TX3, you don’t have to move the switch to the Uploading mode at any time! Yeah, just keep it on the Operating mode always during the code upload and while you are playing with the car.

Finally, upload the code …

Run the Arduino Line Following Robot.

1- First of all, you must prepare a track. I just brought a black cloth and white tape and did my own Arduino infinity-shape track:

2- Cover the robot and turn it on, then pen the 1Sheeld App, select these shields:

  • Gamepad
  • Accelerometer
  • Voice Recognizer
  • Slider
  • GLCD
  • Face Detection
  • Buzzer
  • Color Detector
  • push button

3- You need to reset the Arduino so that the GLCD modes appear and this is done by pressing a bit long on the push button.

4- Then select the LineFollower mode from the GLCD Shield screen.

5- And let your robot breath the freedom on the track 😃


Note: if the Color Detector Shield didn’t open the camera preview then try to download the App from the download page here and install it and the issue will be solved.


More …

So far, we have made 3 projects; Arduino Bluetooth RC CarArduino Obstacle Avoiding Robot and this Arduino Line Following Robot project .. we are almost done for this series except for the last project which will be the most exciting feature you can ever add to your robot 😃

So, again, please play with your robot carefully as you are going to need it for the next project 😉

Finally, if have any questions please let me know in the comments below .. and stay tuned for the upcoming tutorials ^_^

Related Blogs

Arduino Robotics

Arduino Robotics Series, from a car to a robot arm

Arduino keeps standing out from the crowd of all-around development boards due too its ease of use and budget price. As a result, this has enabled almost anyone to get his own idea into life no matter how crazy or even useless to the whole world it was, except for its maker! Also, it has …

Arduino Robot Arm

How to build an Arduino Robot Arm placed on RC Car

Arduino robots are always funny and definitely more enjoyable when combined with robotic arm! And today, I will walk you through the making of a simple Arduino Robot Arm that’s made of cardboard and how you can attach it over your Arduino Bluetooth RC Car / Robot that you have made so far through this series. …

Arduino Obstacle Avoiding Robot

How to build an Arduino Obstacle Avoiding Robot using Cardboard

Back again with another Arduino Bluetooth RC Car tutorial but with an advanced feature that makes your car autonomous by adding ultrasonic sensors to the RC Car you have made before!. Yeah, I know that you may have seen other tutorials using ultrasonic to make the car/robot avoid obstacles ahead, but I am going to …

Arduino Bluetooth RC car

How to make an Arduino Bluetooth RC Car using Cardboard

  Cardboard crafts are one of the most popular and easy to make DIY stuff. Mixing this with the unmatchable enjoyment of RC Cars and the ease of using Arduino, I am going to show you how to make a Cardboard Arduino Bluetooth RC car that you can control via Bluetooth from your smartphone.  …

Arduino Security Camera

Arduino Security Camera System (Arduino Home Hacks #4)

Arduino Security Camera Have you ever wanted to check your home in real time? Afraid that maybe someone has stormed in, don’t remember if you shut the door or not or maybe wanna check if your Hyper-energetic dog has broken any of your dishes AGAIN!! 🙂 Then this is the perfect place for you cause today …

Arduino IoT

Arduino IoT Shield Functions Explainer

Arduino makers …. you can connect your Arduino to MQTT brokers(servers) and launch your IoT with Arduino IoT Shield! It’s the 1Sheeld IoT shield that will do the job for you. It’s one of the most important but recent Arduino shields in 1Sheeld. Simply, it turns your Arduino into MQTT client where you can publish and …