Skip to main content
Version: FILS English

Rusty Car-go line follower

A car that follows a light-absorbing black line using Infrared sensors.

info

Author: Mohamed Daoudo
GitHub Project Link: https://github.com/UPB-PMRust-Students/project-Joan-DwD

Description​

Rusty Car-go is a car programmed in Rust that follows a black colored tape that absorbs light compared to the surrounding surface which typically absorbs more light using IR (infrared) sensors that read digital low or digital high, and the Rasberry Pi Pico 2W reads these signals and adjusts the motors' speed/direction via L298N moto driver, and lights up a little LED when the car is going. This project serves as a door to building more more creative and fun projects.

Motivation​

As a little kid, the idea of seeing wires connected to each other causing machines to move and work, whether for fun or to assist us in our daily lives fascinated me. It led me to build simple projects, such as small fans during the summer or a cotton candy machine because I enjoyed sweets. Reminiscing about these days motivated me to work with DC motors and wires again and build a car with them.

Architecture​

The Raspberry Pi Pico 2W powered by L298N motor driver's onboard 5V regulator to ensure stable supply, It serves as a brain that directs the behaviour of the robot, it's technically responsible for data processing, It outputs directional control and PWM speed signals to the L298N Motor driver which is connected to it via several GPIO pins.

The IR sensors, powered by 3.3V power source of the pico, are connected to the Pico's GPIO pins, detect the line's position based on the color black and send digital signals to the microcontroller to keep the robot on it's track .

The L298N motor driver, powered by batteries, controls the speed and direction of DC motors connected to it via it's output terminals, whose role is to drive the robot's wheels according to Pico's commands, simultaneously, an LED connected to Pico's GPIO pin lights up whenever the motors are active, providing visual feedback.

Finally, the chassis, it provides a well-structured body for the components ensuring stable operation, protection, and ease of assembly.

alt text

Log​

Week 5-11 May​

I started imagining the code and it's structure to make it well-suitable and compatible with what I learned throughout the labs, and wrote a few simple lines regarding the initialization of my components and their behaviour (e.g. PWM for my car's speed via En pins).

However, I immediately started working on the car by assembling and testing some of the components to ensure that they were in a perfect condition as soon as they arrived as it had a higher priority than the software part at that moment.

Moreover, I started desiging an early inchoate version of my KiCad schematic for the robot in order to gain more familiarity with the software and make some improvements later for the Hardware Milestone.

Week 12-18 May​

I finally received all of my stuff including what was missing and used my solderer to connect whats needed (RP, DC motors, and the Switch), assembled all the components, made sure everything is wired and connected carefully, and acquired the final model for the robot.

I also got to update my KiCad schematic and obtain one final version that suits and matches well with my board connections, and took better shots of my hardware.

Without further ado, I began contemplating the software part more deeply and committed what I had written initially.

Week 19-25 May​

This week marked the successful completion of the software for my Car-go. With all hardware components assembled, I focused entirely on finalizing the embedded Rust firmware.

The software is designed to continuously read sensor data in real time and adjust motor behavior accordingly. Depending on the detected position of the black line, the system dynamically regulates motor speed and direction using PWM signals, enabling the car to follow gentle curves and turns smoothly and accurately.

I implemented a responsive control mechanism that interprets various sensor combinations to determine the appropriate motion, such as moving forward, turning left or right, or stopping when the line is lost. All control logic is handled asynchronously to ensure fast reaction times and reliable performance.

After extensive testing and calibration, including adjusting sensor thresholds and motor speeds, the car now tracks the line. With the final version of the code committed and functioning as intended, this week concludes the full integration of software into a working robotic system.

Hardware​

  • Raspberry Pi Pico 2W: The central controller of the robot aka the "brain".
  • Infrared sensors: Used for black or white line detection.
  • L298N motor driver: Controls DC motor speed or direction.
  • DC motors: Used to move and steer the robot.
  • 2 AA battery holders connected (4x, 3x): Power supply to the motor driver.
  • LED: Indicator of motor activity.
  • I/O Switch: Adds more flexibility in turning off/on the robot instead of manual wiring.
  • The robot chassis: It serves as the body of the robot and holds all components.

Pictures​

cargo2

cargo1

cargo

Schematics​

Schematic

Bill of Materials​

DeviceUsagePrice
Raspberry Pi Pico 2WMicrocontroller39.66β€―RON
IR sensorsline detection10,47β€―RON
DC motors with wheels & chassis (unassembled)Structure of the robot79.59 RON
L298N Motor DriverControl speed of DC motors10.99 RON
Male-Male jumper wires setConnecting components7.99 RON
10cm Female-Male jumper wiresConnecting components2.99 RON
20cm Female-Male jumper wiresConnecting components3.99 RON
LEDMotor activity indicationAlready had it
SwitchPower switching1.99 RON
Battery holder 4 x R6Power supply9.43 RON
Battery holder 3 x R6Power supply3.95 RON
BreadboardCircuit building4.56 RON

Software​

LibraryDescriptionUsage
defmtLogging and debuggingprinting debug information
embassy_executorTask management system for asynchronous Rustspawning asynchronous tasks concurrently
embassy_rp::gpioPico GPIO control pinsconfiguring digital input/output pins
embassy_rp::pwmPulse width modulationto mainly control motor speed and direction
embassy_timeTime and delay handling in asynchronous Rustadds delays or wait for a specific duration in tasks
panic_probePanic handlingSends panic messages through defmt
embassy_sync::blocking_mutex::raw::ThreadModeRawMutexblocking thread mutexProvides safe access to shared data across async tasks
embassy_sync::channelChannel messaging systemAllows async message passing between producers and consumers

1.How to construct line following robot

2.Line following car with Raspberry Pi Pico

3.More guidance

4.Reasearch Article