So I use the following function to get the battery level of my 18650 battery with an arduino pro mini 3.3V. I've got 2 x 10k resistors in series between the + & - of the battery with A0 connected to the middle of the two resistors. For some reason the reading fluctuates and isn't anywhere near accurate. I've tried using a lower resistance (5.1k) and still had the same problem. Any ideas?
int batteryLevel(){
int sensorValue = analogRead(batteryPin); //read the A0 pin value
float voltage = sensorValue * (3.3 / 1023.00) * 2; //convert the value to a true voltage.
voltage = voltage * 100; //so that it prints as an int without decimal places
return voltage;
}