Dc-motor
Jump to navigation
Jump to search
L293D motor driver
Diagram
Code
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Motor1 = {'EN': 17, 'input1': 27, 'input2': 22}
for x in Motor1:
GPIO.setup(Motor1[x], GPIO.OUT)
EN1 = GPIO.PWM(Motor1['EN'], 100)
EN1.start(0)
while True:
for x in range(40, 100):
print ("FORWARD MOTION")
EN1.ChangeDutyCycle(x)
GPIO.output(Motor1['input1'], GPIO.HIGH)
GPIO.output(Motor1['input2'], GPIO.LOW)
sleep(0.1)
print ("STOP")
EN1.ChangeDutyCycle(0)
sleep(5)
for x in range(40, 100):
print ("BACKWARD MOTION")
EN1.ChangeDutyCycle(x)
GPIO.output(Motor1['input1'], GPIO.LOW)
GPIO.output(Motor1['input2'], GPIO.HIGH)
sleep(0.1)
print ("STOP")
EN1.ChangeDutyCycle(0)
sleep(5)
GPIO.cleanup()