Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Controlled DC Motor with 12V Battery and Motor Driver

Image of ESP32-Controlled DC Motor with 12V Battery and Motor Driver

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a DC motor using an ESP32 microcontroller and a 2-channel motor driver. The ESP32 sends control signals to the motor driver, which in turn drives the motor. The motor is powered by a 12v battery, which also supplies power to the motor driver. The ESP32 is responsible for generating PWM (Pulse Width Modulation) signals and direction control to regulate the speed and direction of the motor.

Component List

12v Battery

  • Description: A 12-volt battery that provides the main power source for the motor and motor driver.
  • Pins: - (Negative), + (Positive)

DC Motor

  • Description: A direct current (DC) motor that converts electrical energy into mechanical rotation.
  • Pins: pin 1, pin 2

Motor Driver 2 Channel

  • Description: A dual-channel motor driver that allows for direction and speed control of two motors.
  • Pins: DIR B, PWM B, DIR A, PWM A, 5Vo, GND, B+, B-, A-, A+, VM

ESP32 (30 pin)

  • Description: A microcontroller with Wi-Fi and Bluetooth capabilities, used for controlling various peripherals including motors.
  • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3

Wiring Details

12v Battery

  • + connected to VM on Motor Driver 2 Channel
  • - connected to GND on Motor Driver 2 Channel

DC Motor

  • pin 1 connected to B+ on Motor Driver 2 Channel
  • pin 2 connected to B- on Motor Driver 2 Channel

Motor Driver 2 Channel

  • DIR B connected to D23 on ESP32
  • PWM B connected to D22 on ESP32
  • GND connected to GND on ESP32
  • B+ connected to pin 1 on DC Motor
  • B- connected to pin 2 on DC Motor
  • VM connected to + on 12v Battery
  • GND connected to - on 12v Battery

ESP32 (30 pin)

  • D23 connected to DIR B on Motor Driver 2 Channel
  • D22 connected to PWM B on Motor Driver 2 Channel
  • GND connected to GND on Motor Driver 2 Channel

Documented Code

sketch.ino

void setup() {
  // Set motor control pins as outputs
  pinMode(23, OUTPUT); // DIR B
  pinMode(22, OUTPUT); // PWM B

  // Initialize motor control signals
  analogWrite(22, 100); // Set PWM B to a duty cycle for speed control
  digitalWrite(23, HIGH); // Set DIR B high for direction control
}

void loop() {
  // Main code loop
  // Motor control code would be placed here to run repeatedly
}

This code snippet is responsible for initializing the ESP32 microcontroller's pins that are connected to the motor driver. It sets pin 23 as the direction control (DIR B) and pin 22 as the PWM control (PWM B) for the motor driver. The analogWrite function is used to set the speed of the motor by adjusting the PWM duty cycle, and digitalWrite is used to set the direction. The loop function is currently empty, as the main control logic would be implemented here based on the specific application requirements.