Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Pro Mini-Based Obstacle Avoidance Robot with Ultrasonic and IR Sensors

View and Edit Project In Cirkit DesignerImage of Arduino Pro Mini-Based Obstacle Avoidance Robot with Ultrasonic and IR Sensors

Circuit Documentation

Summary

This circuit is designed to interface multiple sensors and motors with an Arduino Pro Mini microcontroller. The circuit includes three HC-SR04 ultrasonic sensors, two DC Mini Metal Gear Motors, an IR sensor, and an L293D motor driver. The Arduino Pro Mini is programmed to read sensor data and control the motors based on the sensor inputs.

Component List

  1. HC-SR04 Ultrasonic Sensor

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Ultrasonic distance sensor used to measure distance to objects.
  2. DC Mini Metal Gear Motor

    • Pins: IN1, IN2
    • Description: Small DC motor with metal gears for precise control.
  3. 7.4v Battery

    • Pins: +, -
    • Description: Power source for the circuit.
  4. Arduino Pro Mini v13

    • Pins: DTR, D0/TX, D1/RX, VCC, GND, A4, A5, RAW, RESET, A3, A2, A1, A0, D13/SCK, D12/MISO, D11 PWM/MOSI, D10 PWM/SS, D9 PWM, D8, D7, D6 PWM, D5 PWM, D4, D3 PWM, D2
    • Description: Microcontroller used to control the circuit.
  5. 7805 Voltage Regulator

    • Pins: Vin, Gnd, Vout
    • Description: Voltage regulator to provide a stable 5V output.
  6. IR Sensor

    • Pins: out, gnd, vcc
    • Description: Infrared sensor used to detect obstacles.
  7. L293D Motor Driver

    • Pins: enable 1, input 1, output 1, gnd, output 2, input 2, vs, vss, input 4, output 4, output 3, input 3, enable 2
    • Description: Motor driver used to control the DC motors.

Wiring Details

HC-SR04 Ultrasonic Sensor 1

HC-SR04 Ultrasonic Sensor 2

HC-SR04 Ultrasonic Sensor 3

DC Mini Metal Gear Motor 1

DC Mini Metal Gear Motor 2

7.4v Battery

Arduino Pro Mini v13

7805 Voltage Regulator

IR Sensor

L293D Motor Driver

Documented Code

// defining the pins
const int trigPin1 = 3;
const int echoPin1 = 5;
const int trigPin2 = 6;
const int echoPin2 = 9;
const int trigPin3 = 10;
const int echoPin3 = 11;
int irpin = 2;

// defining variables
long duration1;
long duration2;
long duration3;
int distanceleft;
int distancefront;
int distanceright;
int a = 0;

void setup() {
  pinMode(trigPin1, OUTPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(trigPin3, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin1, INPUT);  // Sets the echoPin as an Input
  pinMode(echoPin2, INPUT);
  pinMode(echoPin3, INPUT);
  pinMode(irpin, INPUT);
  pinMode(4, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop() {
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distanceleft = duration1 * 0.034 / 2;
  Serial.print("Distance1: ");
  Serial.println(distanceleft);

  digitalWrite(trigPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distancefront = duration2 * 0.034 / 2;
  Serial.print("Distance2: ");
  Serial.println(distancefront);

  digitalWrite(trigPin3, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin3, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distanceright = duration3 * 0.034 / 2;
  Serial.print("Distance3: ");
  Serial.println(distanceright);

  int s = digitalRead(irpin);
  if (s == HIGH) {
    digitalWrite(4, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(12, HIGH);
    delay(1000);
    a = 1;
  }

  if ((a == 0) && (s == LOW) && (