V_CE drop on 2n2222a NPN transistor & analog sensor reading falsification

Hello everyone! Mechanical engineer with almost zero knowledge in electronics here, so bear with me :wink:

I'm currently working on a battery powered project (automated watering system with data logging feature) and therefore need to design an energy efficient circuit. In order to reduce power consumption, I planned to use a 2n2222a NPN transistor to connect/disconnect the utilized sensors and an SD card module to Vcc.

So far so good - at least the SD card module works well in this setup. The sensors (capacitive moisture sensor, water level sensor) however, read a significantly higher value when I use the NPN transistor to connect them to Vcc compared to when they are permanently/directly connected.

After measuring the supply voltage in both cases, I realized that a voltage drop of about 0.8V occurs across the collector and emitter of the NPN transistor. Hence, the sensors are powered with only 4.2V. My understanding right now is that if the Arduino runs on 5V and the supply voltage of the sensors is lower, the offset affects the readings. I tried running the Arduino on 4.2V while connecting the sensor directly, in this case the readings were correct as well. Although I think I have identified the problem and can fix it, I don't quite understand the cause of it. Is the Arduino comparing the read input values to its internal Vcc?

When designing the circuit, I expected the voltage drop across the transistor to be negligible, but after doing some research, I believe the reason for this large drop is the "emitter follower" behavior of the simple NPN switch circuit.

I found and used this formula to calculate the voltage drop V_ce:

V_ce = V_cc - R_eI_e = V_cc - [(beta+1)(V_cc - V_be)][(beta+1)R_e +3]^-1

This when using a 17kOhm or value for the emitter resistance R_e (measured between Vcc and GND of the soil moisture sensor), this yields a drop V_ce = 0.7V, same for R_e = 2MOhm (between Vcc and GND of the water level sensor). The calculations were done using beta=100. The simulation in circuit lab gave similar results, although the drop was slightly lower (0.54V).

When using a PNP transistor, the setup works fine as the V_ce drop is much lower (below 0.1V). I believe this is due to the fact that the high load resistance does not affect the transistor saturation (?), but in this case I need to permanently pull the transistor pin high to cut the supply voltage of the sensors. Does this result in increased power consumption compared to the NPN circuit? To my understanding, with a 5V pin level at the transistor base of the PNP does not allow any current to flow. But then again, the pin needs to permanently be pulled to 5V instead of 0V...

I also found a suggested schematic as an alternative to the simple NPN switch (attachment 2). I plan to go with this, in case the simple PNP variant defeates the purpose of saving power. I don't understand the point of resistor R3 though, can someone help me out here? I would've just used 1kOhm resistors for R1 and R2.

Sorry for the long post, but I thought maybe someone can make use of the information I found during my research. To recap, my three questions are:

  • Why does the voltage offset between the Arduino Vcc and sensor supply voltage alter the sensor readings?

  • Can I switch to the simple PNP circuit and still achieve power saving?

  • What's the point of R3 in the schematic of attachment 2?

Thank you in advance! :slight_smile:
Cheers, Thomas

Are you using the transistors as a switch? Current wise, you should be able to use a multimeter to measure the actual current usage of the arduino when testing the different configuration.

From what you wrote, you have a lot better knowledge then you think. Your understanding is a sign of a good engineer especially considering it is not your field. I would switch to MOSFETs, you have about a 0.7V drop across the 2N2222. This getting in your way is the Aref voltage, the transistor Vf is causing an offset which killing you bad, this will go away with MOSFETs. That voltage drop is the Collector Emitter junction, it behaves just like a diode. MOSFETs only consume current when switching (almost nothing when off), transistors draw current whenever they are on. Your circuits require lots of parts and work assembling. You need a MOSFET and preferably a 10K resistor from gate to source to guarantee off when the arduino outputs are in the tri state mode. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

gilshultz:
From what you wrote, you have a lot better knowledge then you think. Your understanding is a sign of a good engineer especially considering it is not your field. I would switch to MOSFETs, you have about a 0.7V drop across the 2N2222. This getting in your way is the Aref voltage, the transistor Vf is causing an offset which killing you bad, this will go away with MOSFETs. That voltage drop is the Collector Emitter junction, it behaves just like a diode. MOSFETs only consume current when switching (almost nothing when off), transistors draw current whenever they are on. Your circuits require lots of parts and work assembling. You need a MOSFET and preferably a 10K resistor from gate to source to guarantee off when the arduino outputs are in the tri state mode. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Do you think replacing a BJT emitter follower with a MOSFET source follower will reduce the problem?

Uh-boy...

Let's have the illustrations!

NPN_PNP_circuits.png

Alternative_circuit.png

Mr_Mechanics:
What's the point of R3 in the schematic of attachment 2?

Well, that one is easy. It compensates for any leakage in Q3.

R3 is a pull-up to ensure Q2 is off when Q3 is off it should be a larger value compared to R2 so a lower voltage develops to forward bias emitter base junction. This looks similar to a Sziklai pair.

First example using NPN the load should be on the collector side. Try multi sim again moving the load. You will have a harder time with the sensor since now you have to measure the differential instead of source to ground.

