Spinning a Dc Motor With a Raspberry Pi
by Computer Kid in Circuits > Raspberry Pi
1155 Views, 3 Favorites, 0 Comments
Spinning a Dc Motor With a Raspberry Pi
![DSCF2376.JPG](/proxy/?url=https://content.instructables.com/FF1/BI08/K4PAWMAO/FF1BI08K4PAWMAO.jpg&filename=DSCF2376.JPG)
Hi there! Welcome to the somewhat crazy world of relays, motors, electronics, and best of all... RASPBERRY PI!.
I know some of you people don't know anything about raspberry pi, but some of you didn't even know it existed! In case you don't know what it is, click HERE!. Now that all of you are up to speed, LETS GET TO IT! (If you watch my YouTube videos (@Computer Kid), these words are very familiar to you!). If you're interested in laser etching stuff be sure to visit my Facebook page!
Supplies
1. Raspberry Pi (2b and newer to avoid screaming at the pi because of how slow the earlier models are;-)
2. Relay (I used a SRD-05VDC-SL-C))
3. Motor
Hook the Relay Up to the Raspberry Pi
![DSCF2370.JPG](/proxy/?url=https://content.instructables.com/FR0/CRTU/K4PAWMAH/FR0CRTUK4PAWMAH.jpg&filename=DSCF2370.JPG)
![DSCF2373.JPG](/proxy/?url=https://content.instructables.com/FV5/M3AX/K4PAWMAJ/FV5M3AXK4PAWMAJ.jpg&filename=DSCF2373.JPG)
![raspberry-pi-gpio-pinouts.png](/proxy/?url=https://content.instructables.com/FM1/ZE7O/K4PAWMCV/FM1ZE7OK4PAWMCV.png&filename=raspberry-pi-gpio-pinouts.png)
+ goes to 5V.
- goes to GND.
S goes to GPIO18
Hook Up the Motor to the Relay
![DSCF2374.JPG](/proxy/?url=https://content.instructables.com/FA6/6X9M/K4PAWMAL/FA66X9MK4PAWMAL.jpg&filename=DSCF2374.JPG)
![DSCF2375.JPG](/proxy/?url=https://content.instructables.com/FB1/A49Q/K4PAWMAM/FB1A49QK4PAWMAM.jpg&filename=DSCF2375.JPG)
Hook the negative directly up to the motor, positive up to the center of the relay, then finally the left side of the relay to the positive of the motor.
Code It!!
![pythonlogo.0658b34b4498.jpg](/proxy/?url=https://content.instructables.com/F9B/AGEO/K4PAWPFA/F9BAGEOK4PAWPFA.jpg&filename=pythonlogo.0658b34b4498.jpg)
#to create this file type in the terminal sudo nano relay.py #to run this file run in the terminal python3 relay.py import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) while True: GPIO.output(18, True) sleep(1) GPIO.output(18, False) sleep(1)
Downloads
Turn It On!
![DSCF2376.JPG](/proxy/?url=https://content.instructables.com/FF1/BI08/K4PAWMAO/FF1BI08K4PAWMAO.jpg&filename=DSCF2376.JPG)
First run sudo reboot. Next run python3 relay.py. the motor will turn on and off!
Troubleshooting
![warning_sign_bold.png](/proxy/?url=https://content.instructables.com/FRH/WXCK/K4PAWO1O/FRHWXCKK4PAWO1O.png&filename=warning_sign_bold.png)
IF YOUR RELAY/MOTOR ARE WORKING FINE SKIP THIS BORING SECTION!!!
Common problem 1: the relay is clicking but the motor isn't spinning
Fix: check your wiring, if this doesn't work check what voltage your motor is rated for and how much your batteries output.
Common problem 2: raspberry pi won't turn on.
Fix: some wires are probably touching.
Uncommon problem: you smell a burning smell and/or see smoke
What to do: REMOVE THE BATTERY PACK IMMEDIATLY!!!
If you have any issues that are not listed here, or the fixes aren't working post a comment!
Good luck!
Hope You Enjoyed!
![hope you enjoyed!!.bmp](/proxy/?url=https://content.instructables.com/F4H/2XAN/K4PAWP9N/F4H2XANK4PAWP9N.bmp&filename=hope you enjoyed!!.bmp)
Hope you enjoyed! if you want to take relays and motors farther be sure to check out my Motion Detecting Nerf Gun!