Skip to content

A line-following robot project using Raspberry Pi and PiCamera that autonomously follows a black line and detects intersections, navigating a predefined route with PID control.

Notifications You must be signed in to change notification settings

Adilnasceng/Line-follower

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Line Following and Intersection Detection Robot using Raspberry Pi

This project uses a Raspberry Pi and PiCamera to follow a black line on the ground and detect intersections. Based on the detected intersection count, the robot executes predefined movements (e.g., go straight, turn left, stop) using a PID control system.

๐Ÿ”ง Features

  • Real-time video processing using PiCamera
  • Black line detection and tracking
  • Intersection detection based on line width
  • Predefined path control (left, right, straight, stop)
  • PID control for smooth line following

๐Ÿ“ฆ Hardware Requirements

  • Raspberry Pi (3 or 4)
  • PiCamera
  • 2 DC motors
  • Motor driver (e.g., L298N, BTS7960)
  • Robot chassis with black line track

๐Ÿ“Œ GPIO Pin Configuration

Motor Action GPIO Pin
Right Forward 26
Right Backward 6
Left Forward 5
Left Backward 19

๐Ÿš€ Installation

  1. Update packages and install dependencies:

    sudo apt update
    sudo apt install python3-opencv python3-picamera
    
    
  2. Run the program with root privileges:

    sudo python3 main.py

๐Ÿง  How It Works

  • Captures frames from the PiCamera.
  • Converts the frame to grayscale and applies binary thresholding.
  • Detects black contours using cv2.findContours.
  • Identifies the largest black region and calculates its center and angle.
  • Applies PID control based on line position and angle to adjust motor speeds.
  • Detects intersections when line width exceeds a threshold and reacts accordingly.

๐Ÿ—บ Path Definition

The robot follows a predefined route based on the number of detected intersections:

rota = {
    1: "straight",
    2: "left",
    3: "left",
    4: "stop"
}
  • 1st intersection โ†’ go straight
  • 2nd intersection โ†’ turn left
  • 3rd intersection โ†’ turn left
  • 4th intersection โ†’ stop

โš™๏ธ PID Parameters

Kp = 0.35
Ki = 0.001
Kd = 0.09
K_ang = 0.3

You can tune these values to better match your robot's behavior and environment.

๐ŸŽž Demo

Line Following Robot Demo

๐ŸŽฎ Controls

  • Press q to quit the program.

โš ๏ธ Notes

  • Ensure the robot is placed on a surface with high contrast black lines.
  • The robot stops and GPIO pins are safely cleaned up at the end of execution.

About

A line-following robot project using Raspberry Pi and PiCamera that autonomously follows a black line and detects intersections, navigating a predefined route with PID control.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages