ESP32-Controlled Dual DC Motor Driver with L293D and Diode Protection
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control two DC motors using an ESP32 microcontroller and an L293D motor driver. The ESP32 is responsible for generating control signals that are then used by the L293D to drive the motors. Diodes are used in the circuit for protection against voltage spikes that can occur when the motors are turned off.
Component List
ESP32 (30 pin)
- Microcontroller with WiFi and Bluetooth capabilities.
- It has multiple digital I/O pins and provides the control logic for the motor driver.
L293D
- A motor driver IC capable of driving two DC motors.
- It has pins for motor control inputs, outputs to the motors, power supply, and ground.
DC Motor
- An electric motor that runs on direct current (DC) electricity.
- Two instances of this component are used in the circuit to perform mechanical work.
Diode
- A semiconductor device that allows current to flow in one direction only.
- Multiple instances of diodes are used for protection in the circuit.
Wiring Details
ESP32 (30 pin)
D34is connected to the enable pins of the L293D to control the operation of the motor driver.D35andD32are connected to the input pins of the L293D to control the first motor.D33andD27are connected to the input pins of the L293D to control the second motor.Vinis connected to the power supply pins of the L293D through diodes for voltage input.GNDis connected to the ground pins of the L293D and diodes for a common ground reference.
L293D
Enable 1,2andEnable 3,4are connected toD34on the ESP32 for enabling the motor driver.Input 1,Input 2,Input 3, andInput 4are connected toD35,D32,D27, andD33on the ESP32 for motor control signals.Output 1,Output 2,Output 3, andOutput 4are connected to the DC motors with diodes in between for motor operation and protection.Vcc1,Vcc2, andGNDare connected to the power supply and ground through diodes for power and protection.
DC Motor
- Each motor has two pins (
pin 1andpin 2) that are connected to the output pins of the L293D with diodes in between for operation and protection.
Diode
- Multiple diodes are used to connect the power supply to the L293D and to protect the motors from voltage spikes.
Documented Code
#include <Arduino.h>
int motor11 = 35;
int motor12 = 32;
int pornire = 34;
int motor21 = 33;
int motor22 = 27 ;
void setup() {
Serial.begin(9600);
pinMode(motor11, OUTPUT);
pinMode(motor12, OUTPUT);
pinMode(motor21, OUTPUT);
pinMode(motor22, OUTPUT);
pinMode(pornire, OUTPUT);
digitalWrite(pornire, HIGH);
}
void loop() {
digitalWrite(motor11, HIGH);
digitalWrite(motor12, LOW);
digitalWrite(motor21, HIGH);
digitalWrite(motor22, LOW);
delay(1000);
digitalWrite(motor11, LOW);
digitalWrite(motor12, HIGH);
digitalWrite(motor21, LOW);
digitalWrite(motor22, HIGH);
delay(1000);
// The following commented code is for PWM control of the motors
/*
for (int i = 0; i <= 255; i++) {
digitalWrite(motor22, LOW);
analogWrite(motor21, i);
Serial.print(motor22);
Serial.print(" / ");
Serial.println(i);
}
for (int o = 0; o <= 255; o++) {
digitalWrite(motor21, LOW);
analogWrite(motor22, o);
Serial.print(motor22);
Serial.print(" / ");
Serial.println(o);
}
*/
}
The code provided is an Arduino sketch that sets up the ESP32 to control two DC motors via the L293D motor driver. The setup() function initializes the motor control pins as outputs and sets the enable pin high to activate the motor driver. The loop() function then alternates the direction of the motors by changing the state of the control pins and introduces a delay between the direction changes. There is also commented-out code for PWM control of the motors, which can be used for speed control if uncommented and properly configured.