Maker Pro
Maker Pro

Controlling a motor with a transistor and a PIC

Hello again, I'm working on a new PIC experiment in which I'm trying to
control a motor. I'm ignoring the speed of the motor and just trying to
have it be either on or off. The first thing that I tried was just to
attach one lead of the motor to ground and the other to an output pin
on the PIC. I quickly found out that this does not work. I assume that
this is because the chip cannot provide the current that the motor
requires. I then figured that the way to do this was to use a
transistor. I did a bit of reading on the web and it seemed like this
was the right idea. I devised the following circuit for how to do this:

http://img151.imageshack.us/img151/8270/circuit7dx.jpg

With this design I need to put the pin low in order to turn the motor
on. It works great if I use an LED, but with the motor in place it acts
sort of strangely. I must be ignoring something. Perhaps I'm using the
wrong transistor. I'm using a 2N3906 and a high of about 3V.

Thanks for any input!

Brick
 
I had looked at a very similar diagram (similar to the most relevant
one in that link) and tried the diode but it didn't help. What I had
neglected to see is that I would need a resistor inbetween the chip and
the transistor. The thought had actually crossed my mind earlier, but
when I tried it I was using too large of a resistor so it didn't work.
Can't get enough of those current limiting resistors.

Thank you,
Brick

purple_stars said:
http://www.rev-ed.co.uk/docs/picaxe_manual3.pdf

Hello again, I'm working on a new PIC experiment in which ..
[snip]
 
M

Mike

Jan 1, 1970
0
Hello again, I'm working on a new PIC experiment in which I'm trying to
control a motor. I'm ignoring the speed of the motor and just trying to
have it be either on or off. The first thing that I tried was just to
attach one lead of the motor to ground and the other to an output pin
on the PIC. I quickly found out that this does not work. I assume that
this is because the chip cannot provide the current that the motor
requires. I then figured that the way to do this was to use a
transistor. I did a bit of reading on the web and it seemed like this
was the right idea. I devised the following circuit for how to do this:

http://img151.imageshack.us/img151/8270/circuit7dx.jpg

With this design I need to put the pin low in order to turn the motor
on. It works great if I use an LED, but with the motor in place it acts
sort of strangely. I must be ignoring something. Perhaps I'm using the
wrong transistor. I'm using a 2N3906 and a high of about 3V.

Thanks for any input!

Brick


Your biggest problem is that the 2N3906 is the wrong polarity for the
circuit shown in your link. You need an NPN not a PNP.

If it's a really small motor use a 2N3904 instead. Use a 1k base
resistor and a 1N4001 diode across the motor. A 2N3904 can only handle
about 200mA max, so if your motor draws more than that you'll probably
need an NPN darlington power transistor.

You will be much better off to use a power mosfet as shown at the
bottom of page 7 of the picaxe manual. The purpose of the diode is to
conduct the current generated by the magnetic field in the motor as it
colapses when the motor current is switched off. Without the diode a
fairly high voltage is generated by the motor when it's switched off
and that high voltage can damage the mosfet and maybe cause the pic to
get all confused. The diode needs to be a small pwer type such as a
1N4001, a 1N914 or similar signal diode may not withstand the stress
from the back emf, depending on the motor. The diode must be rated for
the max motor supply voltege.

Any type of N channel logic level mosfet rated to handle the voltage
and current requirments of the motor will work.

Logic level just means that the mosfet will be have it's lowest on
resistance with only 5v between the the source and gate pins. If it's
not a logic level mosfet it will require about 10V to full turn on.

I may be wrong, but the IRF530 shown being switched directly from the
pic pin is poor choice because the IRF530 requires more than the 5v
output from the pic to fully turn on.

It's also good practice to insert a low value resistor between the pic
pin and the gate of the mosfet. A 10ohm or so would be fine. Locate
the resistor close to the gate pin of the mosfet. The resistor is just
to help prevent high freq oscillations as the mosfet switches and the
circuit will work without it, but may generate rf interference as the
mosfet switches. The point maked +6 can be any voltage needed for your
particular motor.

Using either an NPN bipolar transistor or an N channel mosfet will
mean that the motor will be turned on when the pic pin is high.

Mike
 
E

ehsjr

Jan 1, 1970
0
Mike said:
Your biggest problem is that the 2N3906 is the wrong polarity for the
circuit shown in your link. You need an NPN not a PNP.

If it's a really small motor use a 2N3904 instead. Use a 1k base
resistor and a 1N4001 diode across the motor. A 2N3904 can only handle
about 200mA max, so if your motor draws more than that you'll probably
need an NPN darlington power transistor.

You will be much better off to use a power mosfet as shown at the
bottom of page 7 of the picaxe manual. The purpose of the diode is to
conduct the current generated by the magnetic field in the motor as it
colapses when the motor current is switched off. Without the diode a
fairly high voltage is generated by the motor when it's switched off
and that high voltage can damage the mosfet and maybe cause the pic to
get all confused. The diode needs to be a small pwer type such as a
1N4001, a 1N914 or similar signal diode may not withstand the stress
from the back emf, depending on the motor. The diode must be rated for
the max motor supply voltege.

Any type of N channel logic level mosfet rated to handle the voltage
and current requirments of the motor will work.

Logic level just means that the mosfet will be have it's lowest on
resistance with only 5v between the the source and gate pins. If it's
not a logic level mosfet it will require about 10V to full turn on.

I may be wrong, but the IRF530 shown being switched directly from the
pic pin is poor choice because the IRF530 requires more than the 5v
output from the pic to fully turn on.

It's also good practice to insert a low value resistor between the pic
pin and the gate of the mosfet. A 10ohm or so would be fine. Locate
the resistor close to the gate pin of the mosfet. The resistor is just
to help prevent high freq oscillations as the mosfet switches and the
circuit will work without it, but may generate rf interference as the
mosfet switches. The point maked +6 can be any voltage needed for your
particular motor.

Using either an NPN bipolar transistor or an N channel mosfet will
mean that the motor will be turned on when the pic pin is high.

Mike

I think he said he's using 3 volts as a high - rules out the mosfet
unless he level converts. A TIP 120 would be fine assuming a
supply for the motor a couple volts higher than it needs.
Vce sat is around 2 volts as I recall. If the motor draw is small
enough, one of the hot zetex bipolars would work, maybe even
a transistor scrounged from a disposable camera.

Ed
 
M

Mike

Jan 1, 1970
0
I think he said he's using 3 volts as a high - rules out the mosfet
unless he level converts. A TIP 120 would be fine assuming a
supply for the motor a couple volts higher than it needs.
Vce sat is around 2 volts as I recall. If the motor draw is small
enough, one of the hot zetex bipolars would work, maybe even
a transistor scrounged from a disposable camera.

Ed

Oops, I missed that 3v thing, but yeah, something like the ZTX1051
should work up to a couple amps.


Mike
 
Top