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

Leave a Reply

Required fields are marked *.