How to Drive a DC Motor With Transistor - Arduino Tutorial

by codebender_cc in Circuits > Arduino

77331 Views, 123 Favorites, 0 Comments

How to Drive a DC Motor With Transistor - Arduino Tutorial

IMG_20150712_191618 (1).jpg

To drive a DC motor you need a larger amount of current than Arduino board can give. For that reason you must use a transistor. Transistors have limits and maximum specs, just be sure those values are enough for your use.

The transistor we are using for this tutorial is P2N2222A and is rated at 40V and 200mA, it just perfect for one toy dc motor.

Note: If your motor needs more current than 200mA you can just buy another transistor (ask the staff in the electronics store). The connections below are the same ;-)

In this tutorial we will spin a dc motor from one direction, with different speed. You will be able to control motor speed from serial monitor!

So, let's get started!

What You Will Need

Χωρίς τίτλο.png

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • 220 Ohm resistor
  • Transistor P2N2222A
  • Diode 1N4148
  • DC Motor

The Circuit

dcmotor.png

The connections are easy, see the image above with the breadboard circuit schematic.

Diode in circuit:

It is possible, when motor is spinning, suddenly turn off because the magnetic field inside it collapses, generating a voltage spike. This can damage the transistor, to prevent this, we use a diode which diverts the voltage spike around the transistor.

Transistor Pinout:

PNP type - front side view:

  • Collector
  • Base
  • Emitter

The Code

Screenshot_1.jpg

Here's the code, embedded using codebender!

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino board with this sketch. And that's it, you've programmed your Arduino with this sketch.

Press connect button below to start serial communication, try to send number from 50 to 255.

Well Done!

IMG_20150712_190916.jpg

You have successfully completed one more Arduino "How to" tutorial and you learned how to drive a DC Motor with Transistor.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!