element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Wiring a motor to the RPi?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 63 replies
  • Subscribers 672 subscribers
  • Views 7289 views
  • Users 0 members are here
  • help
  • rc
  • pi
  • control
  • raspberry_pi
  • please
  • motor
  • raspberr
Related

Wiring a motor to the RPi?

wallarug
wallarug over 13 years ago

What do I need?

 

I am told that I need some transitors.  I have a 12v powerpack and 2 x12v motors.  How do I set this up so that I don't blow-up the RPi and that I can control the motors through the GPIO?

 

I have a gertboard on the way but I would like to see if I can do it without it first.

 

I have little knowlegde about transitors and electronics but I do know how to build circuits.

  • Sign in to reply
  • Cancel
Parents
  • johnbeetem
    johnbeetem over 13 years ago

    If all you want to do is turn a small DC motor on and off, all you need is Gert van Loo's circuit in this thread's 7th post: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=13473.  The motor is driven by an NPN Darlington Pair (http://en.wikipedia.org/wiki/Darlington_pair), which is a great way to convert a small current into a really big current.  The three diodes in series are for people are afraid the Darlington pair might accidentally conduct from collector to base.  Gert says they're not necessary, but with 12V present I'd worry about framboise flambée and put them in. 

     

    The diode next to the motor coil is critically important.  It's called a flyback diode (http://en.wikipedia.org/wiki/Flyback_diode).  When you turn on the transistor, the flyback diode is reverse-biased and has no effect.  However, when you turn off the transistor, the magnetic field in the motor will cause current to continue to flow for a while.  If that current can't go anywhere (because the transistor is off), it will charge the node to a very high voltage and turn the transistor into a fuse and possibly destroy anything connected to the transistor.  It's how spark plugs work.  The flyback diode gives the current somewhere safe to go to prevent Spitzensparken.  The diode should have a current rating higher than the current through the motor.

     

    Gert doesn't give a value for the resistor between the GPIO and the base of the Darlington pair.  I'd start with 1 KOhm which gives you 3.3 mA.  But then, I usually start with 1K image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to johnbeetem

    Could someone confirm if the GPIOs are a ground or send out signals.  I think they are grounds but I can't be certain.

     

    If they are grounds, then how would the transitor work if it is a NPN?  wouldn't you need some positive current comming from somewhere?

     

    Sorry if these are silly questions but I am only learning.

     

    could someone also point me towards a sample code please.  I have heard that the code is the tricky bit.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • bodgy
    bodgy over 13 years ago in reply to wallarug

    The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 3v3 or be held at 3v3 and switch low. You get the choice of deciding which level equals on or off.

     

    If you decide low (0v) is to be off then if using an NPN transistor switching the output high (3v3) would turn the transistor on. If you wanted it the other way around you'd would then use a PNP. However in your case it probably is better for you to start by using an NPN transistor, as from a beginners point of view they work in a more logical fashion.

     

    Do you have a circuit in mind that you've seen where you could provide a link so that we can see if it achieve what you are hoping it will.

     

    Do you know the type of motor - voltage, current requirements you are going to use?

     

    As for code, I think the code for the Gertboard would be a good start especially as it also can run a small motor. I'll have to find the link but on the Pi forums is some example code. are you looking for code in Python or C ?

     

     

    Colin

     

    P.S. I live in the same country as you, so feel free to contact me if you need any further assistance.

     

    Message was edited by: Colin Barnard  corrected maximum voltage to show 3v3 instead of the incorrect 5v

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to bodgy

    bodgy wrote:

     

    The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 5v or be held at 5v and switch low. You get the choice of deciding which level equals on or off.

     

    If you decide low (0v) is to be off then if using an NPN transistor switching the output high (5v) would turn the transistor on. If you wanted it the other way around you'd would then use a PNP. However in your case it probably is better for you to start by using an NPN transistor, as from a beginners point of view they work in a more logical fashion.

     

    Do you have a circuit in mind that you've seen where you could provide a link so that we can see if it achieve what you are hoping it will.

     

    Do you know the type of motor - voltage, current requirements you are going to use?

     

    As for code, I think the code for the Gertboard would be a good start especially as it also can run a small motor. I'll have to find the link but on the Pi forums is some example code. are you looking for code in Python or C ?

     

     

    Colin

     

    P.S. I live in the same country as you, so feel free to contact me if you need any further assistance.

    Firstly, what firmware do I need to swap between 5v and 0v.  Currently I am using GPIO-0.2.0 which does not have this capability.

     

    Secondly, I would like it to be in python becasue I know that a lot better than C.

     

    I am thinking of using a motor rated at 12 volts, 14A. 

     

    wallarug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • wallarug
    wallarug over 13 years ago in reply to bodgy

    bodgy wrote:

     

    The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 5v or be held at 5v and switch low. You get the choice of deciding which level equals on or off.

     

    If you decide low (0v) is to be off then if using an NPN transistor switching the output high (5v) would turn the transistor on. If you wanted it the other way around you'd would then use a PNP. However in your case it probably is better for you to start by using an NPN transistor, as from a beginners point of view they work in a more logical fashion.

     

    Do you have a circuit in mind that you've seen where you could provide a link so that we can see if it achieve what you are hoping it will.

     

    Do you know the type of motor - voltage, current requirements you are going to use?

     

    As for code, I think the code for the Gertboard would be a good start especially as it also can run a small motor. I'll have to find the link but on the Pi forums is some example code. are you looking for code in Python or C ?

     

     

    Colin

     

    P.S. I live in the same country as you, so feel free to contact me if you need any further assistance.

    Firstly, what firmware do I need to swap between 5v and 0v.  Currently I am using GPIO-0.2.0 which does not have this capability.

     

    Secondly, I would like it to be in python becasue I know that a lot better than C.

     

    I am thinking of using a motor rated at 12 volts, 14A. 

     

    wallarug

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • bodgy
    bodgy over 13 years ago in reply to wallarug

    I'm about to go to bed, so this will be quick image

     

    To switch 14A you would be better off using either a MOSFET or an IGBT.  You'd need to find a BJT (an NPN transistor) that has a maximum collector current rating of more than 14A, probably 20A for a safety margin, that is to cover the possibility of keeping the transistor happy. 

     

    An MJH6284G  for example would require at least 800mA into its base to switch it on, so you would need either as has been suggested a Darlington instead, or a smaller transistor between the GPIO and the base of the main BJT to switch it on. There are other  BJTs that would work but they have a less beginner friendly footprint being TO-3s such as the PMD16K80.  Personally I would use what are called logic gate MOSFETS, or you could use a dedicated motor driver chip which would save you some work.

    Others of course might see things differently, there is always more than one answer to solve an electronics problem.

     

     

    Colin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • johnbeetem
    johnbeetem over 13 years ago in reply to wallarug

    Fergus Byrne wrote:

     

    bodgy wrote:

     

    The GPIO outputs can be high or low in output, in other words they can be made to switch from 0v (ground) to 5v or be held at 5v and switch low. You get the choice of deciding which level equals on or off.

     

    Firstly, what firmware do I need to swap between 5v and 0v.  Currently I am using GPIO-0.2.0 which does not have this capability.

     

    Secondly, I would like it to be in python becasue I know that a lot better than C.

     

    I am thinking of using a motor rated at 12 volts, 14A. 

     

    wallarug

     

    First, I'm sure bodgy meant that RasPi GPIO outputs can switch between 0V and 3.3V, not between 0 and 5V.  GPIOs can be configured as inputs or outputs, along with pin-specific special functions.  RasPi GPIOs  are not 5V tolerant.

     

    There's a nice treatment of RasPi GPIOs including software examples in C and Python at the RasPi Hardware Wiki: http://elinux.org/RPi_Low-level_peripherals.

     

    If you're switching 14A you might be better off with a mechanical or solid-state relay.  You'd still need an NPN transistor (or Darlington pair) or N-channel MOSFET to control the relay from RasPi, and you'd need a flyback diode across the relay.  This is assuming you just want to turn the motor on and off.  If you want to do variable torque and/or switch direction, you'll need more interesting circuits.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • bodgy
    bodgy over 13 years ago in reply to johnbeetem

    Ooops, sorry about the 5v confusion, I was still in 5v micro land, I forgot the Pi is a 3v3 beast.

     

    Thinking about it, a TOP or PROFET made for vehicle electronics would probably work here with the advantage it has short circuit, thermal protection and flyback all built in.

     

    BTS555 might be worth checking out.

     

    http://au.element14.com/infineon/bts555/transistor-profet/dp/4109260

     

    A small transistor would still be needed to be able to switch the PROFET on, and the collector of this transistor should be connected to the 12v rail.

     

    Here is a link to how you could set this up, however as John says, if you just want the motor to switch on and off then a small transistor driving a relay or solid state relay would eb the cheapest option.

     

    http://www.picotech.com/applications/pwm_drivers/#chap7

     

    Colin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to bodgy

    Just another Questions,

     

    How much current can each GPIO pin carry?  On the wiki it says "The maximum permitted current draw from the 3.3 V pin is 50 mA."  Does this mean in total or for each pin?

     

    How do you set the GPIO pins as 0v or 3v3. Also I have been unsuccessful in installing the python 0.3.1a GPIO library (http://pypi.python.org/pypi/RPi.GPIO/0.3.1a#downloads). It says it is a C extension so I don't know whether I have to install another library or what?

     

    Thanks for all this advice!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • johnbeetem
    johnbeetem over 13 years ago in reply to wallarug

    Fergus Byrne wrote:

     

    Just another Questions,

     

    How much current can each GPIO pin carry?  On the wiki it says "The maximum permitted current draw from the 3.3 V pin is 50 mA."  Does this mean in total or for each pin?

    50 mA is for the 3.3V power pin (P1-01) which is the output of RasPi's 3.3V regulator RG2.  You can use it for +3.3V ICs and pull-ups on an external board provided that the total current is under 50 mA.  There is also a 5V power pin (P1-02) which can be used for 5V parts or a regulator to get lower voltages.  The 5V pin is connected to RasPi's main 5V (TP1) and current comes from your power supply and must not overload polyfuse F3.  Be very careful not to accidentally short the 5V pin to any other P1 pin -- this could damage your RasPi.  If you're not planning to use 5V strip off a short piece of insulation and slide it over the 5V pin.

     

    According to http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29, the GPIO pins can be configured to drive from 2mA to 16 mA.  How to do this is not in the main BCM2835 peripherals data sheet, but may be in the supplemental data sheet referenced.  The GPIO software libraries should have a way to configure those pins.

     

    I don't know how to use the Python libraries.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to johnbeetem

    Is there a program that I can use to build circuits?

     

    Also, is there a program I can use to test python GPIO code?  So I tell the program that I have an LED connected  9which could be displayed on the screen) and then it can output the data?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to wallarug

    The first question is confusing. Do you mean a program that simulates a hardware circuit?

    To test the gpio, most people use the pi and a breadboard setup with some leds mounted on it.

     

    If you are looking for a program to draw the schematics of the circuits and design the pcb, you can try the eagle program.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to Former Member

    Luc Cool wrote:

     

    The first question is confusing. Do you mean a program that simulates a hardware circuit?

    To test the gpio, most people use the pi and a breadboard setup with some leds mounted on it.

     

    If you are looking for a program to draw the schematics of the circuits and design the pcb, you can try the eagle program.

    I am looking for a simulator.  I have a breadboard but I do not want to keep re-wiring it.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to bodgy

    How do I install the RPi-GPIO-0.3.1a library onto my Raspberry Pi?  This is very important right now so that I can code some LEDs.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • wallarug
    wallarug over 13 years ago in reply to Former Member

    Fergus Byrne wrote:

     

    How do I install the RPi-GPIO-0.3.1a library onto my Raspberry Pi? This is very important right now so that I can code some LEDs.

    i have installed the above python library.  But I still don't know how to wire the motor to the raspberry pi.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube