Raspberry Pi – How to control motors…

In this tutorial I show you how to control a motor with your Raspberry Pi. By the end of this tutorial you will be able to control the direction of the motor, you will understand the basic principles of how that motor works and you will be able to decipher a simple Python program. Personally I think that controlling motors is one of the coolest things that you can do with the Pi and I truly hope that you enjoy this tutorial! Sorry for the long delay in between videos!

Information:

Buy a motor similar to my one from here: http://www.ebay.co.uk/itm/Arduino-Smart-Car-Robot-DC-3V-6V-Drive-Gear-Motor-with-tire-/161071687657?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item25809ee7e9

Buy a battery pack similar to my one from here: http://www.ebay.co.uk/itm/1-2-3-4-6-8-x-AA-AAA-23A-9V-Battery-Holder-Snap-On-Connector-Enclosed-Box-Switch-/180814661762?pt=UK_BOI_Electrical_Components_Supplies_ET&var=&hash=item2a1964c882

Buy an L298N from this link here: http://www.ebay.co.uk/itm/L298N-Dual-H-Bridge-Stepper-Motor-Driver-Controller-Board-Module-Arduino-Ra-Pi-/130968976501?pt=UK_BOI_Industrial_Automation_Control_ET&hash=item1e7e5bfc75

Wires are easily available on eBay as well!

All of the code and information is in this forum post here: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=55288

Thanks for watching and please subscribe, like and comment!

Happy Piing!

The Raspberry Pi Guy

Y U NO SUBSCRIBE?!

Duration : 0:18:13



Posted

in

by

Tags:

Comments

