How to make a Line Tracking robot with Raspberry Pi Pico board

How to make a Line Tracking robot with Raspberry Pi Pico board

Hello and welcome back! In this project, we’ll learn how to make a Line Tracking Robot using the Raspberry Pi Pico board. For that, I used the 3-way IR infrared line tracking sensor module, but you can use any other IR infrared sensor module as well. The process remains the same. We’ll be programming the robot using the Python language, which is beginner-friendly and easy to learn. It’s a great project for those who are just starting out. If you need help setting up the Raspberry Pi Pico board with Thonney IDE, please use this tutorial. Also, I used the L298N motor driver module for controlling the gear motors. Let’s get started and have some fun building our Line Tracking Robot!

3-way Ir infrared sensor module

The 3-way IR infrared sensor module has three IR transmitter and receiver LEDs. This helps the module detect lines and gives us three digital input values to work with. Also, we can use three jumper wires to get the values to the Raspberry PI Pico board.

How to make a Line Tracking robot with Raspberry Pi Pico board
  • You can buy this sensor using this link – Click on me
  • How to make a line-tracking robot with Arduino – Click on me

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, cut a piece of foam board in the following sizes. But, you can use Rigifoam or other suitable materials.

Step 3

Thirdly, cut the car chassis using the following sizes.

Step 4

And then, connect the robot wheels for the gear motors and glue them on the chassis.

Step 5

Next drill a hole near the gear motors and put the motor wire through this hole. After that, install the L298N motor driver board on the top of the robot chassis.

step 6

Now, connect the gear motors to the motor driver board. And then, attach the caster wheel to the back side of the robot car chassis.

Step 6

Next, place the Raspberry Pi Pico board on the breadboard and install it on the top of the robot chassis.

Step 7

And then, connect the motor driver to the Raspberry PI Pico board. For that, use the circuit diagram below.

How to make a Line Tracking robot with Raspberry Pi Pico board

Step 8

Now, attach the 3-way IR infrared sensor module to the front of the robot car chassis. And then, connect this module to the Raspberry Pi Pico board. For that, use the circuit diagram above. (I used 10 male-to-female jumper wires. Because the jumper wires are short. )

Step 9

Next, connect the battery holder wires to the motor driver board. Now, install it on the top of the chassis.

Step 10

Finally, connect this robot to the computer. And then, copy and paste the following script on the Thonny IDE.

  • Script and circuit diagram — Download

from machine import Pin, PWM
from time import sleep

ENA = PWM(Pin(1))
IN1 = Pin(2,Pin.OUT)
IN2 = Pin(3,Pin.OUT)
IN3 = Pin(4,Pin.OUT)
IN4 = Pin(5,Pin.OUT)
ENB = PWM(Pin(6))
right = Pin(7, Pin.IN)
middle = Pin(8, Pin.IN)
left = Pin(9, Pin.IN)

# speed of this car
speed = 45000 # 0 - 65025
ENA.duty_u16(speed)
ENB.duty_u16(speed)


def lineTracking():
    sleep(0.05)
    return[left.value(),middle.value(),right.value()]


def robot():
    sensorValues = lineTracking()
    if sensorValues == [1,1,1]:
        stop()
    elif sensorValues == [0,0,0]:
        stop()
    elif sensorValues == [1,0,1]:
        forward()
    elif sensorValues == [0,1,1]:
        turnLeft()
    elif sensorValues == [0,0,1]:
        turnLeft()
    elif sensorValues == [1,1,0]:
        turnRight()
    elif sensorValues == [1,0,0]:
        turnRight()
        
def forward():
    IN1.on()
    IN2.off()
    IN3.on()
    IN4.off()
    
def turnRight():
    IN1.on()
    IN2.off()
    IN3.off()
    IN4.on()
    
def turnLeft():
    IN1.off()
    IN2.on()
    IN3.on()
    IN4.off()
    
def stop():
    IN1.off()
    IN2.off()
    IN3.off()
    IN4.off()


if   __name__ == '__main__':
    try:
        while True:
            robot()
    except KeyboardInterrupt:
        stop()

  • Now, save this script on the Raspberry Pi Pico board. You have to save it as “main.py”. And then, click the run button.

Step 11

Now, remove the USB cable and put the batteries into the battery holder. And then, check the motor directions and change the motor wires if they are not rotating in the correct direction.

OK, now place this robot car on the black color track. You can design it as you like. Please get a width of 1 inch.

How to make a Line Tracking robot with Raspberry Pi Pico board

OK, enjoy this project. The full video guide is below. We hope to see you in the next project or tutorial.

How to make a Line Tracking robot with Raspberry Pi Pico board

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *