Line Follower Car


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


Hardware Components:
- Freenove 4WD Smart Car Kit (includes motors, wheels, motor driver)
- Raspberry Pi 5 or any (4GB RAM recommended)
- MicroSD Card (32GB or larger)
- USB Webcam (v2 or RaspBerry Pi Camera Module)
- Power Bank or Rechargeable Battery Pack (5V, 2A minimum for Pi + motors)
- MicroUSB or USB-C Cable (for Pi power, depending on Pi model)
Software Requirements:
- Raspberry Pi OS (latest version)
- Python 3.7+ (usually pre-installed)
- OpenCV (pip install opencv-python)
- NumPy (pip install numpy)
- Freenove Car Library (provided with kit)
Tools Needed:
- Screwdriver Set (Phillips head, various sizes)
- Wire Strippers
- Multimeter (for troubleshooting)
- Computer (for initial Pi setup and code development)
Track Materials:
- Black Electrical Tape (for creating test tracks)
- White Poster Board or Large White Paper (track surface)
- Ruler/Measuring Tape (for track layout)
Estimated Total Cost:
- Freenove Kit: € 69.99
- Raspberry Pi 5: € 129,95
- Accessories: € 20 - 30
- Total: ~€ 220-230
Hardware Assembly

- Assembled the Freenove 4WD Smart Car Kit following the manufacturer's instructions
- Connected the Raspberry Pi 5 to the car and wired the motor driver board
- Mounted the USB Camera in an optimal position for line detection (facing downward at appropriate angle)
- Connected all GPIO pins between the Pi and the motor control board
- Installed the power supply system (battery pack) with proper voltage regulation
Software Environment Setup
- Flashed Raspberry Pi OS onto the microSD card and performed initial Pi configuration
- Installed required Python libraries: OpenCV, NumPy, and the Freenove car control library
- Set up the development environment and tested basic camera functionality
- Configured GPIO permissions and tested motor control functions
Line Detection Development
- Started with simple computer vision code to detect black lines on white surfaces
- Implemented adaptive thresholding using cv2.THRESH_BINARY for proper black line detection (white background with black line)
- Developed contour detection algorithms to identify and track the line position
- Created real-time camera feed processing with frame capture and analysis
Motor Control Integration

- Created a robust motor controller class specifically for the Freenove 4WD kit
- Implemented forward, backward, left turn, and right turn functions with proper PWM control
- Calibrated motor speeds for smooth movement and accurate turning responses
- Added safety features including emergency stop functionality
Line Following Logic
- Developed position detection algorithm dividing the camera view into zones (FAR_LEFT, LEFT, CENTER, RIGHT, FAR_RIGHT)
- Implemented decision-making logic to control car movement based on detected line position
- Fine-tuned turning sensitivity and forward speed for accurate line tracking
- Added state management to remember last known line position
Advanced Recovery System
- Identified the problem where traditional line followers get stuck when losing the track
- Implemented intelligent backup functionality that activates when no line is detected for several frames
- Created backup-and-turn movements that search for the line by moving in the opposite direction of the last known position
- Added alternating search patterns to systematically recover lost tracks
Adaptive Threshold System
- Developed brightness detection to automatically adjust threshold values based on lighting conditions
- Implemented adaptive algorithms that work in various environments (indoor/outdoor, different lighting)
- Added real-time threshold adjustment to maintain consistent line detection performance
- Created fallback detection methods for challenging lighting scenarios
User Interface and Debugging

- Built comprehensive debug visualization showing original camera feed, processed images, and detection status
- Added keyboard controls for start/stop, manual override, and system reset functions
- Implemented real-time status display with FPS counter, brightness levels, and detection confidence
- Created detailed logging system for troubleshooting and performance monitoring
Testing and Optimization
- Created test tracks with various challenges: curves, gaps, intersections, and lighting variations
- Iteratively tuned parameters for optimal performance across different track conditions
- Tested recovery system with intentionally interrupted tracks and complex course layouts
- 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