Using Arduino and TIP120 to control a DC Motor

If you are in a need to control the speed of a Dc Motor for one of your projects but you don’t care about the direction then the easiest and cheapest way is through a Darlington transistor like TIP120.  Because Arduino cannot supply enough power to the motor(only 40mA maximum) we have to use external power supply. A small dc motor will  require around 500mA at full speed so if you try to drive it from an Arduino pin probably a damage would occur. And of course there is a possibility your motor may require 12v or higher voltage so external power supply is the only way to go.

Transistors are like digital switches, they have 3 pins , the Collector(C), the Base(B) and the Emitter(E). Whenever we apply voltage to base, the transistor turns on and allows current to flow through emitter and collector. So by applying small current we can control larger currents. In our case we are going to use digital pin 9 which is PWM. This means that it turns high so many times as the value we pass. More about pulse width modulation here. In this way we are controlling the speed. Remember that the value we are getting from the potentiometer ranges from 0 to 1023 and pwn needs to be from 0 to 255, so we need to convert it. Just divide the reading value by 4.



Also in our circuit we are going to use a diode for protection. Diodes protect from reverse voltage and its a good idea to use them in our circuits.

Below is the schematic you can use:


And the code is very simple:

So if you connected everything ok you should have something similar to this:




Now power the circuit and change the value of the pot. You should see the motor spinning.


A small video from my circuit  below.


Good luck 🙂

4 thoughts on “Using Arduino and TIP120 to control a DC Motor”

  1. Pingback: Add bluetooth control to a toy truck |
  2. Trackback: Add bluetooth control to a toy truck |
  3. Larry Blanchard says:

    I tried this circuit with 2 differences. I’m replacing the battery shown with a 12V regulated power source as most model locomotives run on 12 volts. And I’m controlling the analog output with up and down pushbuttons instead of a pot. The results are confusing me. If I do an analogWrite with a value of 1, I get a measured output of just under 0.02V. Just what it should be.

    But as soon as the TIP120 sees that 0.02V, the output instantly jumps from zero to 6.5 volts! Gradually increasing the output from the PWM pin causes a gradual increase in the TIP120 output just as it should.

    I’ve checked and re-checked the soldered involved connections and all appear OK. I’ve checked the TIP120 resistances against a second TIP120 and they are approximately the same.

    Any suggestions?

  4. Larry Blanchard says:

    Y’know, for someone who was a very good SCADA software designer/writer, I’m remarkably stupid when it comes to hardware. I was measuring the output at the board – no load. As soon as I put a load on it at the track – an old loco with an open frame motor – everything worked as it should.

    So please ignore my previous lament.

  5. randolph Maxim says:

    Your diagram shows the diode going from ground to the collector. The site listed below shows the diode going from the collector to positive voltage. IOW, across the motor leads. Which is correct? Or are they equivalent?

Leave a 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.