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
Arduino
  • Products
  • More
Arduino
Blog Working with motors: DC motors
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: organtin
  • Date Created: 3 May 2016 6:39 AM Date Created
  • Views 2506 views
  • Likes 5 likes
  • Comments 12 comments
  • dc motor
  • transistor
  • arduino
Related
Recommended

Working with motors: DC motors

organtin
organtin
3 May 2016

In one of my last posts I have shown how to drive a servo motor. Servo motors comes in two flavours: the standard servo motors can be set such that they reach a given position and maintain it; the continuous rotation servo can rotate continuously at a given speed.

 

DC motors are very similar to continuous rotation servo motors, in fact. With respect to the latter, DC motor technology is much simpler and, as a consequence, these motors are cheaper than servos. As suggested by their name, DC motors need just a DC voltage source to run, so there is no need to use any PWM pin. They just have two wires to be connected to a voltage source. The direction of rotation depend on how you connect the wires to the voltage source. Reversing the polarity of the power makes the motor run in the opposite direction. The speed of a DC motor depends on the applied voltage: the higher the voltage, the higher the speed. Motor specifications tell you in which voltage range it operates: below the minimum voltage the motor will probably do not move at all or they move with lot of difficulty; above the maximum voltage you seriously risk to damage it.

 

Some DC motor, as the one we used for our tests, comes with a gear embedded in their body: gears make the motors more powerful, but slower.

 

If, for any reason, you need to control the rotation of a DC motor using Arduino, in principle it would be enough to connect one of the motor leads to the GND pin and the other to any digital pin. Setting the pin to LOW the motor doesn't move. Setting the pin to HIGH the motor runs if 5V is in its range. Given the fact that the direction of rotation depends on the polarity of the voltage, inverting the wires makes the motor rotate in the opposite direction.

 

In some cases, however, this very simple schema cannot work: manifestly it does not work if 5V are not enough to run the motor; moreover, the maximum current that an Arduino pin can provide is 40 mA (but it is recommended to not exceed 20 mA) and it may not be sufficient to run the motor. In those cases you need an external power source. You cannot use Arduino as the power source, but you can use it as the driver of the motor, controlling an external power source used to feed the motor. Suppose, for example, that you need at least 9V to run your motor. You can use Arduino to realise a sort of switch that stays open until a given digital pin is set to HIGH. As soon as that pin flips from LOW to HIGH, the switch closes and the motor is connected to the power source.

 

Of course you can use a relays to this purpose, but we are going to illustrate the use of a transistor to obtain the same result. Understanding how to use transistors is always a good idea, even if you are not going to use them: knowledge is power!

 

Transistors can be thought as a sort of switches. In fact transistors may act both as amplifiers as well as switches, depending on how they are polarised. If you want to understand how transistors work in a non technical manner you can read my article published on 'The Physics Teacher' (Giovanni Organtini, "A flush toilet model for the transistor", Phys. Teach. 50, 221 (2012); http://dx.doi.org/10.1119/1.3694073). In order to understand this post you don't need to understand how transistor work: it is enough to know that they behave like a switch. The switch connects the transistor emitter with its collector and its operation is driven by its base. Consider the following circuit.

 

image

 

The Arduino board is used just to provide a digital signal on a given pin (pin 9 in the example). This pin is connected to a resistor (whose value is not very important: its purpose is just to limit the current flowing out of the pin) that, in turn, is connected to the base of a transistor. If no current flows to the transistor base, the transistor is said to be in interdiction and acts as an open switch between the emitter and the collector. In our schema the motor is connected to a 9V battery trough the transistor, but you can imagine the transistor being substituted by an open switch. The Arduino ground is in common with the 9V minus lead.

 

As soon as you make enough current flowing into the transistor base, the transistor goes in saturation and acts as a closed switch. In that case the transistor emitter (the lower lead with the arrow in the schema) appears to be short circuited with its collector (the top lead, connected to the motor). In this case the current can flow from the battery and feed the motor that starts running.

 

Below you can see a Fritzing model of the device where you can see that the base of the transistor is its central lead; the emitter is on the left, while the collector is on the right

image

Below you can see our actual setup.

 

image

In order to identify the collector, the base and the emitter of a transistor you must refer to its data sheet. There are common rules among producers, allowing you to identify the leads looking at the transistor shape (the one shown in the picture above is called TO-92). However, it is always a good idea to check the pinout on the specific transistor data sheet, because not all the manufacturers may use the same pinout for the same enclosure. The actual pinout, in fact, depends also on the transistor type.

 

There are two types of transistors: NPN and PNP. Transistors are made out of three semiconductor slices and semiconductors comes in two flavours: N-type and P-type semiconductors. In N-type semiconductors the current carriers are electrons, while in P-type semiconductors the current is due to holes (lack of electrons). In NPN transistors the base is made of a P-type semiconductor, while in PNP ones the base is an N-type semiconductor.

 

In the above example we showed how to use an NPN transistor. If you are going to use a PNP one, you should connect the collector to the positive lead of the battery and the emitter to the motor, while the second lead of the motor goes directly to ground.

  • Sign in to reply

Top Comments

  • kulky64
    kulky64 over 9 years ago +3
    You should put a diode in parallel with the motor (or any other inductive load) to prevent damage to the transistor by voltage spikes that are created when the tranistor opens.
  • shabaz
    shabaz over 9 years ago +2
    Regarding the last paragraph, this circuit needs an NPN BJT. PNP won't work, due to PNP being biased permanently on if the input is from an Arduino.
  • mcb1
    mcb1 over 9 years ago in reply to balearicdynamics +2
    zener diode of the correct value between the power and gnd of the Arduino power This might help, but it will not stop the pin from being damaged. If you want to use a PNP and the motor voltage is higher…
  • Robert Peter Oakes
    Robert Peter Oakes over 9 years ago in reply to dougw

    N Channel FETs or PNP Transistors... the only way to Motorvate image with ease

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • tonyboubady
    tonyboubady over 9 years ago

    Exactly same as my Smart Headlight concept, driving series of LEDs with NPN transistor here TI and Würth Elektronik LED RoadTest+ - The Schema - 5/10 once you have understand the basic concept then you can drive anything using transistors... image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 9 years ago in reply to balearicdynamics

    I mainly use FETs - I like the lower voltage drop and the high input impedance. I seem to always be trying to use less power and generate less heat.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 9 years ago in reply to balearicdynamics

    I always use NPN

    I do too.

     

    The risk of a collector to base short on a PNP is why an opto-coupler is good insurance.

    It is easy to implement, and provides the inversion needed to make a HIGH turn the transistor on.

     

    I consider it cheap insurance ...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 9 years ago in reply to mcb1

    BTW Mark, I always use NPN. But the case of the optocoupler sound a bit... extreme with low power level. Or the risk is independent ? Just asking because I am involved in a similar project just these days.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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