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

Arduino UNO-Based Battery-Powered DC Motor Control System with Rocker Switches

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Battery-Powered DC Motor Control System with Rocker Switches

Circuit Documentation

Summary

This circuit is designed to control multiple DC motors using an Arduino UNO and two L298N motor drivers. The circuit also includes rocker switches for direction control and emergency stop functionality. The power supply is provided by multiple 12V batteries and a 3.3V battery.

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 battery for powering motors and motor drivers.
    • Pins: +, -
  5. 3.3V Battery

    • Description: 3.3V battery for powering switches.
    • Pins: +, -
  6. Rocker Switch

    • Description: Switch for direction control and emergency stop.
    • Pins: output, input

Wiring Details

Arduino UNO

DC Motor 1

DC Motor 2

DC Motor 3

L298N Motor Driver 1

L298N Motor Driver 2

Rocker Switch 1

Rocker Switch 2

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 and rocker switches, reads the state of the switches, and controls the motors accordingly. The stopMotors, moveForward, and moveBackward functions handle the motor control logic.