How to check your arduino's battery pack level?

Hi, I wanted to share this script, the battery pack connects to analog A0 for + and negative to gnd

And when the battery reaches a new low it will store the percent in the battery_percent variable from 0-100

int lowest_level=1024;
int read_battery_level=0;
int battery_percent=100;
int temp_math=0;
void setup() {
Serial.begin(9600);
}

void loop(){
read_battery_level=analogRead(A0);
if(read_battery_level<lowest_level){
lowest_level=read_battery_level;
temp_math=int(String(read_battery_level/1024.0).indexOf('.'));
if(int(read_battery_level/1024)!=1){
Serial.println(String(read_battery_level/1024.0).substring(2,4) + "%");
battery_percent=String(read_battery_level/1024.0).substring(2,4).toInt();
}else{
Serial.println("100%");
battery_percent=100;
}
}
}

Connecting batteries directly to an analog pin is a bad idea without a divider network made to suit the particular voltage of the particular battery.
That at least offers some protection to the analog pin.

Simple enough to do as shown here

Nice thanks