Download and flash the attached microbit-battery-level.hex file to your micro:bit.

When the micro:bit is connected to a battery supply it will display the current supply from the battery (in volts) as a numerical value.

gif showing battery level scrolling across the display on the microbit

In the above animation, the reading is 3.11v, which is a typical output of two AAA batteries that have not had much use.

This code has been developed in c++ so cannot be imported into the MakeCode or Python Editors. The code for this can be found on the mBed OS website