Introduction: How to Drive a DC Motor With Transistor - Arduino Tutorial
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!
Step 1: What You Will Need
For this tutorial you will need:
- Arduino uno
- 220 Ohm resistor
- Transistor P2N2222A
- Diode 1N4148
- DC Motor
Step 2: The Circuit
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.
PNP type - front side view:
Step 3: The Code
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.
Step 4: Well Done!
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!
1 Person Made This Project!
- Famagroup made it!