WebsiteSpark

Monday 15 August 2016

Driving a DC motor using Arduino UNO and L293D driver.

Driving a DC motor using Arduino UNO and L293D driver.

Components required:
1)      Arduino UNO
2)      L293D IC
3)      Breadboard
4)      DC Motor(s)
5)      Connecting wires / jumpers
Connection  

Arduino to L293D to DC Motor.

Pinout diagram of L293D IC












Connectivity

1
Arduino
L293D
Motor
2
D2
1A(2)

3
D3
1B(7)

4
D4
1E(1)

5

M1A
Terminal 1
6

M1B
Terminal 2
7

+VMotor  to External Source

8
GND
GND


Arduino program to control the motor

const int M1A = 2;
const int M1B = 3;
const int M1E = 4;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(M1A, OUTPUT);
  pinMode(M1B, OUTPUT);
  pinMode(M1E, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  //Enable
  digitalWrite(M1E, HIGH);
    
  // forward
  digitalWrite(M1A, HIGH);
  digitalWrite(M1B, LOW);
  delay(5000);              // wait for 5 seconds

  //Reverse
  digitalWrite(M1A, LOW);
  digitalWrite(M1B, HIGH);
  delay(5000);              // wait for 5 seconds 
 
  }
 

  

Driving DC motor using Raspberry Pi GPIO , L293D driver and Python.

Driving DC motor using Raspberry Pi GPIO , L293D driver and Python.

Driving DC motor using Raspberry Pi GPIO , L293D driver and Python.

Components required:
1)      Raspberry Pi
2)      L293D IC
3)      Breadboard
4)      DC Motor(s)
5)      Connecting wires
6)      Pi Cobbler, not mandatory though I have used in my circuit.

Connection  
Pi GPIO to L293D to DC Motor.

Pinout diagram of L293D IC 




Connectivity
1
RPi
L293D
Motor
2
GPIO23 (16)
1A(2)

3
GPIO24(18)
1B(7)

4
GPIO25(22)
1E(1)

5

M1A
Terminal 1
6

M1B
Terminal 2
7

+VMotor  to External Source

8
GND
GND


Python program to control the motor
import RPi.GPIO as gpio
from time import sleep

gpio.setmode(gpio.BOARD)

Motor1A = 16
Motor1b = 18
Motor1e = 22

gpio.setup(Motor1A, gpio.OUT)
gpio.setup(Motor1b, gpio.OUT)
gpio.setup(Motor1e, gpio.OUT)

gpio.output(Motor1A, gpio.HIGH)
gpio.output(Motor1b, gpio.LOW)
gpio.output(Motor1e, gpio.HIGH)

sleep(5)
# reverse
gpio.output(Motor1b, gpio.HIGH)
gpio.output(Motor1A, gpio.LOW)

sleep(5)

gpio.cleanup()