Satpuda STEM Lab · Curriculum Day 4 Capstone · Monday, 23 November 2026

Capstone: Autonomous Radar Obstacle-Avoiding Smart Car

Complete integration of SG90 mini servo scanning radar, HC-SR04 ultrasonic distance telemetry, look-ahead path decision matrix, and dead-end escape algorithms.

Roadmap: 🚗 Day 1: Motors & Power 🛠️ Day 2: Chassis Assembly 🎮 Day 3: Serial & RC Driving 📡 Day 4: Autonomous Radar

1. 🎯 Capstone Robotics Objective

The final capstone milestone of the 4-Day Robotics Workshop equips the robot car with full autonomy. Without any human steering or remote control, the vehicle drives forward continuously, scans the environment using an electronic radar turret, evaluates path clearance, and automatically decides the optimal evasion path around obstacles.

2. 🔌 Complete Hardware Architecture & Radar Turret Wiring

+-------------------------------------------------------------------------------+ | CONNECT ROBO CAPSTONE: AUTONOMOUS RADAR SMART CAR ARCHITECTURE | +-------------------------------------------------------------------------------+ [ HC-SR04 ULTRASONIC SENSOR ] | VCC TRIG ECHO GND | +----+-----+------+------+--+ | | | | | | | +--------+ | | +----+ | | +----+ | | | | | | | [ SG90 SERVO MOTOR ] | | | VCC GND SIG(PWM) | | | +--+----+----+-------+ | | | | | | v v v v v +-----+--------+----+----+---------+-----+ | 5V 5V GND Pin10 PinA1 PinA2 | | | | ARDUINO UNO R3 | | | | Pin5(ENA) Pin7(IN1) Pin8(IN2) | | Pin6(ENB) Pin11(IN3) Pin12(IN4) | | Pin4(BUZZER) | | GND -----------------------------+ | +---+--------------------------------+---+ | | PWM Motor Lines | | Common GND v v +-----------------------------------------------------+ | L298N DUAL H-BRIDGE | | | | [OUT1 OUT2] [OUT3 OUT4] | | (Left Motor) (Right Motor) | | | | ENA IN1 IN2 IN3 IN4 ENB +12V GND +5V | +---+-----+-----+-----+-----+-----+-----+---+----+----+ | | Switch (+) | | Battery (-) +----+ | | | [ SWITCH ] | | | +------+---------+------+ | 2x 18650 LI-ION | | PACK (7.4V) | +-----------------------+
Module / Component Module Pin Arduino Pin Wiring Function & Architecture Description
L298N Left Speed ENA Pin 5 (Timer 0 PWM) Left Motor Speed PWM throttle; remove jumper cap
L298N Right Speed ENB Pin 6 (Timer 0 PWM) Right Motor Speed PWM throttle; remove jumper cap
L298N Direction Left IN1, IN2 Pin 7, Pin 8 Left Motor Direction logic gates
L298N Direction Right IN3, IN4 Pin 11, Pin 12 Right Motor Direction logic gates
SG90 Mini Servo Signal (Orange) Pin 10 Servo PWM Pulse from <Servo.h> (Timer 1)
SG90 Mini Servo Power (Red / Brown) 5V & GND Servo 5V power supply & ground reference
HC-SR04 Ultrasonic TRIG Pin A1 (Digital 15) 10µs ultrasonic ping pulse generator
HC-SR04 Ultrasonic ECHO Pin A2 (Digital 16) Echo return pulse duration reader
Active Buzzer Positive (+) Pin 4 Alert horn / detection beep indicator
Battery Ground Negative (−) L298N GND & Uno GND MANDATORY: Common Ground Junction!

3. 🌟 The 5 Golden Rules of Autonomous Robotics

⏱️ Golden Rule 1: Timer 0 vs. Timer 1 Hardware Isolation

On ATmega328P (Arduino Uno), the <Servo.h> library commandeers Timer 1 to generate precise servo PPM pulses. Using Timer 1 disables hardware PWM on Pins 9 & 10! Therefore, in our autonomous architecture, motor PWM is routed to Pins 5 & 6 (Timer 0), ensuring both servo sweeps and motor speed control function simultaneously without glitching.

🎯 Golden Rule 2: Electronic 90° Center Calibration Before Assembly