While you can design this to work with BJT’s it’s not good to rely on beta which is affected by temp and varies quite a bit from transistor to transistor.

If your sensors have a ratiometric output: connect the collector of Q2 in the second schematic, or Ve or Vepnp in the first schematic, to the Vref pin of your arduino, and set the analogReference to EXTERNAL. That way your full scale (1023 reading) always equals that voltage, regardless of what it really is.

If your sensors produce a voltage output: connect a voltage divider on the sensor output, so the maximum output becomes 1V, then set the analogReference to INTERNAL. Now you're reading using the 1.1V internal fixed reference votlage as full scale (1023 reading).

For this type of high side switching is P-MOSFET much better than a BJT.

BTW 2N2222 is a small signal transistor with limited collector current. Is it suitable to power a SD card?

Elvis has left the building... :wink:

The error was using an emitter follower - that is not used for switching.

A transistor used as a switch is either in cutoff or saturation. Emitter follower cannot saturate, whereas
the correct circuit, the common-emitter, can.

In saturation the base current should be around 5 to 10% of the collector current (in other words the DC current gain of a transistor does not apply to saturation mode).

MarkT:
The error was using an emitter follower - that is not used for switching.

A transistor used as a switch is either in cutoff or saturation. Emitter follower cannot saturate, whereas
the correct circuit, the common-emitter, can.

In saturation the base current should be around 5 to 10% of the collector current (in other words the DC current gain of a transistor does not apply to saturation mode).

In the OP's setup the emitter follower may make sense: you do not waste the base current. If the base current is 10% of the maximum load current it will be significant part of the average current used by an active load such as SD card. Since the device will be powered only shortly power dissipation in the transistor should not be a problem.

Thank you everyone for your replys, I really appreciate the input! And sorry for the delayed response, I was out of town yesterday.

So going one by one here:

zoomkat:
Current wise, you should be able to use a multimeter to measure the actual current usage of the arduino when testing the different configuration.

Yes, you're right. I failed to mention in my original that I have put a simple screw terminal in between the supply voltage and the V_in pin to measure the current consumption. My question (although admittedly badly phrased, it was about 2 a.m. when I posted) was more how a constantly pulled up digital pin will theoretically increase/affect the current consumption of the arduino. After measuring, it turns out that using the NPN circuit for the sensor switching brings down the consumption to about 5.2mA in deep sleep more, while the PNP variant clocks in at 6.4mA. So not all that critical of a difference in my opinion.

gilshultz:
I would switch to MOSFETs, you have about a 0.7V drop across the 2N2222.

First of all, thank you for your kind words! The reason why I went with BJTs is simple: It's what I had laying aound. I agree that MOSFETs are the better way to go in terms of consumption, but since I plan to only swtich on the setup twice a day, I was not too concerned about the current consumption by the BJT. Anything below 10mA in idle state should work fine, considering I have a 2400mAh battery pack and a solar panel attatched to it.

krupski:
Do you think replacing a BJT emitter follower with a MOSFET source follower will reduce the problem?

Without knowing the first two things about the internal processes in MOSFETs, I assume you mean the central problem of having a load dependency in the voltage drop across the transisor will still be present in the suggested setup (MOSFET source follower)?

wolframore:
R3 is a pull-up to ensure Q2 is off when Q3 is off [...]

While you can design this to work with BJT’s it’s not good to rely on beta [...]

I see, thank you! I thought that without R3, the PNP Q2 would simply briefly switch on until it's base is sufficiently biased (as Q3 is "closed" in its default state). But again, my semiconductor knowlege is extremely limited.

Hmm... So you mean with an uncertainty to beta due to the circumstances, an error propagation might affect the sensor readings (as the voltage drop across the transisor varies)? I have some error tolerance in the system, so minor fluctuations are not all that critical...

wvmarle:
If your sensors have a ratiometric output: connect the collector of Q2 in the second schematic, or Ve or Vepnp in the first schematic, to the Vref pin of your arduino, and set the analogReference to EXTERNAL. [...]

I had no idea this was possible, thanks! I will look more into this, manually modifying the reference voltage opens up a whole new set of options.

MarkT:
[...]
A transistor used as a switch is either in cutoff or saturation. Emitter follower cannot saturate, whereas
the correct circuit, the common-emitter, can.
[...]

Yes, this makes sense to me now - I was oblivious of the degree to which the load will affect the saturation. Unfortunately, we had only touched upon BJTs briefly in one class (been a while, too...), where they told us to simply think of BJTs as "electronical switches". In hindsight, a gross simplification...

Smajdalf:
BTW 2N2222 is a small signal transistor with limited collector current. Is it suitable to power a SD card?

The 2N2222a is rated for 800mA max. current, I was measuring a peak current of around 140mA while using the SD card. So I think there should be enough headroom in terms of current.

Smajdalf:
In the OP's setup the emitter follower may make sense: you do not waste the base current. [...]

