Analog Read and Transitors

Hello,
so I have the following shematic:


It is supposed to read the battery level of my device, very simple. I need the BC847 Transistor so I can toggle the voltage divider off ( I need the voltage divider since my arduino is on 3.3V and cant handle the 4.2Vmax).
But I always read the 3.3v from the gpio that should toggle the transistor (i think). There is something im not understanding about this setup, hopefully anyone can give me a hint...

You have built a constant current source which applies the GPIO voltage minus the transistor BE voltage to the voltage divider.

Search for "high side switch" circuits.

1 Like

In order to turn the transistor off the base-emitter voltage has to be zero (the voltage on the base has to equal the voltage on the emitter).

You can hard-wire it that way (shorting the base to emitter) but the GPIO pin won't work.

The emitter voltage will follow the base voltage. A base voltage of zero (pin LOW) turns the transistor off.

Damn should have tested on a breadboard before ordering 25 pcbs... I thought a simple voltage divider needs no testing :upside_down_face:
Thanks for your replies tho, very helpful.

Can I at least somehow detect when my battery is low by shorting/disconnecting some parts?

If you made R3 15k and R6 47k (62k total) the current at 4.2V would only be 68 microAmps, may not need switching. How long could your battery supply 68µA?

Pretty much useless.

If "dividerSwitch" is connected to a GPIO, when the GPIO is HIGH, it will pull the emitter to about 650 mV less than the GPIO voltage, notwithstanding whatever the "BAT+" voltage is.

You might as well not connect "BAT+" at all.

OK, has been said before. :roll_eyes:

Use a P channel MOSFET with "the right" characteristics. I would try to find one with threshold voltage around 2 V.

Or if you have a Base resistor (it is not on the schematic) you may use any PNP transistor.

Thats an ok solution for me, thanks for the input!

May you enlighten me what the base resistor is used for? But I would have to change the shematic with an pnp anyway so the battery does not drain when the device is switched off. Thanks for your feedback tho. I think a mosfet it the easiest solution?

Base resistor is to limit the Base current. Very important in most BJT applications.
If you plan to turn off the Arduino by removing it's power the MOSFET won't help you either. Unless you use low side switching off the power supply (disconnecting GND, not positive battery terminal) - but BJT will work too in this setup.

Thanks for your input, very helpful. Why would a mosfet not help? A mosfet in enhancement mode should work since it stays off when there is no voltage at the gate. And it has very little voltage drop, or am I missing something here?

Indeed the voltage drop is negligible and it is the correct component to use. The problem is that you need several volts on the gate higher than the source to actually turn it on.

For a high side switch you need a logic level P channel MOSFET that can be turned on with the voltage of your battery. It is off as long as the gate voltage is HIGH and on if the gate is sufficiently negative (LOW) vs source (battery +).

That's equivalent to a PNP transistor with emitter at battery + which is turned on with a current from base to Gnd.

Replace your transistor with a diode or two to drop the voltage, then hook the the bottom end of R6 to the freed-up GPIO pin instead of ground. Then you could toggle the GPIO pin to ground the divider or not, or set it to pinMode(GPIOpin,INPUT) and put it in high-impedance mode.

You dont say which "Arduino " you are using.

The arduino analog input has a very high input resistance. (from AtMega328 data sheet)

So you can simply use large value resistors in your divider chain.
That will save you making changes to the pcb.

You WILL need to use the internal reference.
Make R3 +R6 = 4M7 and you will have a constant current of about 1uA which is probably less than the leakage current in your battery.

1 Like

Recommended is a resistance of no more than 50k. At least if more than one channel is sampled and the S&H unit is switched.

How is about the following circuit?
transistorswitch

1 Like

The collector voltage should be measured as well and subtracted from the divider voltage.

The transistor will enter into saturation zone with VCE ~= 0.2V upon receiving HIGH at DPin-2?

A logic level MOSFET is the better switch.