An open API service indexing awesome lists of open source software.

https://github.com/ahmed-maher77/line_follower_robot

An autonomous robot capable of accurately following a designated path, including sharp turns and interruptions. Designed a lightweight, 3D-printed chassis and implemented optimized PID control with infrared sensors for precise and efficient navigation.
https://github.com/ahmed-maher77/line_follower_robot

3d-printing arduino battery c-programming c-programming-language chassis competition competitive-programming embeded-systems ir-sensor line-follower-robot motor-driver motors pid-control robotics robotics-programming sensors spacers

Last synced: about 1 month ago
JSON representation

An autonomous robot capable of accurately following a designated path, including sharp turns and interruptions. Designed a lightweight, 3D-printed chassis and implemented optimized PID control with infrared sensors for precise and efficient navigation.

Awesome Lists containing this project

README

          

# Line Follower Robot — Competition-Ready (Arduino + PID)

An autonomous robot that follows a black line on a white track using infrared reflectance sensors and differential drive. This repo contains two control approaches:

- Basic 2-sensor bang-bang controller: `main.ino` (quick start)
- Advanced 5-sensor PID controller: `main_pid.ino` (smooth, fast, handles sharp turns and gaps)

How to Make Line Follower Robot Using Arduino

### How it works

Infrared sensors emit IR light and measure reflectance from the surface. White reflects more, black reflects less. The controller estimates the line position and adjusts motor speeds to keep the robot centered.

---

## Hardware

- **MCU**: Arduino Uno (ATmega328P) or Nano
- **Motor driver**: L298N (or L293D; wiring identical PWM/IN logic)
- **Motors**: 2× TT/DC gear motors with wheels
- **Sensors**:
- Basic: 2× digital IR line sensors (left/right)
- Advanced: 5× analog IR reflectance sensors (array)
- **Power**: 2S Li-ion/LiPo (7.4V) or 6×AA pack; separate motor/logic rails recommended
- **Chassis**: lightweight acrylic or 3D-printed; ball caster
- **Misc**: jumpers, spacers, switch, battery holder

> Tip: For competitions, prefer a 5–8 sensor analog array and a rigid, light chassis.

line follower robot - hardware

---

## Wiring

### Motors and driver (both sketches)

- `ENABLE_LEFT_MOTOR` → L298N ENA (PWM) → Arduino D5
- `LEFT_MOTOR_PIN1/PIN2` → L298N IN1/IN2 → Arduino D9/D10
- `ENABLE_RIGHT_MOTOR` → L298N ENB (PWM) → Arduino D6
- `RIGHT_MOTOR_PIN1/PIN2` → L298N IN3/IN4 → Arduino D7/D8
- Motor outputs: L298N OUT1–OUT2 → left motor, OUT3–OUT4 → right motor
- Power: Motor VIN (battery), +5V logic to Arduino 5V, common GND

### Sensors

- Basic (digital):
- Right sensor DO → Arduino D11 (`IR_SENSOR_RIGHT`)
- Left sensor DO → Arduino D12 (`IR_SENSOR_LEFT`)
- VCC 5V, GND common; trim pots adjust thresholds
- Advanced (analog 5×):
- S0..S4 → Arduino `A0..A4` (`SENSOR_0..SENSOR_4`)
- VCC 5V, GND common

---

## Firmware

### 1) Basic two-sensor control (bang-bang)

File: `main.ino`

Behavior:

- Both white → drive straight
- Right sees black → steer right
- Left sees black → steer left
- Both black → stop (e.g., junction/finish)

Tweak `MOTOR_SPEED` to set base speed.

### 2) Advanced five-sensor PID control

File: `main_pid.ino`

Features:

- Automatic sensor calibration on startup (3s)
- Weighted average line position (0..4000)
- PID correction for smooth, fast tracking
- Line-loss handling that steers back towards last seen direction

Key parameters:

- `BASE_SPEED` (default 150), `MAX_SPEED` (255)
- PID gains: `Kp`, `Ki`, `Kd`
- `CALIBRATION_TIME_MS` (default 3000)

Upload either sketch as-is depending on your hardware.

---

## PID Tuning (quick guide)

1. Start with `Ki = 0`, moderate `BASE_SPEED` (120–160).
2. Increase `Kp` until it oscillates, then back off ~20%.
3. Raise `Kd` to damp oscillations and improve cornering.
4. Add small `Ki` only if there’s consistent bias/drift.

Symptoms:

- Wobble → decrease `Kp` or increase `Kd`
- Slow response → increase `Kp`
- Corner overshoot → increase `Kd` or reduce `BASE_SPEED`

---

## Build and Run

1. Assemble hardware per wiring above.
2. Place robot over the track; ensure strong contrast (matte black line on matte white).
3. Upload `main.ino` for a quick test, then `main_pid.ino` for competition performance.
4. With PID sketch, on power-up it calibrates for ~3s. Slowly move the robot across the line during this period.
5. Adjust gains and `BASE_SPEED` to your track.

---

## Repository Structure

- `main.ino` — basic digital 2-sensor controller
- `main_pid.ino` — advanced analog 5-sensor PID controller
- `README.md` — documentation, wiring, tuning

---

## Troubleshooting

- Robot veers consistently: check sensor heights (2–3 mm), parallelism, and add `Ki` slightly.
- Random jitter: ensure clean power, common ground, decouple with 100 µF near driver.
- Misses sharp turns: increase `Kd`, or raise `BASE_SPEED` slightly for better angular authority.
- Loses line on gaps: ensure line contrast; the sketch biases towards last known direction.

---

## License

MIT