- DC Motor is small in size, inexpensive and powerful. It is widely used in robotics for their small size and high energy out.
- A typical DC motor operates at a very high speed.
- Gear reduces the speed of the motor and increases the torque.
L293D Motor Driver
- L293D is an H-BRIDGE dc motor controller, which can control dc motor up to 36V.
- Driver allows dc motor to rotate in both direction, which can interface and control the two motor at a time with Raspberry pi.
- Driver allows voltage to flow in both direction hence motor can rotate in both clockwise and anti-clockwise direction.
- Raspberry pi.
- DC motor.
- L293D Motor Driver.
- Jumper wires.
- Create a new text file “Motor.py” by typing the following
- Now type the following code
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) //BCM is broadcom which specifies the actual pin number considered by broadcom chip GPIO.setwarnings(False) //Ignore warnings button_pin=25 enable_pin=18 in1-pin=23 in2_pin=24 GPIO.setup(button_pin, GPIO.IN) //Set pin 25 to be an input pin for push button. GPIO.setup(enable_pin, GPIO.OUT) GPIO.setup(in1_pin, GPIO.OUT) GPIO.setup(in2_pin, GPIO.OUT) GPIO.output(enable_pin,GPIO.HIGH) //set pin 18 to be high for driver circuit if GPIO.input(button_pin) == GPIO.HIGH: GPIO.output(in1_pin,GPIO.HIGH) //Rotates in clockwise direction GPIO.output(in2_pin,GPIO.LOW) time.sleep(5) GPIO.output(in1_pin,GPIO.LOW) //Rotates in anti-clockwise direction GPIO.output(in2_pin,GPIO.HIGH) time.sleep(5) else; GPIO.output(in1_pin,GPIO.LOW) //Motor turn off GPIO.output(in2_pin,GPIO.LOW) GPIO.cleanup() //To reset the pin status
- To run type python Motor.py in the terminal.