Download and transfer the respective hex file depending on the version of your micro:bit.


- BBC micro:bit V1: microbit-battery-level.hex

- BBC micro:bit V2: microbit-v2-battery-voltage.hex


When the micro:bit is connected to a battery pack it will display the current voltage from the battery (in volts in micro:bit V1 and millivots in V2) as a numerical value.


gif showing battery level scrolling across the display on the microbit


In the above animation with a micro:bit V1, 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 https://os.mbed.com/teams/microbit/code/microbit-battery-test/ (V1) and GitHub https://github.com/microbit-foundation/microbit-v2-battery-voltage (V2).