Inconsistent Battery level reading

I have a project which connects two 18650 4.2v 3200mHZ batteries powering my Arduino Pro Mini. I have the two batteries in parallel with the positive lead connected to two 100k resistors connected in series. Between the two resistors I have connected to A2 pin and the end of the resistors are connected to the GND of the Arduino. The batteries positive is also connected to the input side of a 5v boost regulator. The output of the boost is connected to the VCC of the Arduino. I also have a 10uf capacitor connected between the A2 and GND. I have tried a 2.2k and 1k resistors instead of the 100k ones, and although the value of the battery level was much different the variations were about the same. With the current set up sampling every 15 minutes I get variation of 405 down to 375 and anywhere in-between. In my code I have tried reading the power level 5 times with a .1 second delay and averaging them right after the loop begins and before anything else starts up. This doesn’t seem to have any effect.
Here is the code:

void loop() {
  sensorBatValue = analogRead(batteryInPin);
  float v = sensorBatValue;
  sensorBatValue = analogRead(batteryInPin);
  float w = sensorBatValue;
  sensorBatValue = analogRead(batteryInPin);
  float x = sensorBatValue;
  sensorBatValue = analogRead(batteryInPin);
  float y = sensorBatValue;
  sensorBatValue = analogRead(batteryInPin);
  float z = sensorBatValue;
  float A = (v+w+x+y+z)/5;

I would like this reading to be within a range of 5 not 30 or more. Any suggestions?

Please attach proper schematics. This Shakespeare type diagram is not useful. Any misunderstanding gives a totally different Circuit, and helpers don't want to sit and make drawings out of text.

I haven't looked at your code, but would offer that a battery's voltage can vary depending on how much load current it's sourcing. Moreover, the boost regulator, as a switching device, will draw more current at its input than it delivers at its output, and the lower the input voltage, the more current it will draw. So it wouldn't surprise me if the battery voltage reading wandered all over the place. The question is - if you connect your voltmeter leads or scope probe to the battery terminals, do you get the same variation as you're seeing at A1, or is it rock solid? In other words, is the A1 reading giving you the actual battery voltage, or something different?

And I guess I would try it without the capacitor on A1, or with a much smaller capacitor.

You have 2 18650s in parallel so 4.2 volts and a 5 volt pro-mini, why do you need a voltage divider?

I have changed the schematic photo. I hope this is more helpful. Since I am trying to get the battery level before I do anything else with the Arduino I was supposing that the current draw should be the same. I could understand if the battery is draining and every time it keeps getting lower. But it will go from 412 down to 375, up to 395 then 405 etc.

To measure the voltage of a battery directly powering the Arduino through Vcc (for example, one 18650 battery), you do not need a voltage divider. However, you do need a stable voltage reference.

This tutorial shows you how to use the 1.1V reference, which must be calibrated individually as it varies from processor to processor.

The code I use to measure battery voltage, using the measured value of the 1.1V reference, is derived from that tutorial:

// Read 1.1V reference against AVcc
// returns battery voltage in millivolts
// must be individually calibrated for each CPU

unsigned int readVcc(void) {

  unsigned int result;

  // set the reference to Vcc and the measurement to the internal 1.1V reference

  ADMUX = (1<<REFS0) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
  delay(10); // Wait for Vref to settle

  ADCSRA |= (1<<ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // wait until done
  result = ADC;

  // second time is a charm

  ADCSRA |= (1<<ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // wait until done
  result = ADC;

  // calibrated for my Miniduino

  result = 1195700UL / (unsigned long)result; //1126400 = 1.1*1024*1000
  return result; // Vcc in millivolts

I will look into this and try to make it work. Thanks for the suggestion. I would like to understand why there is so much inconsistency when I check the batteries when they are using the same amount of energy though.

We need a clear and complete schematic, not a stamp sized cut and paste.
How have you got the gnds connected?
If all you have done so far is code for battery level, then show us the complete battery and controller circuit.

Tom... :slight_smile:

I'm not sure why you need a full schematic to see about the battery level. The batteries ground is connected to the arduino's GND. I have submitted a full schematic. Like I said I do not do anything before or during the checking of the battery level. i have changed the 10uF capacitor to a .1uF capacitor but it still behaves the same. I am looking at doing jreminqton suggested and will get back with a couple questions tomorrow. Thanks

Why didn't you just add your full schematics in a new post?

I think you need to redraw your schematic so you do not have so many crossing wires.

Tom... :slight_smile:

As well as the schematic, a clear photograph of your wiring would be useful.

A schematic only shows us what you think you have implemented.

If you have made any wiring errors they won't show up on the schematic, but may be revealed by a photograph.

Also a photograph may give us ideas on how your wiring arrangement could be improved, to remove sources of noise/interference that could be causing your problem.

For a start, can you explain why the output of VR3 the NTE1904, 3.3 LDO Regulator is connected to the collector of Q1 and the GND circuit?
Secondly you have the relay K3 coil connected to +Vbatt, which is good, but you have the switching transistor Q1 Collector and Emitter connected the wrong way.
Thirdly you have K2 being directly driven by the ProMini output pin.

Tom.. :o

Here is the start of a clearer schematic.

Tom... :slight_smile:

You are correct that the NTE1904 was hooked up wrong. I was originally going to use an LM11117T which has this configuration but changed to NTE1904. Also you are correct with the 2N2222 transistor. I have changed it on the new schematic I uploaded. I don't think a photo of the wiring would help as most of the wiring is a PCB which I modified as I found things wrong. This schematic represents the wiring of the updated PCB wiring. Thanks for the help. I will try to change the schematic when I get some time.

PLEASE post any updated schematics/images in NEW posts,
The update you last posted should have been on post #13 NOT post #1.
The reason is if someone else decides to help you, or later someone has some similar problems, the thread will read like a book and flow as problems are discussed.
Currently with all your updates at the start mean anyone following your project including me has to keep jumping back to the start to get updates, this is even more of a pain when the thread goes more than one page.
Thanks for the update.

Tom.... :slight_smile:

I have tried to include two photos of the PCB’s front and back. I have drawn in the original wiring with magenta, where I cut those with a red line and new wiring with green. I hope this helps. Sorry I didn’t do everything at first. I tried putting them together but they were too big will post front separately. I will try to redo the schematic soon.

Here is the front

A semi related question. Is it alright to run the HK19 with the 2N2222 transistor for 15 seconds? Or should I use a latching relay so the transistor is only on for less than a second?


Tom... :slight_smile:

A semi related question. Is it alright to run the HK19 with the 2N2222 transistor for 15 seconds? Or should I use a latching relay so the transistor is only on for less than a second?

What is the FULL part number of your HK19 relay?
If you are unsure of the HK19 spec, measure the coil resistance with your DMM.
You should be able to look up the coil specs in the datasheet and apply OHMs law to see what the coil current will be.

Then look up the 2N2222 specs to see what the collector current spec is.

As the 2N2222 is quoted at 800mA collector current, leave the transistor there and don't worry about using a latching relay.

What I am worried about is K2 which is being controlled DIRECTLY from the controller, which has a maximum output current rating of 40mA??????
But it is good practice to use a BJT or MOSFET to drive a relay even if the current draw is low.

I can calculate the coil resistance and coil current at 12V, but see it as an exercise for you to try and do yourself, that is what this forum is trying to encourage.

Tom... :slight_smile: