L293D motor driver with arduino

DC motor

Introducing to L293D motor driver

If you want to control an DC motor that can run forward or reverse you can do that in many ways. But I want to tell you the simplest way to drive DC motor. In this project we will control the DC motor using single IC called L293D. This IC is powerful enough to control DC motor with low current. Before we start the wiring. We will introduce you to L293D IC first. This is the pinout :

L293D Pinout
L293D Pinout




L293D can drive up to 2 motors with single IC. Use input 1 and Input 2 to control first motor. So first motor should be connected to Output 1 and Output 2. And if you want to use second motor, connect input control to Input 3 and Input 4. And motor to Output 3 and Output 4. VCC should be connected to 5V to power up the IC. VSS is input power for motors. So if you want to use 12V motor, this pin should connect to 12V power supply. Connect 12V and 5V ground to gnd, wire all gnd. And Enable pin is used to control speed of motors using PWM. Enable 1 used to control speed of first motor, and Enable 2 for second motor.

L293D schematic with motor example

So how we use this IC? check our example schematic below :

L293D with motors schematic
L293D with motors schematic

To Control first motor (left), you can give input from microncontroller like arduino to make motor run forward or reverse. Give Pin 2 HIGH/5V and Pin 3 LOW/0V to run motor forward. If you want to run motor reverse then give Pin 2 LOW/0V and Pin 3 HIGH/5V.  Give Pin 1 (Enable 1) PWM input to control the speed. If you use arduino UNO you can give PWM from 0-255. Mean that 255 is full speed and 0 is stopped. And if you don’t want to control the speed you can just connect Pin 1 to 5V.



Control the second motor (right) use pin 10 and 15 to give the direction, and Pin 9 to vary the speed.

Example in bread board

Here’s example of using L293D with an arduino UNO and a DC motor

L293D single motor bread board

L293D single motor bread board



In picture above, motor power supply using a 4x AAA batteries. And 5V supply for IC given from arduino 5V.

Code example :

const int motorPin1  = 2;  // Pin 14 of L293
const int motorPin2  = 3;  // Pin 10 of L293

void setup() {
  //Set pins as outputs
  pinMode(motorPin1, OUTPUT);
}


void loop() {
  //This code  will turn Motor forward for 2 sec.
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  delay(3000);
  //This code will turn Motor reverse for 2 sec.
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  delay(3000);
}

If you want to drive High current DC motor, you can visit here.

Understanding Voltage Divider

voltage divider

Just like the term, voltage divider means dividing the voltage into smaller value. Sometimes this is very useful if we had only measurement instrument with limited maximum value. Such as pocket oscilloscope.

Understanding Voltage Divider

Dividing voltage is very simple job but very powerful. We just need two resistor to do it. Here’s the example how we do it.

voltage divider
voltage divider

Consider we have 10V voltage, using two resistor will result 5v at the output. This is how we calculate it :

Vout = Vin * R1/(R1+R2)

So if we want to divide the voltage by 3. You can simply change the R2 to 2k. So the output will be :

Vout = 10 * 1k/(1k+2k) = 3,333 V

Voltage Divider Application Example

In some cases, voltage divider is very useful for signal conditioning. For example, you have to sense a voltage from a power supply using an arduino or other microcontroller. The power supply can generate voltage from 0V-50V. Unfortunately, your arduino can sense voltage only from 0V-5V. That’s why voltage divider come in handy. You can just divide voltage from power supply by 10. So the output will only produce voltage between 0V to 5V and you can read using arduino ADC easily.

Beside divide the voltage, you can use voltage divider to convert resistance based sensor to voltage. For example a light dependent resistor (LDR).

voltage divider with ldr
voltage divider with ldr

Take a look at pcture above. We already know that LDR will vary the resistance by how much light that exposed to it. This will make easier to read voltage output from different light brightness.

Voltage Divider is not for Power Supply

If you are new to electronics and think to use voltage divider for power supply then you are wrong. Why not for power supply? Voltage divider works with big resistors, so it will produce very small current. Small current cannot used for power supply. You can user linear regulator or switching power supply instead.