Learning Goal
The goal of this project is to introduce students to robotics, movement, and intelligent decision-making. Learners will build a robot car that uses sensors to detect and avoid obstacles automatically. This project teaches programming logic, motor control, and problem-solving through hands-on learning. By connecting the robot to real vehicles and robots seen in daily life, students understand how machines navigate safely. The project builds teamwork, creativity, and confidence while laying a strong foundation for robotics, automation, and future AI-based systems.
What You will Need
| Component | Purpose |
|---|---|
| Arduino Uno R4 WiFi | Brain of the robot car |
| L298N Motor Driver Module | Controls motor direction and speed |
| DC Motors (2) | Move the robot car |
| Robot Car Chassis + Wheels | Holds all components |
| Ultrasonic Sensor (HC-SR04) | Detects obstacles |
| Battery Pack (6–12V) | Powers motors |
| Breadboard | Connects low-power components |
| Jumper Wires | Electrical connections |
| USB Cable | Programs the Arduino |
Understand the Circuit
Follow these steps carefully. This section explains exactly what connects to what.
1. Power Connections
⚠️ Motors must use a separate battery.
Connect Arduino GND to L298N GND (common ground).
Connect battery positive (+) to L298N +12V.
Connect battery negative (–) to L298N GND.
Keep Arduino powered via USB or regulated 5V.
2. Connecting the DC Motors to L298N
Connect Left Motor wires to OUT1 and OUT2 on L298N.
Connect Right Motor wires to OUT3 and OUT4 on L298N.
👉 Motor direction depends on polarity; reverse wires if needed.
3. Connecting L298N Control Pins to Arduino
Remove the EN jumper caps to control speed via Arduino.
ENA → Arduino pin 5 (PWM – speed control for left motor)
IN1 → Arduino pin 8
IN2 → Arduino pin 9
IN3 → Arduino pin 10
IN4 → Arduino pin 11
ENB → Arduino pin 6 (PWM – speed control for right motor)
4. Connecting the Ultrasonic Sensor (HC-SR04)
VCC → Arduino 5V
GND → Arduino GND
TRIG → Arduino pin 2
ECHO → Arduino pin 3
👉 This sensor measures distance to obstacles in front of the car.
Circuit Diagram With Breadboard
Circuit Diagram Without Breadboard
The Project Code
// Ultrasonic pins
int trigPin = 2;
int echoPin = 3;
// Motor driver pins
int ENA = 5;
int ENB = 6;
int IN1 = 8;
int IN2 = 9;
int IN3 = 10;
int IN4 = 11;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
}
void loop() {
distance = getDistance();
if (distance > 20) {
moveForward();
} else {
stopCar();
delay(300);
turnRight();
delay(400);
}
}
int getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2;
}
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void turnRight() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void stopCar() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
Uploading the Code
Understand the Code
| Code Section | What It Does |
|---|---|
| Ultrasonic setup | Measures distance to obstacles |
| Motor pin setup | Controls direction and speed |
getDistance() | Calculates obstacle distance |
moveForward() | Moves robot straight |
turnRight() | Avoids obstacles |
stopCar() | Stops movement |
Troubleshooting the code
Robot not moving
Check motor power and battery
Ensure ENA/ENB jumpers removed
Robot moves backward
Swap motor wires
Robot hits obstacles
Increase distance threshold
Motors run unevenly
Adjust PWM values
What You Have Learned
How robots sense their environment
How motor drivers control movement
How algorithms guide robot behavior
Basics of autonomous systems
Teamwork, debugging, and engineering thinking
Extra Challenge
Add LED eyes that react to obstacles
Add a servo-mounted ultrasonic sensor
Control speed based on distance
Use WiFi to control robot remotely
Build a maze and test navigation
AI Extensions
AI Type: TinyML + Autonomous Intelligence
AI Extension 1: Smart Navigation AI
Train AI to learn best turning directions
Improves obstacle avoidance over time
Introduces reinforcement learning concepts
AI Extension 2: Object Classification
Use camera + AI
Recognize walls, people, or boxes
Decide different actions for each object
AI Extension 3: Behavior Learning Dashboard
Send movement data via WiFi
AI analyzes paths and mistakes
Students visualize robot learning progress
👉 Younger learners focus on behavior; older learners train and analyze models.
