Line Follower Car

by kaancelk in Circuits > Raspberry Pi

8 Views, 0 Favorites, 0 Comments

Line Follower Car

IMG_5590.jpeg
IMG_5596.jpeg

An autonomous line-following car built on a Freenove 4WD smart car kit using Raspberry Pi and Python. The robot features advanced computer vision for line detection, adaptive thresholding for various lighting conditions, and an intelligent backup-and-search recovery system when the line is lost

Supplies

rpi5b.jpg
download.png

Hardware Components:

  1. Freenove 4WD Smart Car Kit (includes motors, wheels, motor driver)
  2. Raspberry Pi 5 or any (4GB RAM recommended)
  3. MicroSD Card (32GB or larger)
  4. USB Webcam (v2 or RaspBerry Pi Camera Module)
  5. Power Bank or Rechargeable Battery Pack (5V, 2A minimum for Pi + motors)
  6. MicroUSB or USB-C Cable (for Pi power, depending on Pi model)

Software Requirements:

  1. Raspberry Pi OS (latest version)
  2. Python 3.7+ (usually pre-installed)
  3. OpenCV (pip install opencv-python)
  4. NumPy (pip install numpy)
  5. Freenove Car Library (provided with kit)

Tools Needed:

  1. Screwdriver Set (Phillips head, various sizes)
  2. Wire Strippers
  3. Multimeter (for troubleshooting)
  4. Computer (for initial Pi setup and code development)

Track Materials:

  1. Black Electrical Tape (for creating test tracks)
  2. White Poster Board or Large White Paper (track surface)
  3. Ruler/Measuring Tape (for track layout)

Estimated Total Cost:

  1. Freenove Kit: € 69.99
  2. Raspberry Pi 5: € 129,95
  3. Accessories: € 20 - 30
  4. Total: ~€ 220-230

Hardware Assembly

707aaf77-b26d-4c5d-9b72-0c321b75aa99.jpg
  1. Assembled the Freenove 4WD Smart Car Kit following the manufacturer's instructions
  2. Connected the Raspberry Pi 5 to the car and wired the motor driver board
  3. Mounted the USB Camera in an optimal position for line detection (facing downward at appropriate angle)
  4. Connected all GPIO pins between the Pi and the motor control board
  5. Installed the power supply system (battery pack) with proper voltage regulation


Software Environment Setup

  1. Flashed Raspberry Pi OS onto the microSD card and performed initial Pi configuration
  2. Installed required Python libraries: OpenCV, NumPy, and the Freenove car control library
  3. Set up the development environment and tested basic camera functionality
  4. Configured GPIO permissions and tested motor control functions


Line Detection Development

  1. Started with simple computer vision code to detect black lines on white surfaces
  2. Implemented adaptive thresholding using cv2.THRESH_BINARY for proper black line detection (white background with black line)
  3. Developed contour detection algorithms to identify and track the line position
  4. Created real-time camera feed processing with frame capture and analysis


Motor Control Integration

e23a55d6-4fe1-43d3-80c6-72d41462fcb2.jpg
  1. Created a robust motor controller class specifically for the Freenove 4WD kit
  2. Implemented forward, backward, left turn, and right turn functions with proper PWM control
  3. Calibrated motor speeds for smooth movement and accurate turning responses
  4. Added safety features including emergency stop functionality

Line Following Logic

  1. Developed position detection algorithm dividing the camera view into zones (FAR_LEFT, LEFT, CENTER, RIGHT, FAR_RIGHT)
  2. Implemented decision-making logic to control car movement based on detected line position
  3. Fine-tuned turning sensitivity and forward speed for accurate line tracking
  4. Added state management to remember last known line position

Advanced Recovery System

  1. Identified the problem where traditional line followers get stuck when losing the track
  2. Implemented intelligent backup functionality that activates when no line is detected for several frames
  3. Created backup-and-turn movements that search for the line by moving in the opposite direction of the last known position
  4. Added alternating search patterns to systematically recover lost tracks

Adaptive Threshold System

  1. Developed brightness detection to automatically adjust threshold values based on lighting conditions
  2. Implemented adaptive algorithms that work in various environments (indoor/outdoor, different lighting)
  3. Added real-time threshold adjustment to maintain consistent line detection performance
  4. Created fallback detection methods for challenging lighting scenarios


User Interface and Debugging

5ccb7b87-4d38-4cad-9048-3af5af52ce12.jpg
  1. Built comprehensive debug visualization showing original camera feed, processed images, and detection status
  2. Added keyboard controls for start/stop, manual override, and system reset functions
  3. Implemented real-time status display with FPS counter, brightness levels, and detection confidence
  4. Created detailed logging system for troubleshooting and performance monitoring

Testing and Optimization

  1. Created test tracks with various challenges: curves, gaps, intersections, and lighting variations
  2. Iteratively tuned parameters for optimal performance across different track conditions
  3. Tested recovery system with intentionally interrupted tracks and complex course layouts
  4. Optimized processing speed to maintain real-time performance while ensuring accuracy




Thank you for your attention!

Feel free to contact me if you have any questions about it.

Contact information:

Email: kaan.celik@student.howest.be

Phone number: +32492555208