there i am working on a project in which my system is connected to 3.7v~4.2V lithium battery, I have to read constant battery voltage irrespective of the current battery voltage and to do that I am using internal voltage reference (1.1V). My issue is that before adding sensor code my program was reading constant voltage irrespective of any battery level but the moment I add sensor code to it, the battery voltage readings fluctuate.
If you set the Vref with the internal reference of 1.1v, then the voltage presented at analog pin A1 is simply as:
const float Vref = 1.1; // according to datasheet there is a +/-10% variance, need calibration to confirm the actual value
float VA1 = Vref / 1023.0 * analogRead(A1); // voltage at analog pin A1
float Vbat = VA1 * 5.7; // battery voltage