First voltage measurement reading is high
I've recently had to rebuild a node - I am using a pro mini 3.3V with a BME280 sensor.
Having tested it on the bench before putting outside
I have noticed that at every startup the first reported voltage reading is about 0.2V higher than it actually is(significant on my 3S Lipo battery). The next reading is then nearer to the true voltage.
I am using voltage divider with 1M and 82K resistors. I have a capacitor across the 82K. This allows a max voltage of 14.51 in case I go back to using a lead acid battery.
I have tried moving the voltage part of the code to a different location in the loop but still the same.
Has anyone else seen this behaviour or would know why it happens?? I don't get it on my other nodes that use a single 18650.
@grumpazoid - yes, sometimes it helps to introduce a small wait() before the reading.
I have also made a array so i it always read 4 times and sending an average.
@sundberg84 Ah thanks good to know I am not alone.
I have already included a 1500ms delay before the battery code.
The array sounds a good idea. Any chance of pointing me at some code for that?
Has anyone else seen this behaviour or would know why it happens??
This is well known. If you look in the atmega328p datasheet under ADC, it says to throw out the first reading after starting the ADC.
@NeverDie Excellent. Thank you.