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

Arduino UNO and ESP32-CAM Controlled DC Motor System with Emergency Stop

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ESP32-CAM Controlled DC Motor System with Emergency Stop

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller, an ESP32-CAM module, two L298N DC motor drivers, four DC motors, a 12V battery, a 3.3V battery, and two rocker switches. The Arduino UNO controls the motor drivers and the ESP32-CAM, while the rocker switches are used for direction control and emergency stop functionality.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • 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
  2. DC Motor

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  3. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  4. Battery 12V

    • Description: 12V power source.
    • Pins: +, -
  5. ESP32-CAM

    • Description: Wi-Fi and Bluetooth module with camera.
    • Pins: 5V, GND, IO12, IO13, IO15, IO14, IO2, IO4, VOT, VOR, VCC, IO0, IO16, 3V3
  6. Rocker Switch

    • Description: On/Off switch.
    • Pins: output, input
  7. Battery 3.3V

    • Description: 3.3V power source.
    • Pins: +, -

Wiring Details

Arduino UNO

DC Motor

L298N DC Motor Driver

Battery 12V

ESP32-CAM

Rocker Switch

Battery 3.3V

Code Documentation

// Motor driver 1 pins
const int IN1_1 = 13;
const int IN2_1 = 12;
const int IN3_1 = 11;
const int IN4_1 = 10;

// Motor driver 2 pins
const int IN1_2 = 7;
const int IN2_2 = 6;
const int IN3_2 = 5;
const int IN4_2 = 4;

// ESP32-CAM pins
const int VOR = 0;
const int VOT = 1;

// Rocker switch pins
const int DIRECTION_SWITCH = 2;
const int EMERGENCY_STOP_SWITCH = 8;

void setup() {
  // Initialize motor driver 1 pins
  pinMode(IN1_1, OUTPUT);
  pinMode(IN2_1, OUTPUT);
  pinMode(IN3_1, OUTPUT);
  pinMode(IN4_1, OUTPUT);

  // Initialize motor driver 2 pins
  pinMode(IN1_2, OUTPUT);
  pinMode(IN2_2, OUTPUT);
  pinMode(IN3_2, OUTPUT);
  pinMode(IN4_2, OUTPUT);

  // Initialize ESP32-CAM pins
  pinMode(VOR, INPUT);
  pinMode(VOT, OUTPUT);

  // Initialize rocker switch pins
  pinMode(DIRECTION_SWITCH, INPUT);
  pinMode(EMERGENCY_STOP_SWITCH, INPUT);

  // Initial motor states
  stopMotors();
}

void loop() {
  // Read switch states
  int directionSwitchState = digitalRead(DIRECTION_SWITCH);
  int emergencyStopSwitchState = digitalRead(EMERGENCY_STOP_SWITCH);

  // Control motors based on switch states
  if (emergencyStopSwitchState == HIGH) {
    // Emergency stop: Stop all motors
    stopMotors();
  } else {
    if (directionSwitchState == HIGH) {
      // Move motors forward
      moveForward();
    } else {
      // Move motors backward
      moveBackward();
    }
  }

  delay(100); // Small delay for switch debounce
}

void stopMotors() {
  // Stop motor driver 1
  digitalWrite(IN1_1, LOW);
  digitalWrite(IN2_1, LOW);
  digitalWrite(IN3_1, LOW);
  digitalWrite(IN4_1, LOW);

  // Stop motor driver 2
  digitalWrite(IN1_2, LOW);
  digitalWrite(IN2_2, LOW);
  digitalWrite(IN3_2, LOW);
  digitalWrite(IN4_2, LOW);
}

void moveForward() {
  // Motor driver 1: Forward
  digitalWrite(IN1_1, HIGH);
  digitalWrite(IN2_1, LOW);
  digitalWrite(IN3_1, HIGH);
  digitalWrite(IN4_1, LOW);

  // Motor driver 2: Forward
  digitalWrite(IN1_2, HIGH);
  digitalWrite(IN2_2, LOW);
  digitalWrite(IN3_2, HIGH);
  digitalWrite(IN4_2, LOW);
}

void moveBackward() {
  // Motor driver 1: Backward
  digitalWrite(IN1_1, LOW);
  digitalWrite(IN2_1, HIGH);
  digitalWrite(IN3_1, LOW);
  digitalWrite(IN4_1, HIGH);

  // Motor driver 2: Backward
  digitalWrite(IN1_2, LOW);
  digitalWrite(IN2_2, HIGH);
  digitalWrite(IN3_2, LOW);
  digitalWrite(IN4_2, HIGH);
}

This code initializes the pins for the motor drivers, ESP32-CAM, and rocker switches. It reads the states of the rocker switches to control the direction of the motors and to handle emergency stops. The stopMotors, moveForward, and moveBackward functions control the motor states accordingly.