Spinning a Dc Motor With a Raspberry Pi

Introduction: Spinning a Dc Motor With a Raspberry Pi

About: I love Raspberry pi, Nerf, Minecraft, 3D printing, and raspberry pie😁.

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

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

This is an entry in the
STEM Contest

Be the First to Share

    Recommendations

    • Magnets Challenge

      Magnets Challenge
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    Discussions