Back to Robotics Hub
Advanced Robotics Advanced Mar 21, 2026

Autonomous Obstacle Avoiding Rover

Autonomous Obstacle Avoiding Rover

Project Overview

The ultimate capstone project. This rover uses an ultrasonic sensor mounted on a micro-servo. When it detects an obstacle, it stops, looks left and right, decides which path is clearer, and maneuvers appropriately.

Components Required

  • 1x Arduino Uno
  • 1x Motor Driver Shield (L293D) or L298N
  • 1x SG90 Micro Servo
  • 1x HC-SR04 Ultrasonic Sensor
  • Rover chassis with 2 DC Motors

Wiring Guide

Mount the ultrasonic sensor to the top horn of the servo. Connect the servo signal pin to Arduino Pin 9 or 10. Wire the ultrasonic sensor TRIG and ECHO pins. Run motors from the motor shield outputs.

Source Code Concept


#include <Servo.h>
Servo headServo;

void setup() {
  headServo.attach(10);
  headServo.write(90); // Look straight ahead
  // Initialize motors and sensors
}

void loop() {
  int distance = getDistance();
  
  if (distance < 20) {
    stopMotors();
    headServo.write(0); // Look Right
    delay(500);
    int distRight = getDistance();
    
    headServo.write(180); // Look Left
    delay(500);
    int distLeft = getDistance();
    
    headServo.write(90); // Center head
    
    if (distLeft >= distRight) {
      turnLeft();
    } else {
      turnRight();
    }
  } else {
    driveForward();
  }
}