Admittedly, I did not think of this, although I get your point. Interesting...
But again, since the system will only briefly power up twice a day, I am much more concerned with its inactive/idle power consumption than with the active consumption. The solar panel has plenty of time to compensate the current peaks, and the lower the idle state current to the MCU is, the more output current of the panel will go to the battery.

Again thank you everybody for your explanations! I think I will put together the suggested common-emitter circuit and compare its power consumption to the 6.4mA I currently get with the simple PNP switch.

Also: I have another problem with the circuit (unrelated to the transitor circuit choice). Apparently, the combination of using a relay (and a motor as a load switched by the relay) causes major problems for the Arduino. Should I open up a new thread for the discussion on this topic, since it's not related to the original topic of this post?

Mr_Mechanics:
Apparently, the combination of using a relay (and a motor as a load switched by the relay) causes major problems for the Arduino.

Sounds like a too weak power supply. Or too thin wires to your battery, causing excessive drop.

wvmarle:
Sounds like a too weak power supply. Or too thin wires to your battery, causing excessive drop.

Maybe, I have however measured a voltage spike of around 10V when the relay switches. I'm limited to a multimeter though, without an oscilloscope, I have trouble identifiying how high its max. value actually is (as I guess it will be an impulse/high transient).

I'm afraid it might briefly send a high peak signal (above 12V) into the V_in pin, causing the Arduino to mess up. After switching, the serial monitor breaks down and I have apparently already fried one Arduino Nano this way. At least it doesn't run the code anymore and also won't let my flash it with anything.

The motor uses around 80mA in its steady state by the way. But again, is this the correct thread for it?

If so, attatched is the current schematic of my system. I thought about adding a fly back diode aross the motor terminals (although I wouldn't know how a flyback current should affect the system after the relay has opened) and some buffer capacitors across the V_out+ and V_out- terminals...

Also: I believe the "cleanest" way would be to completely separate the motor circuit from the MCU circuit. But since it's a solar and battery powered project, this would be rather difficult to implement as I'd need a second battery, a second charger etc.

You need a 1N4004 diode in parallel with the motor, cathode (end with band or stripe) toward +V for kickback suppression, same with the relay coil, a 1N4148 will do here, and a 220Ω resistor in series with PNP base to limit current from output pin. And current limit resistors for LEDs, 270 ~ 560Ω. That's all I see for now. :slight_smile:
EDIT: 6V is not enough for VIN, needs at least 7V.

Oh dear, mea culpa... Luckily, the resistors at the PNP base and LEDs are present in my circuit in reality, I just forgot to add them in the schematic (or in case of the LEDs are connected "after" the headers).
Similarly, I'm using a standalone unit for the relay as of now, which has the flyback diode built in. But I also added it in the schematic. Thanks for pointing it out!

Alright, I'll bump up the converter to 7V then. I found 6V as the minimum required voltage on the Vin (6-20V), but I'll be happy to go with your advice!

Then why not set that converter to the 5V the Arduino really needs, connect it to the 5V pin, and forget about that whole Vin pin?

That transient you're measuring is definitely an issue, and you should find the source of it. Both the motor and the relay need flyback diodes.

wvmarle:
Then why not set that converter to the 5V the Arduino really needs, connect it to the 5V pin, and forget about that whole Vin pin?

Good point, that was actually my initial idea. In part also, because the efficiency of the Nano clones onboard 5V regulator (in my case a AMS1117) is nothing to write home about. The problem at hand though, is that the solar panel I use to power the setup has a max. output of 6V. The charger IC connects the load (i.e. the dc dc boost converter) directly to the panel output if the current output is sufficient, bypassing the battery. This means even if I set the converter to 5V, 6V will pontentially be the output if the panel is connected directly. So I would overload the +5V pin and probably damage the Arduino and the peripherals.

wvmarle:
That transient you're measuring is definitely an issue, and you should find the source of it. Both the motor and the relay need flyback diodes.

Yes, I've put flyback diodes on both components (the relay coil already had one, I just missed it in the schematic). A part that I have trouble understanding so far, is that the transient occurs even if I disconnect the motor and measure the voltage across the open output terminals of the relay. Putting capacitors (I tried 0.1µF, 47µF and both simultaneously) across the relay terminals didn't help to absorb it, at least I can still briefly see 10V on the multimeter.

There also exist buck/boost converters, that produce a fixed voltage with both higher and lower voltage as input.

Buck converters tend to need a minimum drop (in the same fashion as linear regulators); maybe boost converters also need a minimum boost? Haven't used them much :slight_smile:

On a separate note, if you compare the schematic of your original circuit with the 'alternate ' circuit ,
you will notice that in the 'alternate ' circuit, the GND is pointing (oriented) towards the bottom of
the page, whereas in your original circuit, you have "-" (negative) terminals pointing (oriented) towards
the top of the page. Visually speaking (not electronically) this is frowned upon because it generally
results in chaos in the appearance of the circuit. As a general rule, ALL positive nodes are oriented
toward the top of the page and ALL GND/negative nodes/terminals toward the bottom. This gives some
uniformity to the circuit and makes it easier to locate positive or GND/negative nodes.