
TinyML Cookbook
By :

For many TinyML applications, batteries could be the only power source for our microcontrollers.
In this final recipe, we will learn how to power microcontrollers with AA batteries.
The following Colab notebook contains the code referred to in this recipe:
06_estimate_battery_life.ipynb
: Microcontrollers don't have a built-in battery, so we need to supply an external one to make the device work when it is not connected through the micro-USB cable.
To get ready for this recipe, we need to know what types of batteries we need and how we can use them correctly to supply power.
Batteries are sources of electric power and have a limited energy capacity. The energy capacity (or battery capacity) quantifies the energy stored and is measured in milli-ampere-hour (mAh). Therefore, a higher mAh implies a longer battery life.
The following table reports some commercial batteries that find applicability with microcontrollers:
Figure 2.34 – Suitable commercial batteries for microcontrollers
The battery selection depends on the required microcontroller voltage and other factors such as energy capacity, form factor, and operating temperature.
As we can observe from the preceding table, the AA battery provides a higher capacity, but it supplies 1.5 V, typically insufficient for microcontrollers.
Therefore, how can we power microcontrollers with AA batteries?
In the following subsections, we will show standard techniques to either increase the supplied voltage or the energy capacity.
When connecting batteries in series, the positive terminal of one battery is connected to the negative terminal of the other one, as shown in the following figure:
Figure 2.35 – Batteries in series
Important Note
This approach will not extend the battery capacity but just the supplied voltage.
The new supplied voltage () is as follows:
Where N is the number of connected batteries in series.
For example, since one AA battery supplies 1.5 V for 2400 mAh, we could connect two AA batteries in series to produce 3.0 V for the same energy capacity.
However, if the battery capacity is not enough for our application, how can we increase it?
When connecting batteries in parallel, the positive terminals of the batteries are tied together with one wire. The same applies to the negative terminals, which are joined together as shown in the following figure:
Figure 2.36 – Batteries in parallel
Important Note
This approach will not increase the output voltage but just the battery capacity.
The new battery capacity () is as follows:
Where N is the number of connected batteries in parallel.
For example, since one AA battery has a battery capacity of 2400 mAh, we could connect two AA batteries in parallel to increase the battery capacity by two times.
Now that we know how to connect multiple batteries together to get the desired output voltage and energy capacity, let's see how we can use them to power the microcontrollers.
Microcontrollers have dedicated pins for supplying power through external energy sources, such as batteries. These pins have voltage limits, commonly reported in the datasheet.
On the Arduino Nano, the external power source is supplied through the Vin pin. The Vin input voltage can range from 5 V–21 V.
On the Raspberry Pi Pico, the external power source is supplied through the VSYS pin. The VSYS input voltage can range from 1.8 V – 5.5 V.
On both platforms, the onboard voltage regulator will convert the supplied voltage to 3.3 V.
Disconnect the Arduino Nano and Raspberry Pi Pico from the micro-USB and keep all the components on the breadboard.
The battery holder considered for this recipe connects the AA batteries in series. We recommend not inserting the batteries in the battery holder yet. The batteries should only be inserted when the electric circuit is completed.
The following steps will show how to power the Arduino Nano and Raspberry Pi Pico with batteries:
Figure 2.37 – Connect the battery holder to the bus rails
Figure 2.38 – Connect the bus rails to the microcontroller power pin and GND
As you can observe from the preceding figure, VIN (Arduino Nano) and VSYS (Raspberry Pi Pico) are connected to the positive battery holder terminal through the + bus rail.
The LED application should now work again.
However, one thing we might be curious about is how can we evaluate the lifetime of a battery-powered application?
Once we have chosen the battery for the microcontroller, we can estimate its lifetime with the following formula:
Where:
Figure 2.39 – Physical quantities of the battery lifetime estimate formula
The following Python code calculates the battery life in hours and days:
battery_cap_mah = 2400 i_load_ma = 1.5 battery_life_hours = battery_cap_mah / i_load_ma battery_life_days = battery_life_hours / 24 print("Battery life:", battery_life_hours,"hours,", battery_life_days, "days")
The preceding code estimates the battery life for the case when the battery capacity (battery_cap_mah
) is 2400 mAh, and the load current (i_load_ma
) is 1.5 mA.
The expected output is as follows:
Figure 2.40 – Expected output from the battery life estimator
Although the formula above is an estimation and valid under ideal conditions, it is enough to understand how long the system could last. A better model could include other factors such as battery self-discharge and temperature.
Change the font size
Change margin width
Change background colour