25 responses to “Raspberry Pi – How to control motors…”

  1. ForNerdGames Avatar
    ForNerdGames

    How to control 12 …
    How to control 12 motors with rasp??

  2. Robin Cerny Avatar
    Robin Cerny

    Most of all videos …
    Most of all videos I’ve seen, the user is pi, with the stupiest sudo setup
    that I know…
    Plus: all of you using the xserver. So much Ressources for a mouse.

    Y U NO use the power of shell??

  3. Mark Smith Avatar
    Mark Smith

    Very simple but …
    Very simple but pretty cool, I think I need to head to maplin! ?

  4. Milan Karakas Avatar
    Milan Karakas

    Good explanation.

    Good explanation.

    I have one question for which I believe other people may have too:

    How to control speed of the motor(s)?

    This is because sometimes we don’t need our robot to run as faster as
    possible, but instead very slowly – especially when some detector
    (ultrasound) is attached to help avoid obstacles. If speed is too fast,
    then robot will bump into obstacles too often.

    Than you in advance,
    milan
    —?

  5. Jeff Neumann Avatar
    Jeff Neumann

    so you made it …
    so you made it control a wheel but how would you get it to control multiple
    wheels??

  6. Qasim Al Khuzaie Avatar
    Qasim Al Khuzaie

    Good for …
    Good for mechatronics enthusiasts! ?

  7. 302RELL Avatar
    302RELL

    Is it possible to …
    Is it possible to control any type of motor with a raspberry pi or arduino?
    I would like to use the actual claw machine from a real arcade machine,
    would I be able to control the motors on the claw gantry(x-y)? They look
    like dc motors. ?

  8. Wesam Fadheel Avatar
    Wesam Fadheel

    please, more …
    please, more experiment?

  9. Barry Houldsworth Avatar
    Barry Houldsworth

    Thanks again. Just …
    Thanks again. Just spent time with my daughter converting a small robot
    using this. We used two wheels (easy enough) and, other than being a little
    under-powered, it worked great.

    I didn’t want to have anything connected such as a keyboard so I set up SSH
    so that I could remote into the Pi and run the programs using Putty from my
    Android tablet. Look ma! No hands!?

  10. Brian Trybus Avatar
    Brian Trybus

    How do you control …
    How do you control 2 or 3 moters?

  11. Zagrajmy z Pistonem Avatar
    Zagrajmy z Pistonem

    Isn’t easier to …
    Isn’t easier to connect motors to relay board??

  12. Groby Cuyai Avatar
    Groby Cuyai

    Nice tutorial! That …
    Nice tutorial! That exactly what I need. But I tried and found the rpi
    can’t work however. When it started screen can print some messages,
    Particularly the network module can’t work, neither wired or wireness. And
    the power I use is 12V. So I doubt the gpio 5V if whether can as the power
    input? I also see the circult diagram, it didn’t has a diode, then I can’t
    how to do next, appreciate for any advices.?

  13. Turtuvshin Namuunzul Avatar
    Turtuvshin Namuunzul

    nice project!!! :v?
    nice project!!! :v?

  14. Bartlomiej Adamczyk Avatar
    Bartlomiej Adamczyk

    I get a syntax …
    I get a syntax error (Non-ASCII character) on line 13 :L when I run the
    code.?

  15. Mark Phelan Avatar
    Mark Phelan

    ?
    ?

  16. CyclesSaga Avatar
    CyclesSaga

    great tutorial, I …
    great tutorial, I don’t think it was to long, just nice and slowly…..?

  17. JVIazRamen Avatar
    JVIazRamen

    Could you also …
    Could you also program/connect an input on the raspberry Pi ??

  18. Jonathan Klingvall Avatar
    Jonathan Klingvall

    I’m doing a project …
    I’m doing a project in school where I want to be able to use the Pi to
    unlock a locker in some way. Is it possible to do this using a L298N? I’m
    completely new to programming.?

  19. Chris Kaspar Avatar
    Chris Kaspar

    Can you control …
    Can you control motor speed with the L298N or is it just an on and off
    function???

  20. Poul Dürr Pedersen Avatar
    Poul Dürr Pedersen

    Hi RaspberryPiGuy, …
    Hi RaspberryPiGuy, first of all thanks for great tutorial vidoes.
    Regarding the L298N, I might have to mention, that maybe you can point out
    that the “5V enable” jumper must be taken off in order to take out the risk
    of pulling more than 16mA from the Pi.
    -I think I have just burned off one of my GPIO pins
    -mine was GPIO 4 used for the ENA
    -now it simpy cuts off after a few seconds

    Furthermore, I can’t seem to pin out why you use two GPIO pins for both ENA
    and ENB, would one not be sufficient??

  21. Jules Wombat Avatar
    Jules Wombat

    Awesome – I am off …
    Awesome – I am off to Maplin. Lets see if I can get my Lego Motors to run.
    As Mindstorms is way too expensive?

  22. AverageSuscriber17 Avatar
    AverageSuscriber17

    Would it be easier …
    Would it be easier and/or more efficient to control motors that
    are connected to arduino but controlled by raspberry pi. I’ve already
    successfully done this but I was wondering if excluding arduino and only
    using RPi would be more beneficial. I’m working on converting a RC car into
    a car that will connect via wifi to be controlled by inputs on my computer
    and receive a live camera feed and later I plan on making the car
    autonomous by adding sensors.?

  23. DesignSparkRS Avatar
    DesignSparkRS

    Great VIDEO from …
    Great VIDEO from the RaspberryPiGuy on how to control motors with Raspbery
    Pi.

    Perfect for any robotics projects

    http://youtu.be/b4uhh_j8uR2?

  24. TheRaspberryPiGuy Avatar
    TheRaspberryPiGuy

    Glad you liked it!
    Glad you liked it!

  25. Christopher Gibson Avatar
    Christopher Gibson

    I have a robot that …
    I have a robot that has 2 6V motors (pololu.com/catalog/product/1060) and
    would like to achieve what you did in this video. I will be using a
    raspberry Pi. Can you recommend a servo board that I can use? Or will the
    one in the video be enough to power both the motors that I have?

Leave a Reply