Excessive Power Consumption Issue with ESP32, MPU6050, and Deep Sleep

87 views Asked by At

I'm facing an issue with excessive power consumption in a project using an ESP32, MPU6050, and deep sleep mode. The 9V battery I'm using lasts only about 11 hours, which is well below expectations.

Project Details:

ESP32: Esp32DevKit CH9102X

MPU6050: Connected to the ESP32 for acceleration and gyroscope measurements.

Battery: Powered by a 9V battery. Code:

Here is the relevant snippet of my code:

#include <Wire.h>
#include <WiFiManager.h>
#include <PubSubClient.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <esp_sleep.h>

const char* mqtt_server = "";
const int mqtt_port = ;
const char* mqtt_user = "MQTT_USER";
const char* mqtt_password = "MQTT_PASSWORD";

WiFiManager wifiManager;
WiFiClient espClient;
PubSubClient client(espClient);

Adafruit_MPU6050 mpu;

#define INTERVALO_DE_COLETA 10 * 60 * 1000000  // Deep Sleep Interval in microseconds (10 minutes)
#define PINO_LED 2  // Change to the GPIO your LED is connected to

RTC_DATA_ATTR int bootCount = 0;

void setup() {
  Serial.begin(115200);
  delay(10);

  bootCount++;
  Serial.println("Boot count: " + String(bootCount));

  // Initialize WiFiManager
  wifiManager.autoConnect("ESP32");

  // Initialize MPU6050
  mpu.begin();
  mpu.setAccelerometerRange(MPU6050_RANGE_2_G);

  Serial.println("Connected to Wi-Fi!");
  Serial.println("IP Address: " + WiFi.localIP().toString());

  client.setServer(mqtt_server, mqtt_port);

  // Configure LED pin
  pinMode(PINO_LED, OUTPUT);
  digitalWrite(PINO_LED, LOW);  // LED off during code execution
}

void reconnect() {
  Serial.println("Attempting to reconnect to MQTT...");
  while (!client.connected()) {
    Serial.print("Connecting to MQTT...");
    if (client.connect("ESP32Client", mqtt_user, mqtt_password)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, return status = ");
      Serial.println(client.state());
      delay(2000);
    }
  }
}

void loop() {
  // MPU6050 data collection...
  // Power management functions for MPU6050...
  // (Add specific code here to turn off MPU6050 before deep sleep and turn it back on after waking up)

  // MQTT data publishing...

  // Configure Deep Sleep for 10 minutes for ESP32
  esp_sleep_enable_timer_wakeup(INTERVALO_DE_COLETA);
  Serial.println("Entering deep sleep...");
  esp_deep_sleep_start();
}

Power Consumption:

I've taken power consumption measurements and noticed that the battery lasts only 11 hours. During deep sleep, the current should be very low, but it seems that something is consuming more energy than expected.

Used Libraries:

I am using the Wire, WiFiManager, PubSubClient, Adafruit_MPU6050, and Adafruit_Sensor libraries.

Questions:

Is there any interference between the libraries I'm using that could affect power consumption during deep sleep? Are there any specific configurations I should consider to reduce power consumption during deep sleep mode? Are there any best practices when using the MPU6050 with the ESP32 that could help optimize power consumption? I appreciate in advance any help or guidance the community can provide to resolve this issue.

0

There are 0 answers