How to save battery with M5StickC

  • I want to make something that can be battery driven for a long time with M5StickC.
    As an operation, M5StickC is in Deep Sleep state → button is pressed → process is performed → Deep Sleep state is entered again.
    I tried the following code, but M5StickC runs out of battery in one day. Even if I press the button after one day, it doesn't return.

    #include <Arduino.h>
    #include <M5StickC.h>
    #include "driver/rtc_io.h"
    RTC_DATA_ATTR int bootCount = 0;
    void setup(){
      M5.Lcd.println("Boot number: " + String(bootCount));
      M5.Lcd.println("Going to sleep now");
    void loop(){

    The information I got stated that it was consuming power because it was in a pull-up state. So I set it to pull-down during normal times so that it returns when it goes high. However, if I do so, it will return immediately after entering the DeepSleep state, and it will repeat indefinitely.

  • I only have limited expirience with sleep mode.
    But when a device comes out of Sleepmode it will not go in to the setup loop again. only during boot.

    And the second thing you could to it to reduce the CPU speed to 80 instead of the default 240. that also saves your battery

  • @takanotume24


    As you see in the tutorial I referenced above the ESP32 has different sleep modes, according how much battery you want to preserve:

    Modem-sleep, Light-sleep, Deep-sleep, Hibernation and Power off.

    During the real deep sleep the RAM is shut off. So your variable Bootcount will get lost after the deepSleep . You must write the values of all the variables you want to preserve into Eeprom (eg. of the RTC) before going into deep-sleep and the retreive them after wake up !

  • The esp in sleep mode consumes almost no power at all, but all the rest can additionally draw a few mA. In the link you have a discussion about what and how much electricity it draws additionally.

  • it also depends on the clock speed. sometimes speed is not needed. and it can save 50% of the power consumption on max CPU load