loading

Hello everyone,

In this instructable we'll be making our own motor driver using transistors.

In my last attempt to use transistor as motor driver I was unable to control the speed of the motor using it.

But, Thanks to valuable comments from instructables users who suggested me to use PWM pins to control motor speed and to improve the circuit. So, this circuit is able to control motor speed using PWM pins, protect arduino and other electronics from back emf and electrical noise generated by the DC motor.

Step 1: Gather the Parts

  1. An Arduino
  2. A breadboard
  3. A 220ohm resistor
  4. A 2N2222 transistor
  5. A IN4001 diode
  6. A 0.1 microfarad ceramic capacitor
  7. A DC motor
  8. A 9V battery
  9. Some jumper or hookup wires

Step 2: Wiring

Hookup all the components according to the circuit diagram shown above.

Why we need a A 0.1 microfarad ceramic capacitor in parallel with the motor?

When DC motors operate they produce a lot of electrical noise, The main cause of this noise is the brushes of the brushed DC motor.

These noise can interfere with the sensors and even impair the micro-controller.

That's why we need a 0.1 microfarad ceramic capacitor in parallel with the motor.

Why we need a IN4001 diode in parallel with the motor?

When the DC motor is turned OFF or current being changed across the motor, The motor generates Back EMF.

This back emf can damage electronics or can cause data loss.

To counter this we need a IN4001 diode in parallel with the motor.

Step 3: The Code

Upload the following code to arduino.

The following code runs the motor at a Higher speed for 10 sec and then lowers the speed for the next 10 sec.

int MotorPin = 10;

void setup()

{

pinMode(MotorPin, OUTPUT);

}

void loop()

{

analogWrite(MotorPin, 200); //Any value between 0 to 255

delay(10000);//Wait for 10 secs

analogWrite(MotorPin, 100); //Any value between 0 to 255

delay(10000);//Wait for 10 secs

}

Step 4: Done

Now Power the arduino and see your motor spinning with varying speeds.

Thanks for viewing.

Please write your questions or suggestions below.

very cool project buddy! I will use this in my latest project!
<p>Спасибо. Хороший урок.</p>
<p>info-Sam, thank you for posting this! I am new to Arduino stuff and looking forward to building on this instruct able as I work towards creating a small bot as a hobby.</p>
Nice work. Could you please suggest components that would control a small 12 V water pump? The pump is 1.5 A at 12v
<p>Why don't you try relays.</p><p>But you won't be able to control the motor speed. </p>
<p>Do you need to control the speed, or just turn it on and off? You'll need a higher power transistor, and a FET would be easier to drive. </p>
I am controlling the speed too.<br>Yes, but in this project I used small hobby DC motor that runs on a relatively small amount of current so I used general purpose transistor.
<p>The componentes would be the same as listed, but 1.5 amps using 12 volts would need a decent power source. Look for an old router power supply or some speakers powers supply, if they are 12v and 1.5amps (or greater amp) they would make the job.</p>
<p>Massive overkill to use an arduino for this. If you just want to control speed, a 555 timer circuit is WAY cheaper (about a 5-10 cents). If you want to control various intervals, a dedicated processor (ATTINY24/45/85 or ATTINY 13 - less than $1) will do the job.</p><p>For switching applications (PWM), especially in battery-operated circuits, a MOSFET is generally preferred over a BJT because it wastes less power.</p>
<p>Of COURSE its &quot;massive over-kill&quot;..</p><p>This is an INSTRUCTable.. it's meant to INSTRUCT or TEACH a process or idea..</p><p>It's NOT meant to mini-max or optimize a production item...</p><p>Indeed, the majority of the articles fall under the &quot;teachable moments&quot;...</p>
Well, in that case, why not go out and buy a new MacBook, a USB to serial converter, an arduino and a motor. That way you could have the MacBook send instructions to the arduino, which could then control the motor.<br><br>Oh wait!<br><br>Why not hire someone full time at $100/hour to watch the MacBook, and use a timer to alert them when they should adjust the motor speed.<br><br>Oh wait! Why not have a government department to set rules and conditions and regulations and...<br><br>Part of learning is understanding when a &quot;solution&quot; makes sense, and when it doesn't. If you need programmable motor control, an arduino isn't a bad first approximation. But if you just need motor control - well, maybe you ought to put an ad on line for motor speed watcher guy positions.
<p>Hahaha! Really funny dude, Your sarcasm is great!</p><p>#MacBookWatcher vacancy?- dial me</p>
Hope I would try it next. <br>Thanks for your suggestions.
<p>nice circuit, and very useful information. thanks for the detailed explanation about the need of use diode and capacitor... i'm a lot of cheap toy to make with this and arduino nano.</p>
Thanks!
<p>I'm wondering is there a way to code it to run for 10 seconds, pause 10, run in reverse 10 seconds, rinse and repeat?</p>
<p>It takes 3 more transistors and a bit more space on the breadboard. Look up references to H-bridge to get the details. You'll be using another output pin on the Arduino, and an input pin to switch directions. Also have to be careful about changing directions when the motor is running--you might let the smoke out of your electronics. Also watch out for the polarity on your electrolytic caps--they're exciting when you violate them!</p>
Yes that works. <br>Thanks.
<p>to run reverse in that kind of motor you need to rewire it the oposite way. So you will have to make a new different circuit. Stepmotors can do that, but the use more wires.</p>
<p>no need for a steppermotor, just an H-bridge or add a relay</p>
<p>not with this circuit. Either with an H-bridge as mentioned by others or ad a relay to switch the polarity</p>
<p>Looks like it would be quite easy:</p><p>https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing/arduino-code</p>
<p>Outstanding. Thank you so much for posting that. I've just begun my arduino adventuring and need to study up. Now I know where to look.</p>
Nice tutorial. But I have a problem with transistor. Its getting too hot and also motors not run in full speed.
Be sure that you are using small hobby motors that derives less current.
<p>now how to put a potentiometer to control speed?</p><p>Thanks for instructable </p>
<p>read a potmeter on the analog port, map the outcome to 255 (or divide it by 4) and use that as input to the pwm statement</p>
<p>google &quot;motor speed control LM555&quot;.</p>
Nice PWM motor controller! Did you consider using a power transistor?
<p>I agree a Darlington would be a little more reliable in case of heat!</p>
Hello,<br>nice explanation about the capasitor and diode.
Thanks for your feedback.

About This Instructable

21,996views

359favorites

License:

Bio: ........ :)
More by Anshu AR:H Bridge Motor Driver For Arduino Using Transistors How To Use A Piezo To Produce Tone : Basics Build Your Own Motor Driver 
Add instructable to: