BLOG > Tutorial 5 for Arduino: Motors and Transistors

This tutorial was featured on the official Arduino blog on 3/9/2011

This week, we’ll finally be using the Arduino to control some motors!  First up, we’ll control a standard DC motor running off a 9V battery with the help of an NPN transistor and a PWM (Pulse Width Modulated) signal from the Arduino.  Next, it’s onto 180 degree servo motors, which we will power on an independent 5V rail using a voltage regulator.  We’ll control the servo using a PWM signal from the arduino, and I’ll show you how you can turn analog distance readings into precise angles for the servo to turn to!

I mention in the video that you can control DC motor direction using an H-Bridge.  If you want to wire that up, take a look through this Wikipedia article, and read through this tutorial.

If you want to learn more about analog input filtering in software, check out this example code.

The Arduino Contest has been extended!  So don’t forget to submit your project.


You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.


301 comments

  1. I have to make a lift with college project and have a big problem of making the lift moving slowly
    i have used a toy car motor
    using 3 volt battery
    swiches to do forward and reverse

    still motor goes up very fast and come down very quick , how to slow down

    pls give a ideas , no time to wait need to send project by friday 19 september 210 14 thanks

    1. use stepper motor for more accurate movements. it has high torque and bi-directional control.
      u can use 12v for car motors. use L293D for both speed and direction control.

  2. I am working on the Chapter4 tutorial in your book and am having an issue with the servo part. I am using a NES-507 servo. As soon as the code myServo.attach(SERVO); is executed my servo rotates as far as it can and continues to try and rotate further causing the servo to start heating up.

    I have triple checked everything and all seems connected correctly servo wires are orange, red, brown, control, power, ground respectively. I am wondering it the issue is because the servo may be an old analog type and not digital.

  3. I am trying to run the initial DC motor tutorial (Exploring Arduino Chapter 4) that ramps the DC motor up and down via the Arduino code. Using the components from the official Arduino starter kit (1N4007 diode, 6/9V DC motor, BC 547B transistor, 1 microfarad electrolyte capacitor [Radio Shack] and 1K resistor), what could be the possible sources of error in my circuit? I have taken a digital multi-meter and I am reading values of a maximum of 2 volts at the DC motor. I have went through the wiring half a dozen times and everything looks proper according to the tutorial schematic. There is a low humming emitted when the sketch ramps up and down. This I believe is verification the code is not an issue just the amount of current the motor is receiving. I have tested the 9V battery and it is putting out 9V. Any suggestions at this point would be appreciated. Thank you.

  4. Hi there, me confirming also. One of the best books I’ve purchased lately about arduino motors. Thanks, worth every penny. Matija from Slovenia.

  5. Can I power 4 SG 5010 Tower Pro using the same single 9V battery and single regulator?
    Or do I need separate regulators for each?
    I cannot see the current ratings of the regulator and the motor too.
    Thanks!

  6. Thank you very much for these very important tutorials and specially for your complete book “Exploring Arduino: Tools and Techniques for Engineering Wizardry”…………..

  7. I have 4 DC toy motors connected to the L293D connected to HT12D. It has a IC7805 to regulate the voltage, I am supplying approx. 18v from 4 Li-ion batteries in series. The motors rotate slowly and jerk suddenly, and this keeps on happening throughout the process, i could not solve this latching problem. Can you please write me a solution?

  8. Hi sir,I have been using l293d ic to run 9v motors.what if i use 9v battery of 1.5 amp at l293d ic to run 9v motor.Does it going to work or damage both ic and motor????

  9. Hi ,

    If I use a non-grounding system breadboard ( normal breadboard ), can I do the project successfully?

    Or then is there any problem with my other components that related to this project?

    Please help

    Thanks , have a nice day

  10. Im having an issue with the circuitry on Figure 4-3, I’ve wired it up exactly the way the book says as well as a few different configurations which all amount to the same thing, and it works in terms of the motor runs when its in the 5V pin which is where the book says to test before moving on but as soon as voltage is applied to the base of the transistor allowing current flow from the 9V battery the transistor gets incredibly hot within a couple secs, in fact before I even realized it was doing that I burnt one out. Ive tried multiple things increasing the size of the resistor in between the 5V output and the base from 1k to 10k which slows down the overheating but only for a couple of seconds and also doesn’t gain a response from the motor as consistently. Ive also tried just attaching the base to a dc regulated power supply instead of the Arduino’s set 5V and slowly increasing the voltage until it lets enough current through that the motor runs which ive found the transistor can do with only about 1.5 volts but even then the transistor gets incredibly hot within a few seconds, Ive also made sure to clear any code on the arduino that could somehow cause this. If anyone can tell me why this is happening and how to fix it, I would appreciate it also amongst all of this the motor doesn’t always turn on consistently either, it seems very temperamental

  11. I was clicking through, browsing stuff.

    One suggestion:
    Your link ‘schematics’ points to a ZIP file.
    I think it would be clearer to readers if the type of link a articulated, ie., zip file, external/new browser window.

    I think it would save some frustrated clicks.

Leave a Reply to sejuta mp3 Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement