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 7772 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
  • Former Member
    Former Member over 13 years ago in reply to wallarug

    Look up an H Bridge circuit.  I have had good luck with this kit with an Arduino.  I made a roller robot.  I tried and failed with TIP102 and TIP107 but I am clumsier than most.  If you go this route,

    buy extra transistors in case you fry them.

     

    Look at http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/.  Follow the links to basic transistor etc.

     

    The H bridge would have one output for forward and one for backwards.  The kit controls 2 motors.

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

    Ken Seymour wrote:

     

    Look up an H Bridge circuit.  I have had good luck with this kit with an Arduino.  I made a roller robot.  I tried and failed with TIP102 and TIP107 but I am clumsier than most.  If you go this route,

    buy extra transistors in case you fry them.

     

    Look at http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/.  Follow the links to basic transistor etc.

     

    The H bridge would have one output for forward and one for backwards.  The kit controls 2 motors.

    Could you draw up a schematic diagram for me if I use this: https://www.adafruit.com/products/807.  My friend has informed me that a H-Bridge is required and I found this IC and I think that it could work nicely.

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

    I have not created schematics except with pencil and paper.  I noticed that his is a 5 Volt chip and the Pi outputs are 3.3 Volt.

     

    I am working on a schematic with 2N3906 transistors to level-shift the outputs.  If you power the motors off 5V as well, it avoids two power supplies.

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

    Motors are powered off 12volts.  Did you look at the Double H-Bridge IC I posted earlier?

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

    Here is the schematic.  JP1 is meant to be the motor.  I should mention that the transistor logically invert their signals.

    When the GPIO is high, the chip input is low. So from the Pi's perspective, they are active when they are zero.

     

    You need two power supplies.  The solarbotics board has an on board regulator to provide the +5 volts.

     

    The Pi only has one PWM output, so you could do PWM in software but get the motor going fast first.

     

    Make sure the motor fits within the chip's power output max or just buy extra chips.

     

    The 2N2222A2N2222A is cheap.  Buy extra.  I live in the US so I would get them here. http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_38236_-1.

     

    Or use Newark/element 14, or Digikey, or Mauser.

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

    Thanks Ken.  Great work.  I will test later

     

    What about the double H-Bridge chip in the earlier post?

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

    The schematic is for TI's L293D chip, which was posted above in a link from Adafruit.

    It is a dual H-Bridge motor driver.

     

    The E on the end of the part number is from the Eagle part library, but the pinout is the same.

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

    Thanks for informing this of that fact.

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

    Ken Seymour wrote:

     

    The schematic is for TI's L293D chip, which was posted above in a link from Adafruit.

    It is a dual H-Bridge motor driver.

     

    The E on the end of the part number is from the Eagle part library, but the pinout is the same.

    How can I get PWM working on the motors? Can you please give me instructions on software and/or extra hardware required (input device)  for PWM to work.

     

    Thanks for all your help so far.

     

    Hardware such as what gert used in his video (the slider at 3:40):

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

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

    @Ken

     

    There is an error in this diagram: pin 8 should be connected to 12V and pin 16 to 5V - why - because pin 16 is what ST (the chip maker) calls Vss and is the logic supply voltage and pin 8 is Vs which is the motor supply voltage.

     

     

    This circuit would be improved by changing the 100R resistors for a higher value, 2k2 would be fine and would reduce the current in the 2N2222A2N2222A transitors from 50mA to 2.3mA while still being able to pull the L293 inputs high. (They need 100uA max).

     

    Michael Kellett

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

    @Ken

     

    There is an error in this diagram: pin 8 should be connected to 12V and pin 16 to 5V - why - because pin 16 is what ST (the chip maker) calls Vss and is the logic supply voltage and pin 8 is Vs which is the motor supply voltage.

     

     

    This circuit would be improved by changing the 100R resistors for a higher value, 2k2 would be fine and would reduce the current in the 2N2222A2N2222A transitors from 50mA to 2.3mA while still being able to pull the L293 inputs high. (They need 100uA max).

     

    Michael Kellett

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

    Just an update on what I am going to use to built this circuit:

     

    2 x 12v motors

    1 x 12v power supply (batery pack)

    1 x L293D (double H-bridge chip)     http://www.adafruit.com/datasheets/l293d.pdf  < Datasheet

    1 x ULN2003 (Darlington Transistor - instead of normal transistors) http://www.jaycar.com.au/products_uploaded/ZK8855.pdf  < Datasheet

    Whatever restiors anyone suggests (I will buy when necessary)

    Headers & PCB

    1 x Raspberry Pi

     

    Can someone let me know if anything else is required.

    • 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