Line follower robot with L298N and TCRT5000
The classic robotics starter: a two-wheeled car that tracks a black line on its own.
Shop by category
Shop all componentsFS90R servos spin all the way round: the pulse width sets speed and direction instead of angle, so you need no motor driver. Two QRE1113 reflective sensors under the front corners see the table surface; when one sees nothing (an edge), the robot backs up and turns the other way. An HY-SRF05 ultrasonic sensor on the front stops it before it hits a wall or a mug. One 18650 cell and a charge-discharge module give 5 V.
Test near the floor; a falling robot can break a servo or the cell holder.
Tick anything you already have and the total updates.
FEETECH FS90R continuous servo
QRE1113 reflective sensor
HY-SRF05 ultrasonic sensor
Follow the colours: red is power, dark grey is ground, blue is a signal.
One 18650 through the 5 V charge-discharge module; charge it over the module's USB port.
edge_robot.inoVerify & upload in Electrolark#include <Servo.h>
Servo left, right;
const int STOP_US = 1500, SPEED = 200; // trim STOP_US until the wheels stand still
const bool GO = true;
long distCm() {
digitalWrite(6, LOW); delayMicroseconds(2);
digitalWrite(6, HIGH); delayMicroseconds(10); digitalWrite(6, LOW);
long us = pulseIn(7, HIGH, 30000);
return us ? us / 58 : 999;
}
void drive(int l, int r) { // -1, 0 or +1 for each wheel
left.writeMicroseconds(STOP_US + l * SPEED);
right.writeMicroseconds(STOP_US - r * SPEED); // the right servo is mounted mirrored
}
void setup() {
Serial.begin(9600);
left.attach(9); right.attach(10);
pinMode(2, INPUT); pinMode(3, INPUT);
pinMode(6, OUTPUT); pinMode(7, INPUT);
drive(0, 0); delay(1000);
}
void loop() {
// QRE1113 digital modules read HIGH when nothing reflects (an edge). Swap if yours is the other way.
bool edgeL = digitalRead(2) == HIGH, edgeR = digitalRead(3) == HIGH;
long d = distCm();
Serial.print(edgeL); Serial.print(' '); Serial.print(edgeR); Serial.print(' '); Serial.println(d);
if (!GO) { drive(0, 0); return; }
if (edgeL || edgeR) {
drive(-1, -1); delay(400);
if (edgeL) drive(1, -1); else drive(-1, 1);
delay(500);
} else if (d < 15) {
drive(-1, 1); delay(400);
} else {
drive(1, 1);
}
delay(20);
}
Trim STOP_US by 5-10 at a time; some FS90R servos also have a small trim screw.
The sensors are too high or point too far forward; mount them 3-5 mm above the surface and just ahead of the wheels.
The cell is low or the wires are thin; charge it and add a 470 uF capacitor across 5 V and GND.
They include the gearbox and driver; one signal wire per wheel is easier for beginners.
Black or glass tops reflect little IR; test the sensor values first and adjust the module's threshold if it has one.
Yes, point the same sensors at a black line on white paper and steer to keep it between them.
9 parts: Generic Nano CH340 Development Board (Soldered), 2 × FEETECH FS90R 6V 360 Degree Micro 9G Positive and Negative Continuous Servo MotorTorque:1.5KG, 2 × Generic QRE1113 Infrared Reflection Sensor Module Red – Digital Output, 3-Pin Header, HY-SRF05 Ultrasonic Sensor Module – 5-Pin Interface, 3cm-4.5m Range, 5V 2A Charge-Discharge Integrated Module, 18650 Li-ion Rechargeable Cell, 18650 Battery Holder, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 3 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (edge_robot.ino).
About ₹1,809 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Driving continuous-rotation servos; Using reflective IR sensors as cliff sensors; Simple behaviour priority in a robot loop.
Test near the floor; a falling robot can break a servo or the cell holder.
The classic robotics starter: a two-wheeled car that tracks a black line on its own.
A robot that looks left and right with its ultrasonic "head" and picks the clearest way.
Roams a tabletop without ever driving off the edge.
Drive a 4WD car from your Android phone over Bluetooth.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.