Battery level self contol

Dear Volks!
I know there were more similar topics, but I did not find the solution even after a lot of search
My device is one Nano, one HC-12 RF module and some sensor, which cc. every 5 minutes send the measured data.
I powered the system with 4 AA NiMH battery connected DIRECT an 5 V pin.
The system has been working perfectly for months, no crash, no problem.
Now I want to measure its battery level, and sendig that value across RF too.
First i connected simply the A7 pin to 5V pin, but from analogRead(A7) give always 1023, even if the real voltage is 4.1 or 4.2 etc.

I will continue the powering with 4 AA battery, no Lipo no 9v or similar accus. Plus info: If these 4xAA batterys are an VCC pin connected, the battery Life go down cc 25% faster. (Interesting, but fact)

Please some wort help, or link to any solution.

Thanks!

This link shows how to measure the voltage of the battery that is directly powering the Arduino.

...R

I powered the system with 4 AA NiMH battery connected DIRECT an 5 V pin.

Don't do that. Use a boost/buck voltage regulator to get consistent 5V from the battery. While there is some power loss in the regulator, it may even improve the battery life by allowing the batteries to be drawn down lower.

I disagree with that suggestion. Power loss with a buck/boost regulator will be in the 10-20% range, getting much worse as the batteries drop in voltage. If the clock speed is chosen appropriately the Arduino chip will run at 1.8V. At that point, a 3xAA NiMH cell pack is completely dead.

Nothing will be gained by using a buck/boost regulator unless some peripheral requires it.

Note: when powering by batteries through the Vcc input, if the battery voltage drops below the "brownout reset" level, the processor goes into the reset state. Sleep modes don't work in reset, of course, and the batteries will be quickly drained dead by the 8 mA or so reset current draw. So, either lower the brownout level or disable it.

Dear Robin2!
Thanks for link!
I read this before, but I just tried it not out. So far.
Comment: The result value from getBandgap() function is far from accurate and not linear, but as a informative guide beseem.

Perhaps this line is important?

const long InternalReferenceVoltage = 1056L;  // Adjust this value to your boards specific internal BG voltage x1000

Where would I know my board specific BG voltage? That is one simple Arduino Nano ATM328

Dear MorganS!
Thanks for the advice:

Don't do that. Use a boost/buck voltage regulator...

I've tried a lot of circuit, but as I wrote, the device works several months ago without fail. Simplicity is also important, 4 x AA NiMH battery can calmly connect direct to 5V pin. I can recommend. 9v accu work cirka 2-3 weeks.
4 x AA NiMH 2000 mAh battery are cheap, and really long life!

Where would I know my board specific BG voltage?

You measure it, or calculate it as the factor needed to get the correct voltage from whatever value is returned. In the latter case, start by assuming 1.1 V.