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 toVMon Motor Driver 2 Channel-connected toGNDon Motor Driver 2 Channel
DC Motor
pin 1connected toB+on Motor Driver 2 Channelpin 2connected toB-on Motor Driver 2 Channel
Motor Driver 2 Channel
DIR Bconnected toD23on ESP32PWM Bconnected toD22on ESP32GNDconnected toGNDon ESP32B+connected topin 1on DC MotorB-connected topin 2on DC MotorVMconnected to+on 12v BatteryGNDconnected to-on 12v Battery
ESP32 (30 pin)
D23connected toDIR Bon Motor Driver 2 ChannelD22connected toPWM Bon Motor Driver 2 ChannelGNDconnected toGNDon 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.
