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 componentsDrive with proportional steering: the joystick's X and Y are mixed so each wheel gets its own speed and the car turns smoothly. Experiment 37 picked one axis and ignored the other. Here both are used at once, with the classic differential mix: left = forward + turn, right = forward − turn. Push the stick diagonally and one wheel simply runs faster than the other, so the car sweeps through a curve instead of pivoting. The sign of each result decides that wheel's direction, and its magnitude becomes the PWM value, this is Cartesian mapping, turning an (x, y) point into two motor commands.
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_43_joystick_car.inoVerify & upload in Electrolarkint ENA = 9, IN1 = 4, IN2 = 5, IN3 = 6, IN4 = 7, ENB = 10;
int xPin = A0;
int yPin = A1;
int deadZone = 60;
void setLeft(int value)
{
if (value >= 0)
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
}
else
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
}
analogWrite(ENA, constrain(abs(value), 0, 255));
}
void setRight(int value)
{
if (value >= 0)
{
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
else
{
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
analogWrite(ENB, constrain(abs(value), 0, 255));
}
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;
if (abs(x) < deadZone) x = 0;
if (abs(y) < deadZone) y = 0;
int drive = map(y, -512, 512, -255, 255);
int turn = map(x, -512, 512, -180, 180);
int leftPower = drive + turn;
int rightPower = drive - turn;
leftPower = constrain(leftPower, -255, 255);
rightPower = constrain(rightPower, -255, 255);
Serial.print("L: ");
Serial.print(leftPower);
Serial.print(" R: ");
Serial.println(rightPower);
setLeft(leftPower);
setRight(rightPower);
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.
Experiment 37 picked one axis and ignored the other. Here both are used at once, with the classic differential mix: left = forward + turn, right = forward − turn. Push the stick diagonally and one wheel simply runs faster than the other, so the car sweeps through a curve instead of pivoting. The sign of each result decides that wheel's direction, and its magnitude becomes the PWM value, this is Cartesian mapping, turning an (x, y) point into two motor commands.
Stick centred: both powers read 0 and the car sits still. Stick fully forward: L: 255 R: 255 and it runs straight. Stick forward-right: L: 255 R: 75 and it sweeps through a curve.
Yes. It is project 43 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_43_joystick_car.ino).
About ₹1,198 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Analog Cartesian mapping; Differential drive mixing; Turning a signed value into direction plus PWM; Why constrain() matters when two values are added.
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.
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.