4

I'm quite new to ESP32 development. I've been using this devkit for a few small projects and everything was going smoothly until I decided to run it on battery. In particular, the ESP32 devkit I'm using, when connected to a battery, seems to have issues when trying to connect to the Wifi.

I'm using a 9V battery connected to a MB-V2 power supply to convert the output voltage to 3.3.V. The power supply board has the following specifics:

  • Input voltage: 6.5-9v (DC) via 5.5mm x 2.1mm plug
  • Output voltage: 3.3V/5v
  • Maximum output current: 700 mA
  • Independent control rail output: 0v, 3.3v, 5v to breadboard

As you can see in the picture, my multimeter measures an output voltage of about 3.3V

Voltage measurement

I built a sample project for debugging, here's the schematics: Schematics Pic of the setup

The battery is connected to the power supply which outputs 3.3V and powers the ESP32 through its 3.3V pin. I don't have a schematic for this specific devkit I'm using so the devkit used in the schematics is the DOIT one, hence all of the pins are off. The code is quite simple, though, so it hopefully can clear things a bit:

#include <WiFi.h>

const int uS_TO_S_FACTOR = 1000000;
const int TIME_TO_SLEEP = 3;
const int RED_LED_PIN = 32;
const int BLUE_LED_PIN = 25;
const int YELLOW_LED_PIN = 26;
const char SSID[] = "SSID";
const char PASS[] = "PASS";

void startupSequence(){
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  // Sequence
  digitalWrite(RED_LED_PIN, HIGH);
  digitalWrite(BLUE_LED_PIN, HIGH);
  digitalWrite(YELLOW_LED_PIN, HIGH);
  delay(1000);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  delay(500);
}

void setup(){
  Serial.begin(115200);
  while(!Serial){}
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
  pinMode(YELLOW_LED_PIN, OUTPUT);
  startupSequence();
  delay(500);
  digitalWrite(RED_LED_PIN, HIGH);
  delay(1000);
  Serial.print("Connecting to ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);  
  while ((WiFi.status() != WL_CONNECTED) && (millis()<10000)) {
      Serial.print(".");
      delay(500);
  }
  Serial.print("Connected. IP: ");
  Serial.println(WiFi.localIP());
  digitalWrite(RED_LED_PIN, LOW);
  if(WiFi.status() == WL_CONNECTED) //Run this only the first time
  {
    Serial.println("Connected");
    digitalWrite(YELLOW_LED_PIN, HIGH);
  } else
  {
    Serial.println("Not connected");
    digitalWrite(BLUE_LED_PIN, HIGH);
  }
  delay(3000);
  digitalWrite(BLUE_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  Serial.println("Going to sleep");
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  esp_deep_sleep_start();
}

void loop(){}

In the code, the ESP32 first lights up all LEDs, then it lights up the red LED while it tries to connect to the Wifi. After at most 10 secs, it lights up the yellow LED if it successfully connected, otherwise it lights up the blue LED. Also, as a last thing I send the ESP32 into deep sleep, as my intention was to measure its power consumption during sleep.

When connected to the PC, everything runs smoothly, while when connected to the battery the ESP32 (apparently) never exits the while loop and the red LED stays always on. The RED led then starts flickering and the power LED start blinking. Resetting it throught the RST button on the devkit causes the power LED to start blinking and the red LED never lights up. This continues until I cut off the power, then the code seems to start again from the beginning (i.e. the startup sequence) and the this behavior repeats.

I've read a few posts about similar issues with ESP32 devkits, but the problem was always about batteries not having high enough voltage, which doesn't seem to be my case. What could be causing the issue?

6
  • 4
    Common problem. These 9V block batteries are not meant for providing the needed current. They are only for low power appliances, like smoke detectors or IR remotes. Use a battery that can actually provide the needed current (can be up to 1A for a short time with Wifi working)
    – chrisl
    Mar 22, 2022 at 20:48
  • 1
    The third point my answer to this question talks about that.
    – chrisl
    Mar 22, 2022 at 20:52
  • "batteries not having high enough voltage, which doesn't seem to be my case" - It is as soon as you actually draw some power from the battery. Then - due to the batteries internal series resistance - the voltage will drop fast.
    – chrisl
    Mar 22, 2022 at 20:55
  • try the gnd pin on the upper right, that one on the lower/middle left is apparently not a gnd but is mislabeled as one on some of my modules. drove me nuts...
    – dandavis
    Mar 23, 2022 at 6:51
  • @chrisl you're completely right, I didn't realize it was the battery. I switched it with my phone power bank, which connects through a USB cable, and everything works fine. I didn't record currents over 120 mA even with the Wifi working though.
    – luigi
    Mar 23, 2022 at 17:56

1 Answer 1

3

I agree with chrisl, the battery does not have a low enough impedance to operate your project. What you are not taking into account is the transmitter current when it is transmitting to the wifi. I have been finding that when it wakes up it draws upwards of 500mA for a short time, measured with a scope and current probe. This appears during the " WiFi.scanNetworks()" function. Add on top of that all the LEDs and other electronics What do you think it will draw. The fact that it operates on the USB also helps confirm this. Try with 6 bigger batteries in series, I expect it to work properly. Check this link out from:Expressif, the manufacturer of the chip at https://esp32.com/viewtopic.php?t=2662

2
  • 2
    Also replacing the linear regulator with a switching one of >1A will help matters considerably.
    – Majenko
    Mar 23, 2022 at 10:18
  • 1
    Thank you very much, it was the battery, I switched it for a power bank and everything works fine. I didn't realize how power-hungry the ESP32 can be. I'll try to use some of the suggestion in this thread since the power bank has another issue: it shuts down during the ESP32 deep sleep phase, but that's a different issue.
    – luigi
    Mar 23, 2022 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.