Circuit Documentation
Summary
This circuit is designed to control a DC Mini Metal Gear Motor using an ESP32 Devkit V1 microcontroller and an L293D motor driver. The circuit is powered by a 12V power supply, which is stepped down to appropriate levels using an LM2596 Step Down Module. The ESP32 is programmed to control the motor speed and direction.
Component List
12V Power Supply
- Description: Provides 12V DC power to the circuit.
- Pins: +, -
L293D Motor Driver
- Description: A dual H-bridge motor driver IC that allows control of two DC motors.
- Pins: Enable 1,2, Input 1, Output 1, GND, Output 2, Input 2, Vcc2, Vcc1, Input 4, Output 4, Output 3, Input 3, Enable 3,4
DC Mini Metal Gear Motor
- Description: A small DC motor with metal gears for increased torque.
- Pins: IN1, IN2
ESP32 Devkit V1
- Description: A development board for the ESP32 microcontroller, featuring Wi-Fi and Bluetooth capabilities.
- Pins: 3V3, GND, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, VIN
LM2596 Step Down Module
- Description: A voltage regulator module that steps down the input voltage to a lower, stable output voltage.
- Pins: OUT-, OUT+, IN-, IN+
Wiring Details
12V Power Supply
- + connected to IN+ of LM2596 Step Down Module
- - connected to IN- of LM2596 Step Down Module and GND of L293D Motor Driver
L293D Motor Driver
- Enable 1,2 connected to D13 of ESP32 Devkit V1
- Input 1 connected to D12 of ESP32 Devkit V1
- GND connected to IN- of LM2596 Step Down Module and - of 12V Power Supply
- Input 2 connected to D14 of ESP32 Devkit V1
- Vcc2 connected to IN+ of LM2596 Step Down Module
- Vcc1 connected to IN+ of LM2596 Step Down Module
- Output 1 connected to IN2 of DC Mini Metal Gear Motor
- Output 2 connected to IN1 of DC Mini Metal Gear Motor
DC Mini Metal Gear Motor
- IN1 connected to Output 2 of L293D Motor Driver
- IN2 connected to Output 1 of L293D Motor Driver
ESP32 Devkit V1
- D13 connected to Enable 1,2 of L293D Motor Driver
- D12 connected to Input 1 of L293D Motor Driver
- D14 connected to Input 2 of L293D Motor Driver
- GND connected to OUT- of LM2596 Step Down Module
- VIN connected to OUT+ of LM2596 Step Down Module
LM2596 Step Down Module
- IN+ connected to + of 12V Power Supply
- IN- connected to - of 12V Power Supply and GND of L293D Motor Driver
- OUT- connected to GND of ESP32 Devkit V1
- OUT+ connected to VIN of ESP32 Devkit V1
Documented Code
int en_1_2 = 13;
int in1 = 12;
int in2 = 14;
const int pwmChannel = 0;
const int pwmFreq = 500;
const int pwmResolution = 8;
void setup() {
ledcSetup(pwmChannel, pwmFreq, pwmResolution);
ledcAttachPin(en_1_2, pwmChannel);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void putaran(int kec, int cW, int cCw) {
ledcWrite(pwmChannel, kec);
digitalWrite(in1, cW);
digitalWrite(in2, cCw);
}
void loop() {
for (int i = 0; i <= 255; i++) {
putaran(i, 1, 0);
delay(1000);
}
for (int i = 255; i >= 0; i--) {
putaran(i, 1, 0);
delay(1000);
}
}
This code sets up the ESP32 to control the L293D motor driver, which in turn controls the DC Mini Metal Gear Motor. The motor speed is varied using PWM, and the direction is controlled by setting the appropriate input pins.