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 componentsTwo Unos, two radios. The controller reads the joystick and sends a tiny packet 25 times a second; the car mixes throttle and steering into left and right wheel speeds. If the controller goes quiet for half a second, the car stops. Button A gives a slow mode for tight spaces. Range is 20–30 m indoors.
Tick anything you already have and the total updates.
The brain of the project; Second Uno, on the car
Connects the Uno to your computer to upload code and power it
Plug-on shield with a two-axis thumb joystick, four big buttons and sockets for nRF24L01 and Bluetooth modules.
2.4 GHz radio transceiver for short messages between two boards, up to about 30 m indoors.; Radio on the car
Raises the cell's 3.0–4.2 V to a steady 5 V for the board
Follow the colours: red is power, dark grey is ground, blue is a signal.
Set the boost converter to 5.0 V with a multimeter before connecting the board. Cell + → boost IN+, cell − (TP4056 OUT−) → boost IN−, then boost OUT+ → board 5V pin and OUT− → GND. A bare 18650 (3.0–4.2 V) cannot run a 5 V board by itself.
nrf24_joystick_rc_car.inoVerify & upload in Electrolark// Radio-controlled car with nRF24 and a joystick shield
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "nrf24-joystick-rc-car"
#include <SPI.h>
#include <RF24.h>
// ---- pins ----
const uint8_t JOY_X = A0;
const uint8_t JOY_Y = A1;
const uint8_t JOY_BTN = 8;
const uint8_t BTN_A = 2;
const uint8_t BTN_B = 3;
const uint8_t BTN_C = 4;
const uint8_t BTN_D = 5;
const uint8_t RADIO_CE = 9;
const uint8_t RADIO_CSN = 10;
const int ADC_MAX = 1023; // 10-bit analog input
const float VREF = 5.0f;
RF24 radio(RADIO_CE, RADIO_CSN);
const byte ADDRESS[6] = "OLDB1";
// ---- latest readings ----
int joyX = 0;
int joyY = 0;
struct Packet { int8_t x; int8_t y; uint8_t buttons; };
unsigned long lastSend = 0;
void setup() {
Serial.begin(115200);
pinMode(JOY_BTN, INPUT_PULLUP); pinMode(BTN_A, INPUT_PULLUP); pinMode(BTN_B, INPUT_PULLUP);
pinMode(BTN_C, INPUT_PULLUP); pinMode(BTN_D, INPUT_PULLUP);
if (!radio.begin()) Serial.println(F("nRF24 not found"));
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(ADDRESS);
radio.stopListening();
}
void loop() {
if (millis() - lastSend < 40) return; // 25 packets a second
lastSend = millis();
Packet p;
int x = map(analogRead(JOY_X), 0, ADC_MAX, -100, 100), y = map(analogRead(JOY_Y), 0, ADC_MAX, -100, 100);
p.x = abs(x) < 8 ? 0 : x; p.y = abs(y) < 8 ? 0 : y; // dead zone
p.buttons = (digitalRead(BTN_A) == LOW ? 1 : 0) | (digitalRead(BTN_B) == LOW ? 2 : 0);
bool ok = radio.write(&p, sizeof(p));
Serial.print(p.x); Serial.print(' '); Serial.print(p.y); Serial.println(ok ? F(" sent") : F(" no ack"));
}
The sketch above runs here on a simulated Arduino Uno. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
rc_car_receiver.inoVerify & upload in Electrolark// nRF24 joystick RC car: RECEIVER (goes on the car)
// Geekobot project library · board: Arduino Uno
#include <SPI.h>
#include <RF24.h>
// ---- pins ----
const uint8_t RADIO_CE = 9, RADIO_CSN = 10; // nRF24L01 CE and CSN (SCK 13, MOSI 11, MISO 12)
const uint8_t ENA = 5, IN1 = 7, IN2 = 8, IN3 = 4, IN4 = 2, ENB = 6; // L298N
RF24 radio(RADIO_CE, RADIO_CSN);
const byte ADDRESS[6] = "OLDB1";
struct Packet { int8_t x; int8_t y; uint8_t buttons; };
unsigned long lastPacket = 0;
const unsigned long FAILSAFE_MS = 500; // stop if the transmitter goes quiet
// speed: -255 (full reverse) to 255 (full forward)
void drive(int left, int right) {
digitalWrite(IN1, left >= 0 ? HIGH : LOW); digitalWrite(IN2, left >= 0 ? LOW : HIGH);
analogWrite(ENA, constrain(abs(left), 0, 255));
digitalWrite(IN3, right >= 0 ? HIGH : LOW); digitalWrite(IN4, right >= 0 ? LOW : HIGH);
analogWrite(ENB, constrain(abs(right), 0, 255));
}
void setup() {
Serial.begin(115200);
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
drive(0, 0);
if (!radio.begin()) Serial.println(F("nRF24 not found"));
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, ADDRESS);
radio.startListening();
}
void loop() {
if (radio.available()) {
Packet p; radio.read(&p, sizeof(p));
lastPacket = millis();
int throttle = (int)p.y * 255 / 100; // forward/back
int steer = (int)p.x * 255 / 100; // left/right
int left = constrain(throttle + steer, -255, 255), right = constrain(throttle - steer, -255, 255);
if (p.buttons & 1) { left /= 2; right /= 2; } // button A: slow mode
drive(left, right);
}
if (millis() - lastPacket > FAILSAFE_MS) drive(0, 0);
}
The shield voltage switch is on 3.3 V; set it to 5 V for the Uno.
Add the 10 µF capacitor, check both sketches use the same ADDRESS, and keep the boards at least 1 m apart.
Open the Serial Monitor at 115200 baud and check for messages. Make sure you chose the right board and port in the Arduino IDE.
Close other programs using the serial port, try another USB cable (some are charge-only) and press reset just before uploading.
Yes. Most of the code works unchanged on an ESP32 with the ESP32 board package. Watch for 5 V modules: ESP32 pins are 3.3 V, so 5 V output signals need a resistor divider. Analog readings run 0–4095 instead of 0–1023, which the ADC_MAX constant handles.
Use a 5 V USB phone charger or a power bank into the board's USB port. Loads such as pumps, fans and solenoids need their own supply.
12 parts: 2 × Uno R3 CH340G ATmega328p Compatible Development Board, 2 × Arduino USB-A to USB-B Data Cable for UNO/MEGA, Joystick Shield for Arduino Robotics & Game Control, 2 × NRF24L01 2.4GHz Wireless Transceiver Module, Electrolytic Capacitor, L298N Dual H-Bridge Motor Driver Module, 2WD Smart Robot Car Chassis Kit, 2 × 18650 Battery Holder, 2 × 18650 Li-ion Rechargeable Cell 2600mAh, MT3608 Mini Boost Converter Module, plus 2 more. Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 4–5 hours. The build on this page has 8 steps.
No. This page has the complete, tested code (nrf24_joystick_rc_car.ino and rc_car_receiver.ino). Install this library first: RF24.
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹1,656 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Analog joysticks and shields; Packet radio and addresses.
Ideas that reuse this build: Bluetooth phone version and Wireless doorbell. They are listed under Take it further on this page.
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.
-40 -39 sent -39 -40 sent -39 -39 sent -39 -40 sent -39 -40 sent -39 -40 sent -39 -39 sent -39 -39 sent -39 -39 sent
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.