Introduction
In this tutorial, we will show you how to make Line Follower Robot using Raspberry Pi Pico at home. This robot follows the black line on a white surface. It uses Infrared sensors to detect the line and follows it. This robot is easy to make and this is an ideal project for beginners who are just starting out with Raspberry Pi Pico.
If you move through the provided guide and follow the step-by-step instruction, you can make your own line follower robot using Raspberry Pi Pico at home. check also Raspberry Pi Pico W Remote Controlled Car Robot Web Server
Materials Required for Line Follower Robot using Raspberry Pi Pico
1. Raspberry Pi Pico ( Amazon / AliExpress)
2. L298N motor driver ( Amazon / AliExpress)
3. IR sensor module ( Amazon / AliExpress)
4. 7.4 or 9V battery ( Amazon / AliExpress)
5. BO motor ( Amazon / AliExpress)
6. Hobby robot chassis ( Amazon / AliExpress)
7. Wires ( Amazon / AliExpress)
Raspberry Pi Pico
Raspberry Pi Pico is a microcontroller board based on a Powerful Chip RP2040 developed by Raspberry Pi Foundation in the UK. pico designed for use to create Electronics Projects and other Devices.
The Pico board features 264KB of on-board SRAM, 2MB of SPI flash memory, and a collection of general-purpose I/O pins. It also supports C, MicroPython, and C++ programming languages. Check Getting Started Tutorial WIth Raspberry Pi Pico – Pinout, Specs – Beginner Guide
How does It work?
Line Follower Robot is an autonomous robot that is developed to follow a line, usually drawn with black tape on a white surface. The robot is fitted with IR sensors which detect the line and guide the robot along it.
Line follower robots are normally used in industrial automation, educational robotics, and competitions.
Circuit Diagram – Line Follower Robot using Raspberry Pi Pico
In this project, we used two motors. Motor 1 is connected to the first channel of the L298N Motor Driver, whereas motor 2 is attached to the second channel of the L298N motor driver.
IN1, IN2, IN3, and IN4 pins are respectively connected to pin 10, 11, 12, and 13 of Raspberry Pi Pico.
The circuit consists of four main parts: two IR sensors, two motors, one motor driver, and one Raspberry Pi Pico Board. Also, there are a few connecting wires. The circuit is powered by a 9V battery. When the sensor detects the reflected IR light, it provides the output to the Pico Board and the pico control direction of the motor.
Software & Micropython Code
Download and install the Thonny IDE Software from the below link and upload the code to your board.
Getting Started With Raspberry Pi Pico With Thonny IDE
Micopython Script – Line Follower Robot using Raspberry Pi Pico
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from machine import Pin from machine import PWM from utime import sleep as delay SensorR = Pin(14, Pin.IN) # Right IR Sensor SensorL = Pin(15, Pin.IN) # Left IR Sensor IN1 = Pin(10, Pin.OUT) # IN1 Motor Driver IN2 = Pin(11, Pin.OUT) # IN2 Motor Driver IN3 = Pin(12, Pin.OUT) # IN3 Motor Driver IN4 = Pin(13, Pin.OUT) # IN4 Motor Driver motorEsq1 = PWM(IN1) motorEsq2 = PWM(IN2) motorDir1 = PWM(IN3) motorDir2 = PWM(IN4) motorEsq1.freq(490) motorEsq2.freq(490) motorDir1.freq(490) motorDir2.freq(490) # Equivalent to map() function def map(x, in_min, in_max, out_min, out_max): return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min # Function to convert speed from 0 to 100 into 16-bit PWM pulse def pulsoMotor(speed): return map(speed, 0, 100, 0, 65534) def parar(): motorEsq1.duty_u16(0) motorDir1.duty_u16(0) motorEsq2.duty_u16(0) motorDir2.duty_u16(0) # 2 second delay to start the "loop" parar() delay(2) while True: valSensorE = SensorR.value() valSensorD = SensorL.value() if not valSensorD and valSensorE : motorEsq1.duty_u16(pulsoMotor(0)) motorDir1.duty_u16(pulsoMotor(50)) elif not valSensorE and valSensorD : motorDir1.duty_u16(pulsoMotor(0)) motorEsq1.duty_u16(pulsoMotor(50)) elif not valSensorE and not valSensorD : motorEsq1.duty_u16(pulsoMotor(50)) motorDir1.duty_u16(pulsoMotor(50)) else: parar() |
Conclusion
In this article, we made a line follower robot using Raspberry Pi Pico. By following the step-by-step instructions shown in this article, you can build a line-follower robot at home.
Raspberry Pi Projects
- Interfacing PIR Motion Sensor with Raspberry Pi Pico
- Raspberry Pi Pico Home Automation System
- Interface Servo Motor With Raspberry Pi Pico
- Interface 0.96″ OLED Display with Raspberry Pi Pico
- Raspberry Pi Pico Weather Station Using Dht11 Sensor
- Interface 16*2 LCD Display With Raspberry Pi Pico