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 & Tria 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 679 subscribers
  • Views 7887 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
  • 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
Reply
  • 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
Children
  • 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
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 © 2026 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