This repository contains the code and documentation for a high-speed line-follower robot developed as a class project. The primary goal was to implement an efficient and responsive state machine for rapid line tracking.
This project was developed as a collaboration by the following members of the Robotics course:
The objective was to build a robot capable of autonomously following a black line on a white surface and completing the course as quickly as possible. This required a focus on speed and efficient state processing to minimize decision latency.
The objective was to build a robot capable of autonomously following a black line on a white surface and completing the course as quickly as possible.
- Speed Focus: Achieving maximum track velocity by minimizing decision latency.
- PID Control: Utilizing a Proportional-Integral-Derivative (PID) control loop for smooth speed adjustments, reducing the "wobble" common in basic line-following robots.
-
O(1) State Encoding: The code uses bitwise operations to encode sensor inputs, ensuring
$\mathbf{O(1)}$ time complexity for state lookup.
The robot utilizes a TCRT5000 Tracking Module for sensing the line, which is central to the control logic.
- Microcontroller: Arduino Uno
- Sensor: TCRT5000 Tracking Module (3-channel)
- Actuator: DC Motors and Motor Driver (L298N is used)
- Chassis: Robot chassis with wheels
- Power: Battery pack (9V)
To upload and run the code successfully, ensure you have the following software and libraries installed:
- Arduino IDE: The latest version of the Arduino Integrated Development Environment.
- Motor Driver Library (Optional): If your motor driver (e.g., L298N) requires a specific library for simplified control, ensure it's installed via the Library Manager.
The following connections are typically required for this setup. Always verify the specific pinout of your motor driver and sensor module.
| Component | Function | Code Definition | Arduino Pin | Pin Type |
|---|---|---|---|---|
| Line Sensor | Left Sensor Input | LEFT | D6 | Digital Input |
| Line Sensor | Center Sensor Input | CENTER | D7 | Digital Input |
| Line Sensor | Right Sensor Input | RIGHT | D8 | Digital Input |
| Left Motor | Left Enable (Speed PWM) | ENA | D10 | PWM Output |
| Left Motor | Forward Direction Pin | IN1 | D5 | Digital Output |
| Left Motor | Backward Direction Pin | IN2 | D4 | Digital Output |
| Right Motor | Right Enable (Speed PWM) | ENB | D9 | PWM Output |
| Right Motor | Forward Direction Pin | IN3 | D2 | Digital Output |
| Right Motor | Backward Direction Pin | IN4 | D3 | Digital Output |
- Motor Driver Connection: The driver requires 6 control pins (IN1 through IN4, ENA, ENB). ENA and ENB must be connected to PWM capable pins (Pins D9 and D10 on the Uno) as they control motor speed via analogWrite().
- Sensor Power: The TCRT5000 sensor module's VCC and GND pins should be connected to the Arduino's 5V and GND rails.
- Motor Power Isolation: It is critical to power the motor driver's dedicated power input (e.g.,
$+12V$ or$+9V$ ) with a separate battery pack (not the Arduino's VIN or 5V pin). This prevents current draw spikes from resetting the Arduino.
Follow these steps to upload the code and start the robot:
- Clone the repository
Clone this GitHub repository to your local machine:
git clone https://github.com/your-username/line-follower-robot.git
- Open in Arduino IDE
- Open the Arduino IDE.
- Go to File > Open and navigate to the cloned folder.
- Select the main sketch file (e.g., line_follower.ino).
- Configure and Upload
- Configure Pins: Double-check that the pin assignments in the code (usually defined at the top) match your physical wiring setup.
- Select Board: Go to Tools > Board and select your Arduino model (e.g., "Arduino Uno").
- Select Port: Go to Tools > Port and select the correct serial port for your connected Arduino.
- Upload: Click the Upload button (right arrow icon) to flash the code to the microcontroller.
- Running the robot
- Place the robot on a designated track (a black line on a white surface).
- Ensure the robot's main power switch (for motors) is OFF before placement.
- Turn the robot power ON. The robot should immediately begin reading the sensors and attempt to follow the line.
In this section, I would love to talk more about the problem we have faced and you may also face during your own testing.
Check the motor direction logic in the code. You may need to swap the HIGH and LOW signals for one or both motors.
Ensure the TCRT5000 sensor is calibrated correctly. Most modules have potentiometers to adjust the sensitivity (the threshold between detecting black and white).
If the robot resets when the motors start, the motors are drawing too much current from the Arduino.