Before fastening the ultrasonic bracket to the servo horn, upload a test sketch or power on the servo while running radarServo.write(90);. Once the servo gear rotates to its true electronic center, press the bracket onto the gear splines facing dead straight ahead and screw the M2 center screw. This ensures 160° = Left, 90° = Center, and 20° = Right.

📏 Golden Rule 3: HC-SR04 Pulse Timeout Guard (Zero Blocking)

Sound travels at ~343 m/s (~29.1 µs/cm). Standard pulseIn(ECHO, HIGH) waits up to 1,000,000 µs (1 full second) if no echo returns! In autonomous driving, a 1-second freeze causes crashes. Our firmware sets a strict 30,000 µs timeout (max ~5 meters), keeping loop response lightning fast.

🧠 Golden Rule 4: Look-Ahead Dual Scan & Dead-End 180° Spin Escape

When an obstacle is detected within 25cm ahead, the car brakes immediately, beeps, rotates the servo left (160°) to measure distance, then right (20°) to measure distance. It steers toward whichever side has greater clearance. If both left and right are blocked (< 20cm), it backs up and performs a full 180° spin turn to escape dead-ends!

🔋 Golden Rule 5: Low-Battery Voltage Drop Prevention

A servo motor and two DC gear motors active simultaneously can draw up to 1.8 Amperes during aggressive turns. If your 18650 batteries are nearly depleted, the voltage will sag below 4.5V, causing the Arduino to reboot in a continuous loop. Always use fully charged 3.7V Li-ion cells.

4. 📋 10-Point Student Autonomous Flight-Check

Checklist Completion: 0 / 10 (0%)
1. Timer 0 Pins: ENA on Pin 5; ENB on Pin 6 (ensures PWM works with Servo library).
2. Motor Direction Pins: IN1→7, IN2→8, IN3→11, IN4→12 wired and tightened.
3. Servo Pin: SG90 orange signal wire plugged into Pin 10.
4. Ultrasonic Pins: TRIG on Pin A1 (D15); ECHO on Pin A2 (D16).
5. Common Ground: Battery (−), L298N GND, and Arduino GND firmly tied together.
6. Horn Check: Active buzzer plugged into Pin 4 for alert beeps.
7. 90° Horn Alignment: Ultrasonic sensor faces directly forward when servo is at 90°.
8. Wire Clearance: Jumper wires bundled with zip-ties so they do not catch on the rotating servo arm or wheels.
9. Bench Test: Robot car supported on a stand; verify wheels spin forward and stop when hand is placed 20cm ahead.
10. Floor Navigation: Place robot car in an open area with boxes or books and observe autonomous pathfinding!
🚀 100% PRE-FLIGHT CLEARANCE VERIFIED! All hardware connections confirmed. Flip Battery Switch ON!

5. 💻 Verified Autonomous Capstone Firmware

Sketch: AUTONOMOUS_RADAR_OBSTACLE_CAR.ino (Autonomous Scanning Radar Robot Car)
/*
 * Connect Robo - Autonomous Radar Obstacle-Avoiding Smart Car
 * Workshop: Satpuda STEM Lab Day 4 Capstone (23 Nov 2026)
 * Target: Arduino Uno (ATmega328P) | Baud: 115200 bps
 * Features: SG90 Servo Scanning Radar, HC-SR04 Rangefinder,
 *           Look-Ahead Decision Matrix & Dead-End 180-Degree Escape
 */

#include <Servo.h>

// Motor Pin Allocation (Pins 5 & 6 for Timer 0 PWM)
const int ENA = 5, IN1 = 7, IN2 = 8, IN3 = 11, IN4 = 12, ENB = 6;
const int SERVO_PIN = 10, TRIG_PIN = A1, ECHO_PIN = A2, BUZZER = 4;
const int SAFE_DIST_CM = 25, CRUISE_SPEED = 180, TURN_SPEED = 195;

Servo radarServo;

long readDistanceCM() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  
  // 30ms timeout prevents blocking if no echo returns
  long duration = pulseIn(ECHO_PIN, HIGH, 30000);
  if (duration == 0) return 300; // No obstacle detected (clear path)
  return duration / 58;          // Convert microseconds to centimeters
}

