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 componentsSteer the chassis by hand with an analog joystick, with the stick's position setting both direction and speed. A joystick is two potentiometers at right angles. At rest both read about 512, and pushing in either direction swings the reading towards 0 or 1023. Subtracting 512 turns each axis into a signed value: how far, and which way. A dead zone of ±80 is essential, real sticks never centre perfectly, and without it the robot would creep whenever you let go.
Switch the battery holder off before you change any wiring, and lift the wheels off the table for the first test.
Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
The brain of every Explorer Kit project
Male-to-female and female-to-female leads for the modules
Analog joystick: two potentiometers and a push switch
2WD chassis with two gear motors, wheels and a caster
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
Motors run from the 2 x 18650 pack (7.4V) through the L298N. The USB cable powers the Nano while you test; unplugged, the L298N's 5V output powers it.
explorer_kit_37_hand_controlled_robot.inoVerify & upload in Electrolarkint ENA = 9, IN1 = 4, IN2 = 5, IN3 = 6, IN4 = 7, ENB = 10;
int xPin = A0;
int yPin = A1;
int deadZone = 80;
void motors(int l1, int l2, int r1, int r2, int power)
{
digitalWrite(IN1, l1); digitalWrite(IN2, l2);
digitalWrite(IN3, r1); digitalWrite(IN4, r2);
analogWrite(ENA, power);
analogWrite(ENB, power);
}
void setup()
{
pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int x = analogRead(xPin) - 512;
int y = analogRead(yPin) - 512;
Serial.print("X: ");
Serial.print(x);
Serial.print(" Y: ");
Serial.println(y);
if (abs(y) > deadZone && abs(y) >= abs(x))
{
int power = map(abs(y), deadZone, 512, 90, 255);
power = constrain(power, 90, 255);
if (y > 0)
{
motors(HIGH, LOW, HIGH, LOW, power); // Forward
}
else
{
motors(LOW, HIGH, LOW, HIGH, power); // Backward
}
}
else if (abs(x) > deadZone)
{
int power = map(abs(x), deadZone, 512, 90, 220);
power = constrain(power, 90, 220);
if (x > 0)
{
motors(HIGH, LOW, LOW, HIGH, power); // Spin right
}
else
{
motors(LOW, HIGH, HIGH, LOW, power); // Spin left
}
}
else
{
motors(LOW, LOW, LOW, LOW, 0); // Centred - stop
}
delay(30);
}
Use the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
Read the centre value in the Serial Monitor and widen the dead zone numbers in the sketch.
Switch the battery holder on, check +12V and GND on the L298N, take the ENA and ENB jumper caps off, and make sure battery GND joins Nano GND.
A joystick is two potentiometers at right angles. At rest both read about 512, and pushing in either direction swings the reading towards 0 or 1023. Subtracting 512 turns each axis into a signed value: how far, and which way. A dead zone of ±80 is essential, real sticks never centre perfectly, and without it the robot would creep whenever you let go.
Serial Monitor shows X and Y near 0 when the stick is centred. Push forward gently and the robot creeps; push fully and it runs. Push sideways and it spins on the spot.
Yes. It is project 37 of 61 in the Geekobot Explorer Kit, in level 7 (Robotics and motion). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
9 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, Dupont Jumper Wires (40 pcs), PS2 Thumb Joystick Module (KY-023 style), 2WD Smart Robot Car Chassis Kit, L298N Dual H-Bridge Motor Driver Module, Arduino Nano IO Expansion Shield (328P Compatible), 18650 Battery Holder and 2 × 18650 Li-ion Rechargeable Cell. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1 hour. The build on this page has 7 steps.
No. This page has the complete, tested code (explorer_kit_37_hand_controlled_robot.ino).
About ₹1,198 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Analog joystick mapping to motor speeds; Centring a reading by subtracting the midpoint; Why a dead zone is necessary; Choosing between axes with abs() comparisons.
Switch the battery holder off before you change any wiring, and lift the wheels off the table for the first test. Charge 18650 cells only in a proper Li-ion charger and never short the holder's wires.
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.
Learning project. Check every circuit and the datasheet of each part before you power it up.