Voltage across PN2222 (and base resistor)

Most tutorials online on how to connect a motor to arduino have a circuit similar to the one I made. The problem is I can't get 5V across the transistor when using a resistor between the base and the arduino PWM pin.

This is how my circuit is at the moment with the voltages measurements (external power supply is 5V):

If I remove the resistor, the motor gets the full 5V, but I read that this means it could be drawing all the power from the arduino instead of from the power supply.

This is how my circuit is at the moment with the voltages measurements (external power supply is 5V):

Well that is blank so we have no idea.

Please read this:-
How to use this forum
It will tell you about attaching an image file.

nexflatline:
The problem is I can't get 5V across the transistor

Specify "across the transistor"? A transistor has 3 legs, across refers to 2 which leaves 3 options (6 if you count polarity) for across :wink:

And the drawing is what we call in the business a Fritzing (breadboard) mess. Without pinout of the exact transistor you used I'll just have to assume you connected the resistor to the base, emitter to GND and collector to the motor. Proper schematic, even a quick hand drawing, is much more useful.

What I do see is that you have no flyback diode across the motor. So you might have killed the transistor.

OK now I can see the diagram.

If I remove the resistor, the motor gets the full 5V,

Do you mean short it out? That would imply the transistor is still working but you are not supplying enough base current. With the resistor in you will see 0.7V across the base to ground.

Try reducing the resistor to 100R.
How much current is the motor taking?
Yes you need a flyback resistor.

I would check that you have correctly identified the emitter and collector as a low gain is the symptom of getting those the wrong way round.

I would check that you have correctly identified the emitter and collector as a low gain is the symptom of getting those the wrong way round

I would also ask if you have a DMM and know how to use it to test a transistor on diode scale ?

If this is, indeed, a PN2222, and if your Fritzing is a true representation, then your transistor is connected wrong.

If you pop it out, and turn it 180°, and plug it back in, it should be facing the right way.

As for your "5V across" comment, when juxtapositioned with your resistor fiddling, it sounds like you have a misconception about how a Bipolar Transistor is "biased".

The thing to know is that a bipolar transistor is a "Current Amplifier". Thus, it's the current on the input, that makes it "go". If you try to put 5V across the Base-Emitter junction, you will either fry the transistor, or you will severely tax whatever is trying to supply that 5V -- in other words, somebody gonna suffer! In fact, if you try to do that with an Arduino output, there's a good chance you'll burn it out!

OK, so what is the proper way to bias a bipolar transistor? Depends on how you want to use it, but lets just talk about using it as a "switch". Like I said, before, a bipolar transistor amplifies current. So, to figure out what current to apply on the "input" [the Base-Emitter junction], we need to start with how much current we want to switch. In your case, that will be whatever maximum current that motor will be drawing -- and the maximum current will, invariably, be the start-up current [and actually the stall current, which will be nearly the same]. So, first of all, I'm going to assume you meant a "2N2222A" [slightly better than a 2N2222], which is rated a 625mW MAX, so rule of thumb, half that for, lets say 300mW.

Figure 4, of the ON Semi datasheet, shows around 210mV for a Collector current of 500mA, when the base current is at 40mA, the ABSOLUTE MAX current an Arduino output should source. That amounts to a power dissipation of:

P[sub]D[/sub] = 500mA * 210mV = [b]105mW[/b]

So, well within the 2N2222A's 300mW power handling capability. So, that would be the ABSOLUTE limit of using this transistor, with an Arduino, as a switch. I, personally, don't like demanding more than 20mA from my Arduino outputs :wink:

So, back to biasing that transistor! Let's say your motor needs a half an amp to get it running. And, let's say we don't mind torturing our poor little Arduino, by forcing it to supply 40mA to the base of that transistor, then, the math would be as follows:

R[sub]Base[/sub] = (5V - VBE)/40mA = (5V - 0.7)/40mA = [b]107Ω[/b] -- or next standard value up:
** **110Ω** **

Now, a note or two about something called Beta, and how that figures into the relationship between drive current [what flows through the Emitter-Collector junction] and Base current [what flows from Base to Emitter]. Beta [often, the Greek letter
** **ß** **
is used to indicate "Beta"] is the ratio between the Collector-Emitter current, and the Base-Emitter current. There is the Maximum Beta, called the hFE. Then, there is the Beta for setting optimal conditions for switching. Most datasheets recommend a Beta of 10 for switching [sometimes it's a little more, like 15 or 20]. What's going on, here, is, you want the Collector-Emitter "saturation" voltage to be as low as possible ['cuz the higher that voltage is, the more power gets lost in the transistor, and thus is not delivered to the thing being switched]. And, the higher the base current is [up to, of course, whatever current will fry the Base-Emitter junction], the lower that Collector-Emitter voltage is going to be. BUT, there is a tipping point, where a large amount of current, into the Base, isn't going to make a significant difference in the Collector-Emitter voltage, and it becomes a matter of silly waste.

So, that tipping point is, generally accepted to be a Beta of around 10. So, if you need to drive something that needs 2A, then you'll need around 200mA on that Base. At, 1A, the Base will need 100mA, etc. [dare I say it? It's all about dat Base -- ooooh! Couldn't resist!!]

And, that, my friend, is why, if you need to drive something that needs more than around a half an amp -- consider using a MOSFET.

BTW: you might have noticed that in my little thought experiment, I set the Beta to:

[b]ß[/b] = 500mA/40mA = [b]12.5[/b]!

Just wanted to see if you were paying attention! And, to show that you don't, necessarily, have to stick to a Beta of 10, even if the datasheet recommends it -- be an engineer, and fudge a little, now and then :wink:

BTW2: In case you're wondering what that resister is actually doing -- it's, essentially, converting Voltage into Current. The Arduino output is a fairly constant Voltage that supplies varying current, as needed -- it, isn't, really, designed to deliver a specific current. The Base, on a bipolar transistor, requires a specific current -- which is way a conversion is needed. The resistor takes the Arduino's output voltage, and sets it to a specific current. That's the simple explanation. There are a lot of details, like the fact that the Output voltage isn't exactly constant -- it varies a little as the current changes, and then there's that Base-Emitter voltage, and how it behaves in the real world, etc. But, that's a whole different, rather complex, conversation, and actually, for your purposes, inconsequential.

...and, I took another look at your Frizing, and noticed the 0.68V measurement, across the Motor. That might be due to the motor demanding more current than those batteries can deliver. Also, if you have this wired the way your diagram shows, the potential for large contact resistance is very high, and large contact resistance will, very much, reduce the amount of voltage that reaches the motor.

Thank you @ReverseEMF for the class and others for pointing out my mistake in inverting the emitter and the collector (dumb mistake, sorry!).

I have also calculated the base resistance and got 220ohms considering the motor has a resistance of 25ohms and using a beta of 12. I hope I did it right (so far it's working). This motor takes only 120mA on 3V, but I have no idea how it scales to 5v.

This motor takes only 120mA on 3V, but I have no idea how it scales to 5v.

Measure the resistance of the motor when it is stopped and out of the circuit. Use ohms law to calculate the current at 3V and you will see it is higher than 120mA. This is called the stall current and is the peak current the motor takes when starting up or when it has so much load that it stalls.

You can use the same reading to calculate what the stall current is at 5V.

However you can not calculate the unloaded free running current because you don’t know things like the rotor mass and the bearings friction.