void setup() {
  Serial.begin(115200);
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENB, OUTPUT);
  pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER, OUTPUT);

  // Attach servo and calibrate to 90 degrees center
  radarServo.attach(SERVO_PIN);
  radarServo.write(90);
  stopMotors();

  // Startup chirp
  digitalWrite(BUZZER, HIGH); delay(100); digitalWrite(BUZZER, LOW);
  delay(1000);

  Serial.println(F("=================================================="));
  Serial.println(F("🤖 Connect Robo Autonomous Radar Car Initialized!"));
  Serial.println(F("Cruising forward with look-ahead radar obstacle evasion..."));
  Serial.println(F("=================================================="));
}

void loop() {
  radarServo.write(90); // Look straight ahead
  long frontDist = readDistanceCM();
  Serial.print(F("[RADAR] Front Distance: ")); Serial.print(frontDist); Serial.println(F(" cm"));

  if (frontDist > SAFE_DIST_CM) {
    // Clear path ahead - cruise forward
    moveForward();
    delay(60);
  } else {
    // Obstacle detected! Execute evasion maneuver
    stopMotors();
    alertBeep();
    Serial.println(F("[ALERT] Obstacle ahead! Initiating radar sweep..."));

    // Step 1: Scan Left (160 degrees)
    radarServo.write(160);
    delay(350);
    long leftDist = readDistanceCM();
    Serial.print(F("[RADAR] Left Clearance: ")); Serial.print(leftDist); Serial.println(F(" cm"));

    // Step 2: Scan Right (20 degrees)
    radarServo.write(20);
    delay(400);
    long rightDist = readDistanceCM();
    Serial.print(F("[RADAR] Right Clearance: ")); Serial.print(rightDist); Serial.println(F(" cm"));

    // Step 3: Return radar to center
    radarServo.write(90);
    delay(150);

    // Step 4: Look-Ahead Decision Matrix
    if (leftDist <= 18 && rightDist <= 18) {
      // Dead-End Trap! Reverse and perform 180-degree spin escape
      Serial.println(F("[DECISION] Dead-end detected! Reversing & executing 180-deg spin escape"));
      moveBackward();
      delay(700);
      spinLeft();
      delay(900);
      stopMotors();
    } else if (leftDist >= rightDist) {
      // Left path has greater clearance - steer left
      Serial.println(F("[DECISION] Left path clearer → Executing Left Turn"));
      spinLeft();
      delay(450);
      stopMotors();
    } else {
      // Right path has greater clearance - steer right
      Serial.println(F("[DECISION] Right path clearer → Executing Right Turn"));
      spinRight();
      delay(450);
      stopMotors();
    }
  }
}

void moveForward() {
  analogWrite(ENA, CRUISE_SPEED); analogWrite(ENB, CRUISE_SPEED);
  digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}

void moveBackward() {
  analogWrite(ENA, CRUISE_SPEED); analogWrite(ENB, CRUISE_SPEED);
  digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}

void spinLeft() {
  analogWrite(ENA, TURN_SPEED); analogWrite(ENB, TURN_SPEED);
  digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}

void spinRight() {
  analogWrite(ENA, TURN_SPEED); analogWrite(ENB, TURN_SPEED);
  digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}

void stopMotors() {
  digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
  analogWrite(ENA, 0); analogWrite(ENB, 0);
}

void alertBeep() {
  digitalWrite(BUZZER, HIGH); delay(80); digitalWrite(BUZZER, LOW);
}

6. 🩺 Classroom Troubleshooting Matrix

Quick Filters:
Issue Observed Underlying Cause Instant Classroom Remedy
Ultrasonic sensor constantly reads 0 cm or 300 cm TRIG or ECHO jumper wires loose or swapped. Verify TRIG is on Pin A1 and ECHO is on Pin A2.
Servo jitters violently or resets Arduino Voltage drop caused by simultaneous motor + servo inrush current. Ensure 18650 battery pack is charged; verify Arduino GND and L298N GND are tied together.
Car turns toward the obstacle instead of away from it Left/Right scan values swapped or motor polarity reversed. Verify 160° points to the car's physical left, and 20° points to the physical right.
Car does not turn sharply enough on carpets Friction on rubber wheels requires higher turn torque. Increase TURN_SPEED in code from 195 to 220 or 240.
Servo arm hits chassis or wire bundle during sweep Mechanical interference on rotation arc. Tuck wires behind the sensor mount using zip-ties or rubber bands.