XIAO ESP32C3 Battery ussage

Update now power is 36ma. Put CPU at half speed dropped tp 27ma. Plenty of power to run off a good 18650 for day. charging works great using USB C charger.

Happy so far.

Good morning. Can someone tell me how to implement an ON OFF switch when the battery is being used to turn off the ESP32C3?
thank you so much.

I am facing a similar issue, battery is working fine when charging. I have tried on 2 different ESP32C3 xiao modules. They work fine for one day and next day when I remove usb type C, they don’t work on battery. Battery and xiao ESP32C3 is mounted inside an enclosure.

Hi there,
I see several options for Battery’s holder with a switch

Cr2032, or 18650. These are AOK.and if you want to ONLY charge the battery. one like this.

GL :slight_smile: PJ :v:

1 Like

News? Can I purchase some of them, or it’s just a waste of money?

1 Like

Battery is working fine for me. Here is my test script.
Hardware is just a basic lipo battery attached and two buttons connected to gpio 2/3 and gnd

#include "WiFi.h"
#include <PubSubClient.h>


const char* ssid     = "DronesAreWatching";
const char* password = "";   

const char* mqtt_server = "blue.home";
const char* mqttUser = "internal";
const char* mqttPassword = "";

void debug(String msg){

WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {
  // We start by connecting to a WiFi network
  debug("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

  debug("WiFi connected");
  debug("IP address: ");
  // debug(WiFi.localIP());

void setup() {
  pinMode(D0, INPUT_PULLUP);
  debug("Startup...send message");


  client.setServer(mqtt_server, 1883);
  client.connect("ESP8266Client", mqttUser, mqttPassword);

  uint64_t gpio_reason = esp_sleep_get_gpio_wakeup_status(); 
  int GPIO = 0;
  if (gpio_reason > 0){
    GPIO = log(gpio_reason)/log(2);

  String GPIOString = String(GPIO);
  int str_len = GPIOString.length() + 1; 
  char char_array[str_len];
  GPIOString.toCharArray(char_array, str_len);

  client.publish("mouse/trigger", char_array);

  esp_deep_sleep_enable_gpio_wakeup((1ULL << 2), ESP_GPIO_WAKEUP_GPIO_LOW);  //GPIO2
  esp_deep_sleep_enable_gpio_wakeup((1ULL << 3), ESP_GPIO_WAKEUP_GPIO_LOW);  //GPIO3

  debug("Going to sleep in 5 seconds"); //time to send message


void loop() {

One way that I have used successfully on boards that don’t have any built-in circuitry to detect the USB is to simply put in a resistor divide by 2 circuit from the 5V pin and connect the centre of the resistor divider to an analog input and read the voltage. A bit of maths lets you work out if the 5V is present. (Note that it might not be exactly 5v depending on diodes, usb supply etc. But there ought to be a significant difference to the voltage sensed this way between when the USB is plugged in or if you are running on a single cell LiPo battery.
Note that you need the resistor divider because the 5V is more than the chip’s inputs can take. Divide by 2 is safe (i.e. 5/2 is less than the 3.7 or so that the pins can take) There is probably a diode from the USB V+ as well that drops the voltage actually seen at the 5V pin.
Good luck!

1 Like

Hi folks, thanks for this thread. Since no one has mentioned ESP32S3 boards yet in this discussion, I’ll add that my experience is identical to @chipko. When plugged into USB with a battery attached, the charging light blinks and the program runs. But when unplugged, the program halts and does not run, even after manual restarting. This is the sample Arduino Blink program, which does not include any use of Serial.begin(). I have 3 other boards that all work with this same program and same battery. I think some boards might just be faulty.