How to control DC gear motors and stepper motors using L293D motor driver IC

How to control DC gear motors and stepper motors using L293D motor driver IC

Hello and welcome back. In this tutorial, we will learn how to control DC gear motors and stepper motors using the L293D motor driver IC. I think you already know about this IC. Because the L293D motor driver shield is designed using these two ICs. But in this tutorial, we will learn how a single IC works. For that, I used two gear motors and one stepper motor. And with this knowledge, you can use this single IC instead of a motor control board to control the motors. Ok, let’s go ahead.

The Internal structure of these ICs

These mainly consist of two main techniques. That is,

  • PWM (Pulse Width Modulation)

Through this, we can control the speed of DC motors. These ICs include two pins for that. That is the ENA pin and the ENB pin. The speed of the motors increases or decreases depending on the potential given to these pins.

  • H-Bridge

This h-bridge circuit can control the spinning direction of the motors. Also, the h-bridge circuit is mainly designed using four transistors, which change the spinning direction of the motors by turning them on and off in a special way. Each of these ICs has two h-bridge circuits. So we can control two dc motors individually.

The PIN diagram of this IC

How to control DC gear motors and stepper motors using L293D motor driver IC

OK, let’s learn how to control two DC motors and one stepper motor with this IC. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

DC Gear motor control

We can control two DC gear motors with this IC. If you want to control more motors you can use more ICs.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. For that, use the circuit diagram below.

How to control DC gear motors and stepper motors using L293D motor driver IC

Step 3

Thirdly, let’s upload the program. It is as follows.

  • The full program of this project — Download
/*L293D with gear motor control
 * https://srituhobby.com
 */
 
//Define input and PWM pins
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 5
#define ENA 9
#define ENB 10

void setup() {
//Set those pins as output pins
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
}

void loop() {
  forward();
  delay(3000);
  Stop();
  delay(2000);
  backward();
  delay(3000);
}

void forward() {
  analogWrite(ENA, 200);
  analogWrite(ENB, 200);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}
void backward() {
  analogWrite(ENA, 200);
  analogWrite(ENB, 200);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}
void Stop() {
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

Step 4

Now, select board and port. After, upload this code to the Arduino board.

Stepper motor control

We can control one stepper motor through this IC.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. For that, use the circuit diagram below.

How to control DC gear motors and stepper motors using L293D motor driver IC

Step 3

Thirdly, let’s upload the program. It is as follows.

  • The full program of this project — Download
/*L293D with stepper motor control
 * https://srituhobby.com
 */
//Include the stepper motor library
#include <Stepper.h>

int steps = 500;//change this to fit the number of steps per revolution

// initialize the stepper library
Stepper myStepper(steps, 2, 3, 4, 5);

void setup() {
  // set the speed at 30 rpm
  myStepper.setSpeed(30);
}

void loop() {
  myStepper.step(steps);
  delay(500);

  myStepper.step(-steps);
  delay(500);
}

Step 4

Then, select board and port. After, upload this code to the Arduino board.

Ok, enjoy this tutorial. The full video guide is below. So see you in the next project or tutorial.

How to control DC gear motors and stepper motors using L293D motor driver IC

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *