I'm working on a battery-powered logging project that we're trying to keep the battery running for as long as possible. We're taking full advantage of the ATMega's sleep modes, however we also have a fair amount of sensors and peripherals connected that add up to a pretty sizeable current drain. Logically, we want to turn these off too.
A couple of the devices have a "sleep mode" we can activate, but we need to turn them all off. So I tried using a transistor as a power supply for the sensors, then controlling the transistor with a pin to effectively turn on or off the power to the bank of external devices.
Problem is, it didn't work. The transistor got hot and only output a couple volts. I can't figure out why it didn't work, do you know of any reasons why it shouldn't? Or have any of you done something like this before?
The total current consumption of the external devices (max) is about 230 mA. The transistor I'm using is a 2SD2012 npn 60V 3A transistor, it should have a gain of at least 100. The datasheet is here: http://www.st.com/stonline/books/pdf/docs/9864.pdf.
I connected the base of the transistor through a a 470 ohm resistor to an Arduino digital pin, the collector to +5V and the emitter to the device bank's power.
From my rather limited knowledge of electronics, I should be fine, but I'm obviously missing something.
Thanks for any help you can send my way, it is greatly appreciated!
Grumpy mike needs to chime in here, but I think your problem (based on his hints about h-bridges and other motor drivers) is that you have your load on the wrong side of the transistor; your emitter should go to ground, and your load should be on the collector side of things, I think.
From my rather limited knowledge of electronics, I should be fine, but I'm obviously missing something.
You are missing knowledge of electronics.
As c0sh says, if the load is in the emitter you can only get the output voltage of the arduino pin minus about 0.7V. The output of the pin while it cab be 5V is probably only 4.3 and could be as low as 3.8V. This gives you say 1.4 volts drop with 230mA you have 0.33 watts to dissipated.
So as you say hot transistors.
So you need to use a PNP transistor emitter to +5 and collector to your load. A low voltage turns it on and a high turns it off.
Alternatively (and better) use a logic level P-channel FET.
Aye, sadly my mechanical engineering degrees' electronics coursework was restricted to RCL circuits and mains lines, and the internet is a sloppy hodge-podge of information.
Anyway, thanks, I'll give it a try!
I don't fully understand why there's a difference between where the load is placed, as transistors have always been described to me as a controllable short-circuit with a minor (0.7V) voltage drop when activated.
Since cr0sh's posting, I've been scouring Google for information on the sourcing / sinking of the transistor (that's what is effectively going on, right? Either you sink current into the collector or source current out of the emitter?), but I hadn't found anything about the difference. Do you know of any places I can read up on this sort of thing (besides Wikipedia, which uses too much jargon to read effectively)?
Is there no way this can be done with an npn transistor? I'd hate to have to place an order through Digikey just to get a FET or PNP (the only electronics store where I live only sells LEDs, resistors, and wire at about 1000% markup). If I went with a FET, then would the +5 be on the drain and load on the source?
After doing some searching on Digikey, I found this p-channel FET: http://www.semiconductor-sanyo.com/ds_e/EN7501A.pdf. It seems like massive overkill, but it's cheap enough and they don't have anything smaller in stock. I know even less about MOSFETs than I do about npns, any chance you could tell me if this would work?
Thanks so much, really I need all the help I can get!
Is there no way this can be done with an npn transistor?
It depends on how the rest of the circuit is connected up to the arduino pins. Bottom sided switching for this application leaves the positive still connected and allows current to flow down through the arduino pins to ground. This can cause latch up problems. So when you are powering something down then you are much better off using top side switching. This is not quite the same as current sourcing or sinking, although I could see how you might mistake it as the same thing.
I don't fully understand why there's a difference between where the load is placed, as transistors have always been described to me as a controllable short-circuit with a minor (0.7V) voltage drop when activated.
A transistor needs current through it's base to turn on or control the current flow. That means (for a NPN transistor) a voltage between the emitter and the base of about 0.7V. But if the load is in the base as soon as current starts to flow through the load it develops a voltage across it which raises the emitter voltage and so reduces the voltage between the base and emitter. This acts as a feed back mechanistic and effectively chokes off the current supply to the base.
If the load is in the collector this does not happen as the emitter is always at ground and the emitter base voltage does not get reduced as more current flows.
Ok, I think I finally understand a little better. P-channel FETs are for high side switching, while N-channel FETs are for low side switching, right? And yes, I'll probably want to do high side switching, so I'll need to use a p-channel FET on the high side in place of the npn on the high side like I had tried. I've attached a schematic of what I believe low-side and high-side switching to be:
And according to the diagram I've drawn above, I should use the high side switch with a p-channel fet, with all the sensors' +5Vs going the the drain of the p-channel fet.
Is this correct?
A transistor needs current through it's base to turn on or control the current flow. That means (for a NPN transistor) a voltage between the emitter and the base of about 0.7V. But if the load is in the base as soon as current starts to flow through the load it develops a voltage across it which raises the emitter voltage and so reduces the voltage between the base and emitter. This acts as a feed back mechanistic and effectively chokes off the current supply to the base.
If the load is in the collector this does not happen as the emitter is always at ground and the emitter base voltage does not get reduced as more current flows.
This makes so much sense! I feel silly not realizing that on my own, but now it is much clearer!
Thank you so much for your help, you truly are a god among men!
I think the succint way to express this is that you have used an emitter-follower circuit where you should have used a common-emitter circuit. wikipedia etc will fill in the gaps!
My other 2 pennies worth is use a MOSFET and you'll have about 0V drop across it rather than the 0.3V of a saturated bipolar transistor, which will make an analog voltages you measure from the sensors a lot more accurate. For 250mA load you want a MOSFET that runs from logic levels with Ron at or below 50mohm to keep the voltage drop negligible.
One poster suggested high-side switching was necessary because otherwise the ATmega will sink current through its inputs in sleep mode - is this actually true? I don't remember seeing such a warning in the ATmega datasheet.
the ATmega will sink current through its inputs in sleep mode - is this actually true?
It is a problem you can have with power down circuits. It is not talked about in data sheets but it is a real problem on many projects I have worked on. I have not done this type of circuitry with this chip because this is not the best chip for making low power and power down applications.
and you'll have about 0V drop across it rather than the 0.3V of a saturated bipolar transistor,
Well with a power transistor you are more likely to get 1.2V or higher saturation. You don't get 0V drop across a FET. The turn on resistance will be low, normally less than one ohm but it is still something. The volts drop you get will depend entirely on the current through it.
@Adrastos - Yes that is right. It is advisable to put a 100R resistor in line with the FET gate. This is because a FET that is off looks like a capacitor and a capacitor initially looks like a dead short, so you will be very briefly taking too much current from the arduino's output pin.
If you're thinking about a P-channel FET, check out this one: it has a lower gate threshold, more suited to use in a 5V system.
As I recall, an octopart search turned up better prices when someone brought that FET to my attention the other day, but you mentioned Digi-key, so I checked there.