Possible opto circuit ...
very nice thanks, I like the opto coupler, never heard of it before. What are its downsides?
A bit more PCB space and cost.
The part shown can take up to 80V (pin 4), saturation voltage is 0.06V (can account for this in your readings). PC817 datasheet
But of course it matters. And I hope it's an 8Mhz board.
You should be using 1.1volt Aref for voltage measurements, not default 3.3volt VCC.
Voltage divider can simply be done with Megohm resistors, so all the advice given becomes useless.
Leo..
Or short the transistor, use 1Megohm for R6 and 3.3Megohm for R3.
And add a 100n ceramic cap from A5 to ground.
That will draw about 1uA,
which could be less than the periodic 'on' current plus the leakage of a fet or opto.
Leo..
Summarised in #37, thanks to @ShermanP for posting the circuit and adding to my explanation in #27. ![]()
Well, you provided 2.7V to the gps Vcc, which apparently was high enough for it to run. The transistor could not provide a higher voltage than that because if it tried to, no base current would flow, and the transistor would turn off.
In the case of your original divider circuit, if you provide 3.3V at the transistor base from a GPIO pin, the voltage at the top of the divider would be 2.7V regardless of battery voltage - until the battery discharges to the point that Vcc is no longer 3.3V. So really you weren't passing the real battery voltage through the transistor. The emitter has to be 0.6V below the base voltage before any current will flow through the collector.
Thanks @Wawa - like I said in post 15.
and it needs no mods to the PCB.
Of course (bit of lateral thinking) if the OP REALLY wants to use a switch that wont affect the measurement they could always use one of these ..
![]()
Sorry didn't see that.
Your easy answer got buried in an avalanche of needlessly complicated and worse solutions.
Leo..
With high megohm resistances on a PCB, its difficult to maintain accuracy and stability. Leakage resistance becomes an overriding issue, which is why I would suggest 2 or 3 orders of magnitude lower values for R1/R2. However, this also means a switched solution is needed.
I never had problems with 1Megohm values on circuit boards.
If you can expect conductive dust or condensation, then yes/maybe.
In those cases you could drop to 100k:330k (10uA) which still isn't a big drain.
Leo..
holy moly, thank you! I finally understand transistors!
how is this circuit diving to 1.1V at A0?
If I understand correctly: low side switching with an n-channel mosfet would work because threshold Vgs (3.3v from gpio to gnd) stays 3.3V. But highside would not work because behind the source is the load and thus there will be at best 4.2-3.3=0.9V left for threshold
The resistor values shown there were from another circuit. To bring a 4.2V battery to under 1.1V, I think 33K and 10K would work. That would give you about 1V at full charge and 0.81V when discharged to 3.5V. Your ADC values would range from about 930 down to 911, which should be enough resolution for this purpose. Or 330K and 100K.
With high megohm resistances on a PCB, its difficult to maintain accuracy and stability.
This is a "high Mohm " resistor designed for PCB mounting
https://uk.farnell.com/ohmite/sm102031007fe/res-1g-1-1w-radial-thick-film/dp/1550765
I've used glass encapsulated ones like this for measuring HIGH voltages
https://uk.farnell.com/ohmite/rx-1m1007fe/res-1g-1-500mw-axial-metal-film/dp/1633830
The problem is not the resistor itself but leakage around the resistor. Through dust on the surface, moisture in the PCB, capacitor leakage current and (maybe the most important) leakage of the ADC pin itself.
Unless the board is intended to be used in a very hostile environment (outdoor, bathroom) I think resistances around 1M are OK.
To the original question:
You have already stated small current used continuously for the divider is no problem. So you can short out the transistor and use large resistors in the divider. If you are using the ADC for something else you need to add a capacitor (I would use 100 nF because I have most of them; any ceramic from 10 nF up would do). I would use the cap even when battery measuring is the only task. If you are using reasonable sized SMD resistors soldering a ceramic cap of the same size to the top of the resistor is simple. For THT resistor it is often possible to solder a SMD cap between its legs or use a THT cap and plug legs of both components in the same hole.


