Building your first robot car with Arduino is one of the most satisfying DIY electronics projects you can tackle. You start with a pile of parts and end up with a programmable wheeled robot that you fully understand and can extend in many directions. This step-by-step guide takes you from an empty workbench to a moving robot, then adds Bluetooth control and ultrasonic obstacle avoidance.
Table of Contents
Parts List
Before you start, gather all the parts. Here is everything you need for a complete 4WD robot car with Bluetooth and obstacle avoidance:
- 1x 4WD robot car chassis kit (with 4 BO motors and wheels)
- 1x Arduino Uno R3 (or clone)
- 1x L298N dual H-bridge motor driver module
- 1x HC-05 Bluetooth module
- 1x HC-SR04 ultrasonic distance sensor
- 1x 18650 battery holder (2S, 7.4V) or 4x AA battery pack (6V)
- Jumper wires (male-male, male-female)
- Small screwdrivers, zip ties, double-sided tape
- USB cable for programming
Step 1: Chassis Assembly
The chassis is the physical frame of your robot. For a 4WD chassis kit:
- Identify the two acrylic platform layers and the metal motor mounts.
- Attach all four BO motors to the motor mounts using the M3 screws provided. Make sure all motors face the correct direction (shaft outward).
- Press the rubber wheels onto each motor shaft. They should fit snugly.
- Bolt the upper and lower acrylic platforms together using the supplied standoffs.
- Mount the Arduino Uno and L298N on the upper layer using double-sided foam tape or nylon standoffs.
- Mount the battery holder at the bottom layer for lower centre of gravity.
For a 2WD chassis, the process is similar but you only attach two motors plus a ball caster at the front or rear for balance. Either configuration works well for a beginner robot car.
Step 2: Motor and L298N Wiring
The L298N motor driver is an H-bridge IC that allows you to control the speed and direction of two DC motors. Here is how to wire it:
Motor Connections
- OUT1 and OUT2: Left motor (or left pair of motors in parallel)
- OUT3 and OUT4: Right motor (or right pair)
For a 4WD chassis, wire the two left motors in parallel to OUT1/OUT2, and the two right motors in parallel to OUT3/OUT4. Connect positive to one output and negative to the other — which way determines forward direction (you can swap if the motor runs backwards).
Arduino to L298N Control Pins
- IN1 → Arduino Pin 2
- IN2 → Arduino Pin 3
- IN3 → Arduino Pin 4
- IN4 → Arduino Pin 5
- ENA (Enable A) → Arduino Pin 6 (PWM)
- ENB (Enable B) → Arduino Pin 7 (PWM) — or use Pin 9/10 for PWM
Power Connections
- 12V terminal on L298N → Battery positive (7.4V–12V)
- GND on L298N → Battery negative (and also connect to Arduino GND)
- 5V output on L298N → Arduino 5V pin (only if L298N 5V jumper is present and battery is 7–12V)
Important: Always connect Arduino GND to L298N GND, otherwise signals will not be referenced correctly and the motors will behave erratically.
Step 3: Basic Movement Code
Upload this sketch to your Arduino to test forward, backward, left, and right movement:
// Robot Car - Basic Movement
// L298N motor driver, 4WD chassis
// Left motor
const int IN1 = 2;
const int IN2 = 3;
const int ENA = 6;
// Right motor
const int IN3 = 4;
const int IN4 = 5;
const int ENB = 9;
int motorSpeed = 180; // 0-255
void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
}
void moveForward() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void moveBackward() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void turnLeft() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH); // Left motors reverse
digitalWrite(IN3, HIGH); // Right motors forward
digitalWrite(IN4, LOW);
}
void turnRight() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); // Left motors forward
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); // Right motors reverse
digitalWrite(IN4, HIGH);
}
void stopMotors() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void loop() {
moveForward(); delay(2000);
stopMotors(); delay(500);
moveBackward(); delay(2000);
stopMotors(); delay(500);
turnLeft(); delay(600);
stopMotors(); delay(500);
turnRight(); delay(600);
stopMotors(); delay(1000);
}
Adjust motorSpeed (0–255) to change how fast the robot moves. If a motor runs in the wrong direction, simply swap the two wires on that motor at the L298N output terminals.
Step 4: Adding Bluetooth Control with HC-05
The HC-05 Bluetooth module lets you control the robot from your Android phone using a free Bluetooth RC app. Wiring:
- HC-05 VCC → 5V (Arduino 5V or L298N 5V)
- HC-05 GND → GND
- HC-05 TXD → Arduino Pin 10 (SoftwareSerial RX)
- HC-05 RXD → 1kΩ voltage divider to Arduino Pin 11 (SoftSerial TX at 3.3V logic)
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); // RX, TX
// (Include all motor pin definitions from previous sketch)
void setup() {
// ... pin modes same as before
BT.begin(9600);
}
void loop() {
if (BT.available()) {
char cmd = BT.read();
switch(cmd) {
case 'F': moveForward(); break;
case 'B': moveBackward(); break;
case 'L': turnLeft(); break;
case 'R': turnRight(); break;
case 'S': stopMotors(); break;
}
}
}
Pair your phone to HC-05 (default password: 1234 or 0000), then use any Bluetooth RC car app that sends F/B/L/R/S commands.
Step 5: Obstacle Avoidance with HC-SR04
Mount the HC-SR04 sensor at the front of the chassis facing forward. Wiring:
- VCC → 5V
- GND → GND
- TRIG → Arduino Pin 12
- ECHO → Arduino Pin 13
const int TRIG = 12;
const int ECHO = 13;
long getDistance() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long duration = pulseIn(ECHO, HIGH);
return duration * 0.034 / 2; // cm
}
void loop() {
long dist = getDistance();
if (dist > 20) {
moveForward();
} else {
stopMotors();
delay(300);
moveBackward();
delay(400);
turnRight();
delay(500);
}
delay(50);
}
The robot now moves forward until it detects an obstacle within 20cm, then backs up and turns right to navigate around it.
Next Steps: Taking Your Robot Car Further
Once your basic robot is working, here are the most popular upgrades:
- Line Following: Add IR line sensor modules (TCRT5000) below the chassis and write a PID-based line follower.
- Smartphone App Control: Build a custom app using MIT App Inventor that sends directional commands over Bluetooth.
- Servo-Mounted Sensor: Put the HC-SR04 on a servo and sweep it left-right to map obstacles before choosing a direction.
- WiFi Control: Replace the Arduino Uno with an ESP8266 or ESP32 for web-based control over WiFi.
- Camera: Add an ESP32-CAM for live video streaming from the robot’s perspective.
Frequently Asked Questions
Q: Can I use just 4 AA batteries to power the robot?
Yes, 4 AA batteries give about 6V which is enough for the BO motors. However, alkaline AAs drop voltage quickly under load. Rechargeable NiMH AAs (2500mAh) last longer. For best performance, use 2 x 18650 Li-ion cells (7.4V) in a battery holder — they provide steady voltage and are rechargeable.
Q: My robot turns in circles instead of going straight. Why?
Motor mismatch is the most common cause. Left and right motors may spin at slightly different speeds even at the same PWM value. Calibrate by adjusting the ENA/ENB PWM values independently until the robot tracks straight on a flat surface.
Q: Can I replace the Arduino Uno with an Arduino Nano?
Yes. The Arduino Nano is smaller and lighter, which is ideal for a robot chassis. The pin numbers and code are identical. Just note that the Nano uses a Mini-USB or Micro-USB connector depending on the version.
Q: What is the maximum load the L298N can handle?
The L298N chip is rated for 2A per channel (4A total), but it runs hot above 1.5A per channel. For heavier robots or faster motors drawing more current, upgrade to the Cytron MD10C or a DRV8833-based module for better efficiency and thermal performance.
Q: Is this project suitable for school or college project submission?
Absolutely. An obstacle-avoiding Arduino robot car is a great mini-project for school science fairs, engineering college lab submissions, and workshops. You can extend it further with a 16×2 LCD showing sensor readings, a buzzer for alerts, or an OLED displaying live distance data.
Get Your Robot Car Parts at Zbotic.in
Zbotic.in stocks Arduino boards, L298N motor drivers, robot chassis kits, Bluetooth modules, and all the parts you need to build your robot car, with fast delivery across India.
Add comment