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.


  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

    • 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. that npn transistor is the one you used in your video tutorial?

  4. Can u tell mi how can I switch on and off projector by interfacing arduino…???

  5. Pingback: Bluetooth modules on the way :):):) | KYchem

  6. 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.

Leave a Reply

Required fields are marked *.