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

Arduino and ESP32-CAM Based Autonomous Robot with Ultrasonic Obstacle Detection and Battery Power

View and Edit Project In Cirkit DesignerImage of Arduino and ESP32-CAM Based Autonomous Robot with Ultrasonic Obstacle Detection and Battery Power

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a robotic vehicle. The circuit includes various sensors, motors, and microcontrollers to enable autonomous navigation and obstacle avoidance. The primary components include an HC-SR04 Ultrasonic Sensor, multiple DC Gearmotors, a Servomotor, an ESP32-CAM, an Arduino UNO, and a DRIVER SHIELD L293D. The circuit is powered by a 2x 18650 battery pack and controlled via an Arduino UNO microcontroller.

Component List

  1. HC-SR04 Ultrasonic Sensor

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Ultrasonic distance sensor used for obstacle detection.
    • Purpose: Measures distance to obstacles in front of the robot.
  2. Gearmotor DC Wheels Left

    • Pins: PIN1, PIN2
    • Description: DC motor for driving the left wheels.
    • Purpose: Provides movement to the left side of the robot.
  3. Gearmotor DC Wheels Right

    • Pins: PIN1, PIN2
    • Description: DC motor for driving the right wheels.
    • Purpose: Provides movement to the right side of the robot.
  4. Servomotor SG90

    • Pins: SIG, VCC, GND
    • Description: Small servomotor for precise control.
    • Purpose: Used for steering or other precise movements.
  5. Rocker Switch (SPST)

    • Pins: 1, 2
    • Description: Single-pole single-throw switch.
    • Purpose: Used to turn the circuit on and off.
  6. ESP32-CAM

    • Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
    • Description: Microcontroller with camera module.
    • Purpose: Provides vision capabilities to the robot.
  7. Arduino UNO

    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
    • Description: Microcontroller board based on the ATmega328P.
    • Purpose: Main controller for the robot.
  8. 2x 18650 Battery Pack

    • Pins: vcc, gnd
    • Description: Battery pack with two 18650 cells.
    • Purpose: Provides power to the circuit.
  9. DRIVER SHIELD L293D

    • Pins: RESET, 3.3V, 5V, GND, VIN, 9V, A0, A1, A2, A3, A4, A5, M2 (+), M2 GND (-), M1 (+), M1 GND (-), M3 (+), M3 GND (-), M4 GND (-), M4 (+), SERVO_2, SERVO_1, RX/D0, TX/D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, ARef, D13, D12, VCC (External Power Supply), GND (External Power Supply)
    • Description: Motor driver shield for Arduino.
    • Purpose: Controls the motors and provides power distribution.
  10. Lilygo 7670e

    • Pins: 3v3, Gnd, Pin 32, pin 33, pin 34, pin35, pin 25, Pin 26, Pin 27, Pin 4, Pin 2, Pin 15, pin 14, Pin 13, Pin 12, VBAT, TXD, RXD, 3v3, Pin 22, Pin 21, Pin 23, Pin 19, Pin 18, Pin 5, Pin 39, Pin 36, Pin 0, RST, VBUS, LTE antenna, Gps Antenna, Type C
    • Description: Microcontroller with various I/O pins.
    • Purpose: Additional processing and control capabilities.

Wiring Details

HC-SR04 Ultrasonic Sensor

Gearmotor DC Wheels Left (Instance 1)

Gearmotor DC Wheels Left (Instance 2)

Gearmotor DC Wheels Right (Instance 1)

Gearmotor DC Wheels Right (Instance 2)

Servomotor SG90

Rocker Switch (SPST)

2x 18650 Battery Pack

ESP32-CAM

Lilygo 7670e

Servo

Documented Code

#include <Servo.h>

volatile int IN1 = 11;
volatile int IN2 = 6;
volatile int IN3 = 5;
volatile int IN4 = 3;
volatile int rightDistance;
volatile int leftDistance;
Servo servo_4;

void left_side_forward(int speed) {
  analogWrite(IN1, speed * 0.92);
  analogWrite(IN2, 0);
}

void right_side_forward(int speed) {
  analogWrite(IN3, speed);
  analogWrite(IN4, 0);
}

void left_side_backward(int speed) {
  analogWrite(IN1, 0);
  analogWrite(IN2, speed * 0.92);
}

void right_side_backward(int speed) {
  analogWrite(IN3, 0);
  analogWrite(IN4, speed);
}

float checkdistance_A1_A2() {
  digitalWrite(A1, LOW);
  delayMicroseconds(2);
  digitalWrite(A1, HIGH);
  delayMicroseconds(10);
  digitalWrite(A1, LOW);
  float distance = pulseIn(A2, HIGH) / 58.00;
  delay(10);
  return distance;
}

void forward(int speed) {
  left_side_forward(speed);
  right_side_forward(speed);
}

void backward(int speed) {
  left_side_backward(speed);
  right_side_backward(speed);
}

void left(int speed, int time) {
  left_side_backward(speed);
  right_side_forward(speed);
  delay(time);
  stop();
}

void right(int speed, int time) {