**Abstract**

The ESP32 is a popular microcontroller for IoT use cases. For many IoT applications (e.g., environmental sensors or wearables), a continuous power supply is either not possible or too cumbersome, requiring battery operation. However, the ESP32 has a relatively high power consumption. This chapter focuses on battery life optimization methods for this family of microcontrollers. For scenarios where data logging is relevant, methods for increasing communication speed in relation to power consumption are examined in detail. Measurements of seven different commercially available development boards were evaluated in terms of sleep modes, reduced CPU frequencies, and serial communications with the goal of better power efficiency. Therefore, the common scenario of data logging was compared with the performance and power consumption when communicating with different SD cards and CPU frequencies via the SPI and SD bus. Our test results showed that peripheral components (such as voltage regulators) have a large impact on the power consumption of the ESP32 microcontrollers, especially in sleep mode. For data logging, higher clock rates combined with high-quality SD cards and using the SD bus in 4-bit mode resulted in the lowest battery discharge.

**Keywords:** ESP32, energy consumption, write speed, performance to energy, SD bus, SD-MMC, SDIO, CPU frequency, battery life, IoT, wearables

#### **1. Introduction**

For various research questions, comprehensive and objective data collection using appropriate sensor technology is essential. However, for some applications, there are no (affordable) devices available on the market or do not provide the needed data quality, form factor, or access to raw data. As a side effect, one might have special requirements regarding data privacy and protection. As a scientific institution in the biomedical field that has to deal with specific needs and research questions, financial restrictions, and sensitive data retrieved from the sensors, the above-mentioned aspects lead to many software and IoT-related hardware projects [1–4]. One of our medical projects intends to measure heart rate variability. The sensor has to exceed the precision of a clinical-grade ECG device, but at the same time has to be wireless, to be worn on the body, waterproof, heat resistant, and able to resist chemical disinfection [2].

The ECG-based measurement allows medical grade data quality for examining the activity or response of the autonomous nervous system, which is involved in many diseases such as chronic pain, addiction medicine, mental illnesses (e.g. depression) as well as in sports medicine and performance diagnostics. The device is used in several clinical trials and connected to an open-source IoT platform, that allows fleet management of many devices [1]. Another project that uses the same sensor deals with VR-based addiction diagnostics and treatment. In this use case, the main aspect is interoperability with the development environment and the flexibility of integrating further sensors. In both cases, it is particularly important that the battery life is as long as possible and that the raw data (ECG) is stored locally at the highest possible resolution, as correct wireless data transfer cannot always be ensured. There are many more applications in projects, where our custom build sensors came to use, for example, in environmental measurements (urban climate and fine dust measurements, spectro-radiometric measurements, or radiation sensors) or lab sensory, that is used as part of lab experiments or as a fundamental part of lab automation within microbial or cellular experiments [1].

Like us, many other research teams want to take data acquisition into their own hands and develop specially adapted instruments [5, 6]. It is also possible to describe exactly and transparently which algorithms were used to increase the reproducibility of the results. The widespread use and rapid development of easy-to-program microcontrollers such as the Raspberry Pi or microcontrollers based on the Arduino platform, as well as the many sensor modules, libraries and sample codes and projects available, make this easier, and once the basic system is developed, it is easy to add more sensors or adapt the system to different requirements. This allows data to be collected quickly under laboratory conditions. However, if the prototype is to be used in real-life scenarios or in field studies, additional obstacles need to be considered. Haghi et al. list the following points that should be considered when developing wearable IoT devices [7]:


In order to limit the scope of this work, we will mainly focus on the aspects of reducing power consumption, as this is directly related to wearability and form factors. In addition, we will also look at data storage, as if large amounts of data are collected and need to be stored locally, this will also have a significant impact on battery life. The aim of this work is to list possible approaches for an optimal compromise between data write speed and energy efficiency in order to derive a best practice for custom development.
