I used a motor from a toy car (3v, but runs fine at 5v), and I tried to use it with my arduino. I have an output going to the base of a 2n3904 transistor (NPN, of course) through a 1k resistor, the emitter is at ground (from the arduino's ground port) and the collector is connected to a motor which in turn is connected to Vcc (from the arduino). The motor won't run unless given a little motion with my hand, that too runs very slow, and if I hook it up directly with 3v from two alkaline batteries, I have it going very fast without a problem or a push of my hand. What should I do? Get a power transistor? Employ a second battery pack for the transistor only?
Try the following:
Disconnect the end of the 1K Ohm resistor from the Arduino pin and connect it to +5 Volts. (Other connections remain as you described.)
What happens?
Regards,
Dave
Second battery pack for the motor only.
You don't want nasty motor voltage spikes arriving on your Arduino. Plus, as you've seen, there's not a lot of current available for turning motors.
The way you have it hooked up is fine - with one likely exception: you need an external battery or other power supply. Hook the positive of the supply/battery to the motor, the negative should be commonly tied to the ground with the Arduino. You will also likely want a small rectifier diode (1n4001 or 4004) across the emitter-collector junction (to prevent back EMF from destroying the transistor), and a small non-polarized disc capacitor (10uf maybe) across the motor's terminals to cut down noise.
Note that this will only allow you to drive the motor in a single direction; for control of the motor in two directions, you need an h-bridge (or a half-bridge if you use a dual-ended supply; but you rarely see this approach used - although a notable use of it was on the Milton Bradley Big Trak).
-
Isn't there a limit to BE voltage a 2n3904 can take? (in response to davekx)
-
I have a flyback diode, I forgot to mention that
-
A second battery back? The car's almost dead anyway with the weight from a nine volt, the arduino, and another PCB for an LCD!
EDIT: I crossed my fingers and hooked up 5v and the car flew out of my hands! : But, the transistor did get warm.
But, the transistor did get warm.
Hmm - the 2n3904 might be too small for the job, then - maybe something in a larger case might be better?
Also, your base resistor may be too small and allowing too much current (BE) to flow - try increasing it; you want just enough current to turn the transistor fully on, and no more (there are ways to calculate this, using the transistor's specs). The excess current is being disappated as heat.
You might also try to decrease the voltage to the motor (down to its original 3 volts if you can).
Isn't there a limit to BE voltage a 2n3904 can take?
That's maximum reverse voltage, which does not apply here. (The base-emitter junction of an NPN transistor does an avalanche-breakdown of you apply voltage that is too negative.)
Forward base-emitter voltage of a saturated transistor like a 2N3904 or a 2N2222 is a few tenths of a volt (which is why you need the resistor between the transistor base and the 5V Arduino output pin).
If the transistor gets too hot under these circumstances, the load is drawing too much current. It's time to get a larger transistor with a current rating commensurate with your motor. (Little battery-operated motors can draw more current than you might think.)
If attaching the resistor to +5 volts makes the motor go (the same +5 that powers your ATmega, right?) but attaching it to the Arduino output pin doesn't make it go as well, maybe the ATmega pin isn't set up to be an output. (It's easy to forget that you have to use pinMode() to set it as an output before you use digitalWrite() to set the bit high. Is it possible that you forgot?)
New topic:
A separate battery for the motor (3 Volts if it's that's the motor's rating) would be appropriate. Just connect the negative battery contact to Arduino ground and the positive to the motor, with the other motor contact to the collector of the transistor, as you now have.
Regards,
Dave