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

ESP32-Controlled Dual DC Motor Driver with L293D and Diode Protection

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Dual DC Motor Driver with L293D and Diode Protection

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)

L293D

DC Motor

Diode

Wiring Details

ESP32 (30 pin)

L293D

DC Motor

Diode

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.