Introduction: Spinning a Dc Motor With a Raspberry Pi

About: I like Arduino, Raspberry Pi, modifying Nerf blasters, and messing with virtual machines. Also, make sure to follow my Instagram @analogchip (haven't posted in a while, but still.)

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

4. Battery Holder

5. Female To Female Jumper Wires

Step 1: Hook the Relay Up to the Raspberry Pi

+ goes to 5V.

- goes to GND.

S goes to GPIO18

Step 2: Hook Up the Motor to the Relay

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.

Step 3: Code It!!

#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)

Attachments

Step 4: Turn It On!

First run sudo reboot. Next run python3 relay.py. the motor will turn on and off!

Step 5: Troubleshooting

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!

Step 6: Hope You Enjoyed!

Hope you enjoyed! if you want to take relays and motors farther be sure to check out my Motion Detecting Nerf Gun!

STEM Contest

Participated in the
STEM Contest