I need help running a small DC motor with the arduino

I can't seem to figure this out, and I know it must be simple enough to do.

I have the arduino pin 9 connected to the base on a p2n2222a transistor through a 22K resistor. I connected the 5V and ground to the rails on my bread board. The collector is connected to ground, and the emitter is connected through my DC motor to the positive rail. I also have a diode connected in parallel across the motor as you should do with any inductive load.

Nothing happened when I powered on the arduino and wrote some code to turn pin 9 on. (I tried using USB power and a wall wort)
I wasn't positive that I knew my collector from my emitter, so I switched it and still nothing.

I measured the current through the transistor circuit and it was at about 5 mA, which obviously isn't enough to run the motor. And to top it all off my ATMega was getting really hot, so I unplugged it and am now stumped.

Here is a picture of my circuit set up. Any advice?

Hello,

if you didn't make a mistake on the transistor reference, and if I got the right manual off of the internet, that is an NPN transistor.
Therefore, the collector should be connected to 5V and the emitter should be connected to the ground. I'd use the motor connected on the collector side instead of the Emitter side... but it should work either way as long as it is powered properly.

By the way, do remember to reverse the diode, otherwise you'll be "short circuiting" the motor.

The resistor you've mention is pretty high,
put something 220 Ohm - may be 300 Ohm

Here's an example circuit of an NPN transistor like 2N2222 driving relay to drive a higher current motor.
Put your smaller motor between +5 and the collector.

The collector is connected to ground, and the emitter is connected through my DC motor to the positive rail

The 2n2222 is an NPN

"And to top it all off my ATMega was getting really hot, so I unplugged it and am now stumped."

Usually a good sign that ATMega has been damaged by excessive current draw. Might be dead.
With external stuff unhooked, does a basic sketch like Blink upload & run?

Thanks for the answers guys. I dropped the resistor and put the transistor in the right orientation, and still nothing. I also checked to make sure it still runs the blink sketch, and it does.

I then disconnected everything from the arduino, loaded the blink sketch and just connected my multimeter to measure how many volts it is putting out. Here is the strange thing, most times I measured it, 5.6V high, 0V low, but sometimes when I measured it, there would be 1.2V high and 0V low. Also it once read 3.5V high. What does this mean? Did I fry my ATMega?

Since I was worried my pins did not work, I connected the base through a 330 resistor directly to my 5V out, and the circuit still did not work. I tried multiple transistors. I was able to get a LED blinking through the transistor, but there was still not enough current to drive a motor.

I watched this video: Transistor Amplification - Arduino Workshop Project Video #2 - YouTube and did everything he did exactly, and my motor did not run. I have no idea what to do next.

A DC motor could be anything from a phone vibra to a diesel truck starter motor.
You need to find out the characteristics of your motor.

I watched this video: Transistor Amplification - Arduino Workshop Project Video #2 - YouTube and did everything he did exactly, and my motor did not run. I have no idea what to do next.

ok well did you connect the collector and motor to the 5v pin on the arduino and not the digital pins? Also what kind of motor is it?
If you have access to a multimeter measure the current the motor draws when it is connected DIRECTLY to the power supply, that means putting the multimeter in SERIES with the motor and battery/power source.

Laslty, it depends on what power source you are using for your arduino. If you are using something higher than 5v then the arduino's regulator must work harder to bring it down to 5v. That is probably why it gets so hot.

Luckily I had a problem similar to yours and I have a whole post about it and my trials and it happens that I got everything to work.

Here's the link: http://arduino.cc/forum/index.php/topic,54761.0.html

@polishdude20

Thanks for the response. I did try connecting the transistor directly to the arduino 5V out. It is a pretty small DC motor, 1.5V if I remember correctly. I measured the current draw on the motor connected directly to a 9V battery and it was pretty high, about 650 mA if I remember correctly. The 2n2222a is rated to 600 mA, but I figured that would be enough to run the motor just a little slower. Is this logic wrong?

The ATMega itself was getting hot, not he voltage regulator. I am guessing this means it was drawing too much current through itself, which makes no sense to me.

I read through your thread, you found out you just needed to use MOSFETS? Maybe I will go buy some of those tomorrow.

sirphilip:
@polishdude20

Thanks for the response. I did try connecting the transistor directly to the arduino 5V out. It is a pretty small DC motor, 1.5V if I remember correctly. I measured the current draw on the motor connected directly to a 9V battery and it was pretty high, about 650 mA if I remember correctly. The 2n2222a is rated to 600 mA, but I figured that would be enough to run the motor just a little slower. Is this logic wrong?

The ATMega itself was getting hot, not he voltage regulator. I am guessing this means it was drawing too much current through itself, which makes no sense to me.

I read through your thread, you found out you just needed to use MOSFETS? Maybe I will go buy some of those tomorrow.

yes but my problem was that the transistors where getting too hot and not the atmega itself. hmm. I also had a 1k resistor in series with the base of the transistor, try that. Also it would help if you posted some code maybe? The MOSFETs I use I found in an old UPS
(Uninterruptible power supply) and they are the IRFZ44V, I know how confused I was when I was trying to buy parts and didn't know which ones exactly s there's that name for you, I'm sure there's other equivalent ones that will work but there ya go.

Oh and that logic isn't wrong your right, at 9 volts the current averaged at around 650 mA so approximatly at 5 volts lets say the current would go down to around 350mA at 5v using ohms law so yeah that should be fine, BUT, you might find that the motors use maybe almost an amp when they spike right when they start from a full stop. Check the current through the motor again with 9v or 5v if you want, and this time, like crossroads told me in my post , measure the current while the motor is stopped with your fingers, then also check that spike in the current when the motor first starts from a stop. Because if it does that you may find that the transistor can't provide that high spike current to get the motor to even start.

Lastly, try and "help" the motor by spinning it with your fingers while you have the transistor providing current.

sirphilip:
Here is a picture of my circuit set up. Any advice?
http://i.imgur.com/EKZ8n.jpg

I've got a board like that. The black sides are made of metal (aluminium I think). It looks from the photo the metal side is very close to, if not touching, a row of pins on the side of the Arduino. That won't help if it does.

Also judging by the photo you have run Vin to the minus (blue) rail, and Gnd to the positive (red) rail. That's OK if you are consistent, but as long as you don't get confused later on.

CrossRoads:
Here's an example circuit of an NPN transistor like 2N2222 driving relay to drive a higher current motor.
Put your smaller motor between +5 and the collector.

Crossroads, I always like your posts because I often learn something new from them. :slight_smile:

Just a question though, in the circuit you posted you had the load between +5 and the collector. What would the practical difference be if you had the load between emitter and ground? The same current, roughly, would flow through it wouldn't it? Or are there subtle reasons why you wouldn't do that?

One way to think of BJT (NPN & PNP) is like this for the way we using them as digital switches:

NPN transistors like to sink current, so have the emitter to ground.
PNP transistors like to source current, so have the emitter tied to +V.
This has to do with the way current froms the base and out of the transistor.
Effectively the voltage difference between base and emitter is hosed when you try to source a high voltage out of the emitter vs having the emitter at basically ground in an NPN, and similar for a PNP.

http://www.opamp-electronics.com/tutorials/introduction_3_04_01.htm
This is a good explanation. The arrows for current flow are backwards from how we normally think of them - from electricity going from positive to negative. The electrons actually from the negative terminal of a battery to the positive for example.