Using a BJT as a switch

I’m currently using my Arduino to measure various aspects of a separate battery system, like state-of-charge and current draw. This is what the circuit looks like:

Every once in a while I will need to swap out the 12V battery to recharge it. However, I’ve read from posts like these that if there is an external voltage being applied to the analog pins while the Arduino is unpowered, it has the potential to cause problems. The most obvious solution is to open the 48V circuit when swapping out batteries, but I’d like to have some extra protection by only allowing a current to flow into them when the Arduino is powered on, probably with transistors. There are a few potential problems that I feel like I may run into, however:

  • The only component I have available to me to do this with (at least that I know of) are BJTs
  • The voltage coming off of the shunt will be very small, which may not interact well with the various traits of the BJTs
  • From what I’ve read there is a voltage drop across the BJT, which may make the measurements fuzzy with the voltage divider
  • The backpower may be enough to drive the BJT into saturation, defeating the purpose of it being there (no idea if this would happen or not and I suspect it wouldn’t, but might as well throw it in there anyway)

Are these concerns accurate/relevant, or should a BJT work fine as a switch in this case? Would biting the bullet and getting some MOSFETs or some other component be the best solution? (I’ve never used them before and don’t know anything about them) Also, while I’m at it, are there any other obvious glaring issues with this design that I’m missing?

Bonus:

OpAmp im using: https://www.ti.com/lit/ds/symlink/lm158-n.pdf

BJT: https://www.amazon.com/SODIAL-New-2N2222-Transistor-600mA/dp/B07DXRGPR7

Shunt opamp power should ofcourse come from the 5volt pin of the Arduino, not from another source.
And the 48volt voltage divider should have high value resistors that can't do any damage.
Then I don't see any problem.

An INA169 high-side shunt breakout board could have been a better/easier solution.
Leo..

Whoops, should've done a bit more research when looking into current measurement, that would've made things much easier. Oh well.

That aside, what's wrong with powering the opamps from an external regulator? The grounds of all of the voltage regulators are tied together, so 5V from the arduino should be the same as 5V from the regulator. I just did it because I've had some experiences in the past with the Arduino 5V supply being a bit unreliable (possibly due to user-error).

The voltage divider has a total resistance of 110,000 ohms currently, but I could very easily solder together one that has 1.1M if that's too low.

Nothing wrong with external 5volt for the opamps, but why.
The LM358 draws a few milliamps, so no problem to power them from the Arduino.
Did you use the internal 1.1volt Aref in code, because the LM358 has a poor output swing (~0-3.5volt).

The <=500uA from your 48volt divider should be ok.

Could have powered the Arduino directly (5volt) from the 48volt battery bank, with a switching regulator.
Leo…

The 5V regulator will also be powering other components, like a LoRa transceiver LCD, etc. The main reason I'm using the external regulator is because I want to want to up the transmitter power as much as possible, and noticed some voltage drops on the Arduino when it was drawing power from it. I can see how its presence would have seemed strange without that information, sorry for not mentioning it earlier.

I'm using the 5V ARef right now, but if resolution becomes an issue I can change the ratio of the voltage divider and get everything below 1.1V to get better readings.

The reason why I'm not pulling power off of the 48V battery (which I wanted to do in the first place to simplify things) is because of a technicality in the rules of the competition that this system is being built for. The "high-voltage" source can only be used to power the main load, and everything else (such as this circuit) has to be powered through supplemental batteries.

All of that said, thanks for going everything and making sure it checks out. As for the switch situation, are you saying that the current from the analog inputs is too small to cause any backpowering issues? Do I need to add any extra protection against it, or does everything look good as-is?

Just realized I posted this in the wrong subforum, mods feel free to delete/move this thread

I'm currently using my Arduino to measure various aspects of a separate battery system, like state-of-charge and current draw. This is what the circuit looks like:

Every once in a while I will need to swap out the 12V battery to recharge it. However, I've read from posts like these that if there is an external voltage being applied to the analog pins while the Arduino is unpowered, it has the potential to cause problems. The most obvious solution is to open the 48V circuit when swapping out batteries, but I'd like to have some extra protection by only allowing a current to flow into them when the Arduino is powered on, probably with transistors. There are a few potential problems that I feel like I may run into, however:

  • The only component I have available to me to do this with (at least that I know of) are BJTs
  • The voltage coming off of the shunt will be very small, which may not interact well with the various traits of the BJTs
  • From what I've read there is a voltage drop across the BJT, which may make the measurements fuzzy with the voltage divider
  • The backpower may be enough to drive the BJT into saturation, defeating the purpose of it being there (no idea if this would happen or not and I suspect it wouldn't, but might as well throw it in there anyway)

Are these concerns accurate/relevant, or should a BJT work fine as a switch in this case? Would biting the bullet and getting some MOSFETs or some other component be the best solution? (I've never used them before and don't know anything about them) Is this even a problem that I should be concerned about in the first place, or is the current flow too small to disrupt anything? Also, while I'm at it, are there any other obvious glaring issues with this design that I'm missing?

Bonus:

OpAmp im using: https://www.ti.com/lit/ds/symlink/lm158-n.pdf

BJT: Gikfun NPN Transistor TO-92 2N2222A 2N2222 for Arduino (Pack of 100pcs) EK2111: Amazon.com: Industrial & Scientific

The voltage divider has a resistance of about 110K Ohms, while the Opamp setup is about 1.1M Ohms.

Current from the voltage divider is too small to cause phantom-powering issues.

I assume the shunt is used low-side (not clear from your diagram).
If so, than that also shouldn't give any issues.
Leo..

Double posting questions is not allowed, it wastes everyone's time.
Read the rules for posting questions on the forum.

...triple.

Threads merged.

Firstly ------ if 48 V supply is available, then I assume this circuit has access to mains power, so that mains power is converted to DC power through a power supply.

If that's the case, then is it necessary to use batteries? If you don't need to use batteries, then is it feasible to just use regulated DC power supply (mains powered)? Otherwise - have a good charging circuit that keeps the 12V battery charged up, so that you don't have to periodically recharge it.

That 9V regulator is redundant. You have 5V, use it to power the Arduino as well. It loves regulated 5V.

Most LoRa modules take 3.3V power.

A schematic is much more useful than the block diagram you posted.

If you have any significant current flowing into the analog pins while the Arduino is powered up, you're doing something VERY wrong. The resistance of your voltage divider is probably high enough to also not cause any issues when the Arduino is powered off (but you didn't specify these resistor values so we can't be sure).