Class 12 computer science exhibition

Obstacle Avoidance Car

A car that sees before it moves.

An autonomous two-wheel drive robot powered by an Arduino Uno that scans its surroundings using high-frequency 40 kHz ultrasonic sonar pulses to navigate around obstacles in real time.

Credits: Tijil Das, Shreyam Chaudhury, Shreyas Chatterjee, Shaurya Gupta, class 12 science, St. Aloysius School.
.car.png 16:9
Obstacle Avoidance Car

Demo video

Autonomous obstacle avoidance demonstration with ultrasonic pulse ranging and active servo radar scanning.

HLS stream: .mp4/index.m3u8 720p 24fps
Adaptive bitrate HLS streaming HC-SR04 sonar telemetry

How the car works

An engineering summary of acoustic ranging physics, servo kinematics, motor drive electronics, and autonomous decision logic.

Subsystem Hardware component Interface Operating value
Microcontroller Arduino Uno R3 (ATmega328P) Pins 4–10, 5V / Vin 16 MHz
Acoustic sensor HC-SR04 ultrasonic module TRIG pin 9, ECHO pin 8 40 kHz
Scanning actuator TowerPro SG90 micro servo PWM pin 10 0° to 180°
Motor controller L298N dual H-bridge Pins 7, 6 (Right), Pins 5, 4 (Left) 2A peak
Power supply 9V DC battery pack Isolated rail, common ground 9V / 5V

1. Ultrasonic sonar physics

The HC-SR04 emits an inaudible 40 kHz acoustic burst when triggered by a 10 µs HIGH pulse on pin 9. Sound travels through air at approximately 340 m/s (29.1 µs/cm).

The sensor measures round-trip flight duration on pin 8. The Arduino calculates one-way distance:

distance = duration / 58.2; // cm

2. Active radar sweep and motor drive

The HC-SR04 sensor has a narrow beam angle of approximately 15°. Mounting it to an SG90 servo allows an active 180° radar sweep across right (0°), center (90°), and left (180°) positions to identify open escape trajectories.

The L298N motor driver converts low-power logic signals into high-current polarity switching for the two geared motors. Motor power is decoupled from the Arduino logic rail with a shared common ground to eliminate inductive brownout resets.

Autonomous control loop

Condition 1: clear path distance > 15 cm

Servo centers at 90°. Both motors drive forward (MRb=HIGH, MLb=HIGH). Continuous cruise speed.

Condition 2: hysteresis buffer zone 10 cm ≤ distance ≤ 15 cm

Maintains current motion state to prevent oscillation (flip-flopping) caused by acoustic measurement jitter.

Condition 3: obstacle avoidance routine 0 < distance < 10 cm

1. Stop all motors (100 ms).
2. Sweep servo across 0° (right), 180° (left), and 90° (center) at 500 ms intervals.
3. Drive backward for 500 ms.
4. Stop for 100 ms.
5. Pivot turn left for 500 ms.
6. Re-evaluate distance in the next loop cycle.

Think about them

Six questions exploring acoustics, thermodynamics, sensor blind zones, and motor control edge cases.

1 Question 1

1. On a hot day, will the car misjudge a 50 cm obstacle as nearer or farther?

Nearer. Sound travels faster in hot air, so the echo returns sooner. The code assumes a fixed speed of sound, so it calculates a shorter distance. The error is small (a cm or two), but it is always in the “too close” direction.

2 Question 2

2. The car reverses with no rear sensor. What could go wrong?

The sensor faces forward, so the car backs up blind. It can hit a wall, a person’s foot or another robot behind it. The fix is a rear sensor, or only reversing for a short, safe distance.

3 Question 3

3. Why is “turn for 500 ms” an unreliable way to turn a fixed angle?

Time isn’t angle. As the battery drains, the motors slow down and the car turns less. Floor grip, wheel slip and uneven motors also change the result. Encoders on the wheels or a gyroscope measure the actual turn instead of guessing it.

4 Question 4

4. What happens if you add two more sensors and fire them together?

They interfere, because each sensor hears the others’ pings and echoes. This is the same “phantom obstacle” problem as Quiz Q2. The fix is to fire them one at a time, with a short pause between, so each one only listens for its own echo.

5 Question 5

5. Why does the code check distance > 0 as well as < 10?

When no echo comes back (nothing in range, or the echo is lost), the timing function typically returns 0, which turns into a distance of 0 cm. Without > 0, the car would treat that as an obstacle right in front of it and stop for nothing.

6 Question 6

6. Why might the car miss an obstacle only 1 cm away?

The HC-SR04 has a blind zone: it can’t measure very short distances (its minimum is around 2 cm). The echo returns while the sensor is still finishing its own ping, so it can’t tell them apart. Objects that close are effectively invisible to it.

Assets

Project files in Website/Assets. Click anywhere on an asset row to view, or Download to save the file.

Asset name Filename Format Actions

Visitor feedback

If your have explored our project or have visited the exhibition at St. Aloysius School on 6th Nov, 2026, please leave a feedback.