Poweroff the PING

Greetings!

I'm building a battery powered project that includes a PING sensor from Parallax. With the PING sensor powered, the project uses 43 mA. With the PING sensor not powered, the project uses 23 mA. A very big difference.

The vast majority of the time the PING sensor is not needed so I've decided to control its power. This seems like a good way to accomplish the task...

http://www.arduino.cc/playground/uploads/Learning/multiple_leds2.jpg

...with the PING substituted for the LEDs. I used a 2N3904 for the transistor (because that's what I have) and a 1K resistor for R1. It's working very well.

Is 1K a good choice? Will a different resistor reduce the PING-on power consumption, the PING-off power consumption, or the overall power consumption? Does it make any difference what resistor I use?

I've searched for answers but I honestly don't know if I'm even searching for the right thing. Some people say use 1K, some 3.3K, some 10K. The schematic shows 1K or 2.2K. There are a few transistor-resistor calculators but I don't have a clue what to enter for all the values.

Thanks for any guidance, Brian

Is there any reason you couldn't power the ping directly from a digital output pin set to high to power on the ping and low (or set as a input pin) because a output pin is rated to able to source around 40ma ?

Lefty

I’ve never used a discrete transistor in a circuit and decided this was as good a time as any to learn how to do it.

Thanks for the fast reply!

  • Brian

Just clearing up you question:-

Does it make any difference what resistor I use?

Yes the larger the resistor the less current you will draw turning it on. However if you take it too high then there won't be enough current to turn the transistor fully on.

Collector current = base current * transistor gain

So the trick is to look at the data sheet and see what the minimum gain of that type of transistor is and choose a resistor that gives that current. As the gain has a wide range the other thing you can do is measure the gain of the transistor you have and use that. However the design will not be repeatable as you can't be sure that the next transistor you use will have at least that gain.

Is it worth going a little deeper into the theory? Since you are using the 2N3904 as a switch, you want to drive the 3904 into saturation in order to maintain the Ping's logical zero output as low as possible. Consequently, you will want to drive the base harder than you would calculate to just provide enough current to run the Ping.

In this case, where you might calculate a 10K base resistor would be adequate to provide enough current to run your sensor, if you want to drive the 3904 into saturation, you would use a 1.5K.

Or is that just being too pedantic?

No, it's a valid guestimate for using a hfe=100 transistor at 5 volts with load that is well below the collector current of that device.

A good rule of thumb is: 5V base voltage, 1K Base resistor, small switching transistor.

You could also have good luck with a 2N7000 in this application. It requires less current from the micro controller to turn on.

Vbe sat for that transistor is 0.9V at almost 3 mA base current for a collector current of 20 mA. That'll give you a Vce sat of 0.2V which won't hurt anything with 5 volt logic, may be all right at 3.3V.

I use a p-channel fet myself. They cost about the same as a bjt and by switching the high side, you eliminate the problem all together.

Lots of ways to address the same issue.

First and foremost, thank you all for your willingness to share your knowledge! I sincerely appreciate it.

Grumpy_Mike:

Collector current = base current * transistor gain

The Minimum Gain listed on the datasheet is 30. The datasheet for the PING lists the maximum supply current as 35 mA. Assuming I understand…

35 mA = Base Current * 30
Base Current = 35 mA / 30 = ~1.2 mA
Voltage (E) = Current (I) * Resistance (R)
5 = 0.0012 * R
R = 5 / 0.0012 = ~4.2K

So I should not use a resistor greater than 4.2K ohm? If I do use a resistor that’s more than 4.2K, not enough current will be available for the PING?

EmilyJane:

you want to drive the 3904 into saturation

If a transistor is “saturated” that means it acts like a switch? To drive it to saturation, a minimum amount of current should flow from the Arduino pin, through the resistor, into the transistor’s base? In other words, if the resistor is too much, the transistor won’t reach saturation?

pwillard:

You could also have good luck with a 2N7000 in this application

Thank you for the recommendation! The next time I order parts, I’ll include a few.

EmilyJane:

Vbe sat for that transistor is 0.9V at almost 3 mA base current for a collector current of 20 mA.

I need at least 3 mA flowing from the Arduino to the transistor’s base to get the transistor to reach saturation?

That’ll give you a Vce sat of 0.2V which won’t hurt anything with 5 volt logic

You’re saying that there should be about a 0.2V drop across the transistor?

  • Brian

5 = 0.0012 * R R = 5 / 0.0012 = ~4.2K

This bit is wrong. Although you are connecting it to 5V you have the Vbe (voltage from base to emitter) to contend with so the voltage accross the resistor is 5 - Vbe. As this is 0.9V in this case you have 4.1V / 0.0012 = 3.4K

So you use a resistor that is 3.4K or smaller to get your base current.

Let me see if I can explain without going into so much theory as to just make it more confusing.

An NPN bipolar transistor is said to be forward biased when the base to emitter voltage is greater than approximately +0.7 volts. It is actually a diode junction so that is why the +0.7 volt drop may sound familiar. When the transistor is operating in what is called the linear region, the current that flows through the collector-emitter junction is proportional to the current flowing through the base-emitter junction by what is called the gain. I think you have a good handle on that based on the calculations you posted.

If you bias your transistor, as you have calculated, to conduct the 35 mA that you need for your Ping sensor, the collector-emitter voltage will be 1 volt. This is from the data sheet. As you can see, the collector-base junction under those conditions is still “back biased”. Think of it as a diode again like the base-emitter junction, it will not be forward biased until the collector voltage falls below +0.7 volts.

When conditions exist to forward bias the collector-base junction, the transistor is said to be saturated and is operating in the non-linear portion of its curve. To get the transistor to this state you have to force more current through the base-emitter junction. That’s where the lower base resistor come in. Again, from the data sheet, the 3904 requires about 0.1 times the collector current through the base to push it into saturation. At that point the collector-emitter voltage is around 0.2 volts. As you can see, that makes the transistor a more efficient switch.

Whew!

I hope that was helpful and not just more confusing.

And if you want to drive to saturation, 4.1 / (.035 * 0.1) = ~1.2K.

Which is why I haven't bothered to "recalculate" those numbers since 1976 when I first started using TTL logic chips and driving loads like small relays and indicators with 2N4400 or 2N2222's transistors. The 1K resistor between the transistor base and the driving pin has served me well.

A few resistor values I always have a lot of "on hand" when working with 5V logic are 1K and 10K followed closely by 4.7K.

I met the 2N2222 and its PNP complement the 2N2907 in the 60s at TI when we were building them under license to Motorola. Up until then the germanium 2N170 and its complement the 2N107 from GE had occupied the equivalent spot in designs.

Even though the 1K base resistor rule of thumb works very well, I still take a look at the data sheet of new devices, as few general purpose transistors are as durable as the venerable 2N2222.

On the other hand, for switching the power to sensors and even logic, nowadays I use a P-channel fet from the FDV302-304 series. These will switch at less than 1.5 V, which is important as I move more and more toward 3.3 V parts.

Thanks again for the help!

Grumpy_Mike:

you have the Vbe (voltage from base to emitter) to contend with

Got it.

EmilyJane:

I hope that was helpful and not just more confusing.

It definately helped.

pwillard:

The 1K resistor between the transistor base and the driving pin has served me well.

The 1K resistor worked well for me. But, I'm trying to squeeze as much life out of the batteries as possible and if a bit more resistance will lower the base current that much the better!

EmilyJane:

for switching the power to sensors and even logic, nowadays I use a P-channel fet from the FDV302-304 series

I can't make heads-nor-tails of the datasheet for the FDV302P so I hope you don't mind one more question...

Is using a P-channel FET instead of a transistor like the 2N3904 a good choice for what I'm trying to do (reducing the total current consumption)?

  • Brian

I don't mind at all. The P-channel FET is analogous to a PNP bipolar transistor. You would connect its source to 5 V, the drain to the power-in pin of the Ping and the gate to the output pin of your Arduino. To ensure the FET turns off completely, connect a 10K resistor from the gate to 5V. Then, driving the gate to 0 V turns the FET on.

The circuit is sometimes called a "high side switch" for obvious reasons. The advantage over switching ground or the "low side" is that switch resistance doesn't adversely affect logic levels.

Now, having gone through all that, as Lefty suggested in the very beginning, the best thing to do might be to just power the Ping directly from an output pin. From the Ping description it looks like there is plenty current available and that would waste the least amount of power. No additional parts necessary either. Seriously.

On the other hand, for switching the power to sensors and even logic, nowadays I use a P-channel fet from the FDV302-304 series. These will switch at less than 1.5 V, which is important as I move more and more toward 3.3 V parts.

AMEN. Love Them.