Introduction: OpenCV Based Line Following Robot

About: An Electronics engineer and a hobbyist. I love to keep experimenting with microcontrollers.

Hello!!, It's really been a long time since I uploaded any project here. So, I spent this weekend to come up with a project idea that I could make while stuck at home in this lockdown.

Now I had previously made a line follower using IR sensors and the latest one I made was using only one IR sensor. So I had to take that project to a new height.

This led me to the idea of making a line follower using Image Processing. The main core of this project will be a raspberry pi zero and the sensor will be a USB Webcam connected to the Rpi.

Watch the video above to understand more about the project.


Step 1: Things We Need

List -

1. Raspberry Pi Zero (Any other model will be fine too)

2. USB Webcam / Raspberry Pi Camera

3. Robot Chassis with Motors and Wheels

4. L298N Motor Driver Module

5. 12 Volt Battery for powering the robot

6. A power bank to power the Raspberry Pi (You can also go with a buck converter)

Additional Supplies -

Header wires, Black tape and Some sort of mount for the camera, USB OTG cable

Step 2: Schematic Diagram

Now make all the connections as shown in the image above.

You can power the motor driver and the raspberry pi using the same battery by making use of a step down converter.

IMPORTANT : Do not supply more than 5V to the raspberry pi or it will sure be a burnt pi.

Step 3: Python Program

Now download the code from below.

To run this code on your raspberry pi, you will first need to setup VNC Viewer on your desktop to remotely access the rpi. Or you can use a separate monitor for this. Then open the downloaded code on the raspberry pi.

Make sure that you have installed the OpenCV, Numpy and Rpi libraries before running the code.

Recheck all the connections and then place the robot on a black line.

I made the path using black electrical tape.

Now connect the batteries and watch your robot follow the line.

Note : If you find the speed of your robot is way too slow then change the values to 100 in the p1.start(50) and p2.start(50) instructions.

That's it for this project. I intentionally kept this instructable short as I have already covered most of the stuff in the video. So do check it out. If you have any doubts do drop a comment. I will do my best to help you out.

Thank you.