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 componentsThe MPU6050 on the back of a glove measures how your hand tilts. Forward tilt becomes throttle and sideways tilt becomes steering, sent over the nRF24 radio in the same packet as the joystick remote, so the car runs the same receiver sketch. Hold your hand level and the car stops; hold the button for slow mode.
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
Six-axis motion sensor: a three-axis accelerometer that feels gravity and bumps, and a three-axis gyro that measures how fast it turns.
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.
tilt_glove_rc_car.inoVerify & upload in Electrolark// Tilt-glove remote for the nRF24 RC car
// Geekobot project library · board: Arduino Uno
// Wiring diagram, parts list and build steps: Geekobot project page "tilt-glove-rc-car"
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <RF24.h>
// ---- pins ----
const uint8_t RADIO_CE = 9;
const uint8_t RADIO_CSN = 10;
const uint8_t BUTTON_PIN = 2;
Adafruit_MPU6050 mpu;
sensors_event_t accEvt, gyrEvt, tmpEvt;
RF24 radio(RADIO_CE, RADIO_CSN);
const byte ADDRESS[6] = "OLDB1";
// ---- latest readings ----
float pitchDeg = 0;
float rollDeg = 0;
float shakeG = 0;
struct Packet { int8_t x; int8_t y; uint8_t buttons; }; // same packet as the joystick controller, so the same car code works
const float MAX_TILT = 35; // degrees of tilt for full speed
unsigned long lastSend = 0;
void readImu() { mpu.getEvent(&accEvt, &gyrEvt, &tmpEvt); }
float pitchDegNow() { return atan2(accEvt.acceleration.x, sqrt(accEvt.acceleration.y * accEvt.acceleration.y + accEvt.acceleration.z * accEvt.acceleration.z)) * 57.3f; }
float rollDegNow() { return atan2(accEvt.acceleration.y, accEvt.acceleration.z) * 57.3f; }
float shakeGNow() { float a = sqrt(accEvt.acceleration.x * accEvt.acceleration.x + accEvt.acceleration.y * accEvt.acceleration.y + accEvt.acceleration.z * accEvt.acceleration.z) / 9.81f; return fabs(a - 1.0f); }
float gyroZNow() { return gyrEvt.gyro.z * 57.3f; } // turning speed in degrees per second
void setup() {
Serial.begin(115200);
if (!mpu.begin()) Serial.println(F("MPU6050 not found"));
mpu.setAccelerometerRange(MPU6050_RANGE_4_G);
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
pinMode(BUTTON_PIN, 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();
pitchDeg = (readImu(), pitchDegNow());
rollDeg = rollDegNow();
Packet p;
int x = constrain(rollDeg / MAX_TILT * 100, -100, 100), y = constrain(-pitchDeg / MAX_TILT * 100, -100, 100);
p.x = abs(x) < 12 ? 0 : x; p.y = abs(y) < 12 ? 0 : y; // hold the hand level to stop
p.buttons = digitalRead(BUTTON_PIN) == LOW ? 1 : 0; // hold the button for slow mode
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);
}
Check SDA and SCL are not swapped. An I²C scanner should show 0x68 (0x69 if AD0 is tied high).
Keep I²C wires short, add a 100 nF capacitor across VCC and GND, and mount the board away from motor wires.
Add the 10 µF capacitor, check both sketches use the same ADDRESS, and keep the boards at least 1 m apart.
The button is rotated 90°; legs on the same side are already connected. Turn it.
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.
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.
13 parts: 2 × Uno R3 CH340G ATmega328p Compatible Development Board, 2 × Arduino USB-A to USB-B Data Cable for UNO/MEGA, GY-521 MPU6050 6-Axis Gyro and Accelerometer Module, 2 × NRF24L01 2.4GHz Wireless Transceiver Module, Tactile Push Button Switch, 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, plus 3 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 10 steps.
No. This page has the complete, tested code (tilt_glove_rc_car.ino and rc_car_receiver.ino). Install these libraries first: Adafruit MPU6050, Adafruit Unified Sensor and 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,715 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.
Accelerometers, gyros and tilt angles; Packet radio and addresses; Pull-ups and debouncing.
Ideas that reuse this build: Joystick RC car and Bluetooth RC car. 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.
0 0 sent 0 0 sent 0 0 sent 0 0 sent 0 0 sent 0 0 sent 0 0 sent 0 0 sent 0 0 sent
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.