So this is another simple project with the Raspberry Pi where I’ve controlled the direction of rotation of DC Motor.
Check out other Raspberry Pi Projects here: (LINK)
You can’t really see the direction of rotation here!! Sorry!
- Raspberry Pi (I’ve used Raspberry Pi 3)
- HDMI Screen
- DC Motor
- External Power Supply
- Jumper wire
- Link to article that I followed: (LINK)
Note that the following code is in python!
View on/Download from Github: (LINK)
import RPi.GPIO as GPIO from time import sleep Motor1A = 24 Motor1B = 23 Motor1E = 25 def setup(): GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(Motor1A, GPIO.OUT) GPIO.setup(Motor1B, GPIO.OUT) GPIO.setup(Motor1E, GPIO.OUT) def loop(): #forwards GPIO.output(Motor1A, GPIO.HIGH) GPIO.output(Motor1B, GPIO.LOW) GPIO.output(Motor1E, GPIO.HIGH) sleep(5) #backwards GPIO.output(Motor1A, GPIO.LOW) GPIO.output(Motor1B, GPIO.HIGH) GPIO.output(Motor1E, GPIO.HIGH) sleep(5) #stop GPIO.output(Motor1E, GPIO.LOW) def destroy(): print("Destroyed") GPIO.cleanup() if __name__ == '__main__': setup() try: while True: loop() except KeyboardInterrupt: destroy()
Stay Tuned for upcoming posts on Raspberry Pi Projects! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!