Building a 3-Sensor Line Follower Robot | Arduino + L298N | DIY
by Amit_innovates in Circuits > Arduino
46 Views, 0 Favorites, 0 Comments
Building a 3-Sensor Line Follower Robot | Arduino + L298N | DIY



π Introduction
In this project, weβll build a simple and efficient 3-sensor line follower robot using an Arduino, L298N motor driver, and IR sensors. Perfect for beginners and ideal for robotics competitions, this bot can follow a white path on a black surface and navigate turns using only three IR sensors.
π― Features
- Follows a white line on a black surface
- Takes sharp and soft turns
- Stops at junctions or line loss
- Simple logic using digital IR sensors
π‘ Check For Update: https://github.com/Amitm0v
Supplies






οΈ Step 1: Components Required
- Arduino UNO Amazon
- L298N Motor Driver Amazon
- 3 IR Line Sensors (Digital Output) Amazon
- 2 BO Motors + Wheels Amazon
- Chassis (custom or kit) Amazon
- Jumper wires Amazon
- Power supply (6Vβ12V battery pack)
- 18650 Battery (12v-18v) Amazon
- 3-4 Cell Holder Amazon
- Switch (optional)
Note:
- i m using Buck converter because my L298N doesn't output 5volts
π§ Wiring and Assembly



Attach the motors to the chassis.
IR Sensors:
- Left Sensor (LS): Digital output to pin 13 (D13)
- Middle Sensor (MS): Digital output to pin 12 (D12)
- Right Sensor (RS): Digital output to pin 11 (D11)
L298N Motor Driver:
- Left Motor: OUT1 & OUT2
- Right Motor: OUT3 & OUT4
- IN1 (LM1): Arduino D2
- IN2 (LM2): Arduino D3
- IN3 (RM1): Arduino D4
- IN4 (RM2): Arduino D5
- Enable Pins: Jumpered or connected to 5V
Power:
- L298N VCC: 12V battery pack
- GND: Common GND with Arduino
- Arduino: Powered by USB or Vin pin (from L298N 5V)
π§ Code


Im using Arduino IDE cloud.
Upload the following code to your Arduino:
( Code for black line on a white surface you will find on my github)
Downloads
Working Principle
Each IR sensor detects either black or white:
- White (no line): HIGH output
- Black (line): LOW output
The bot uses these sensor readings to decide the direction
|LS|MS|RS| Action |
|----|----|----|----------------------|
| 0 | 1 | 0 | Move Forward |
| 1 | 1 | 0 | Sharp Left |
| 0 | 1 | 1 | Sharp Right |
| 1 | 0 | 0 | Turn Left |
| 0 | 0 | 1 | Turn Right |
| 1 | 1 | 1 | Stop (junction) |
| 0 | 0 | 0 | Stop (lost) |
βοΈ Testing and Calibration

- Place the robot on a white line track with a black background.
- Power it on and observe its motion.
- Adjust sensor height or placement if it misreads.
- Check serial output for debugging info.
π‘ Tips and Troubleshooting
- If the bot moves randomly, check IR sensor logic (HIGH/LOW on line).
- If motors donβt rotate, verify L298N enable pins.
- You can swap wires to fix wrong motor directions.
- Add an LED to indicate line detection for debugging.
Adding Speed Control
For speed control, connect ENA and ENB pins of L298N to Digital I/O pins of Arduino UNO marked with PWM (~). The only addition in software would be to declare those pins, set them up in OUTPUT pinMode in void set up, and add the following lines of code at the start of void loop:
analogWrite(ENA, <speed>);
analogWrite(ENB, <speed>);
Where the value speed can take is between 0-255, 0 being stop, and 255 being highest achievable speed.
π Conclusion
This project introduces basic autonomous robot logic using just three sensors. It's ideal for beginners learning about embedded systems, sensor integration, and motor control.
Ready to take it to the next level? Try:
- Analog sensors for smoother line tracking
- PID control
- Maze-solving algorithms
- Use N20 Motors or stepper