I've made a "weather station" using the ESP8622. To save battery I'm using sleep mode but still the battery is drained after a couple of days. According to this post it should last at least a year.

I haven't done any measurements yet, wanted to know if there's something obvious that I've missed that could explain why the battery is drained so quickly? Attaching code and an image showing the hardware setup.

#include "DHT.h"
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define DHTPIN D2
#define DHTTYPE DHT22

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

const char* host = "xxxx";

void setup() {

  Serial.print("Connecting to ");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
  ESP.deepSleep(18e8); //30 minutes

void readSensorsAndPost() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  char charVal[10];
  dtostrf(t, 5, 2, charVal);

bool makeAnHttpRequest(String msg) {
  //send the value

void loop() {


esp8622 and DHT22

  • First do measurments
    – Pararera
    Dec 16 '18 at 17:02

The example shows a Sparkfun Thing, which the article notes doesn't have extra peripherals. What you show is something different, like a NodeMCU dev board, which typically has a linear regulator, possibly a power LED (which the article notes can be removed).

I see you're using a DHT11 or DHT22, which has a pull-up resistor. The pull-up resistor is constantly using power. Instead of connecting the pull-up to the power rail, you can connect it to a GPIO pin and pull that pin LOW before you go into sleep, which effectively disables the sensor and stops it from drawing power just to keep the data line high.

Safe to say that somewhere there is something drawing power -- have you measured the actual current draw in deep-sleep, or are you only noting that your batteries run low sooner than expected?

  • I haven't done any measurements yet but when I have I will post the result. Will also change the setup as per your suggestion.
    – Christian
    Dec 15 '18 at 14:30
  • 3
    You are also powering the USB interface chip, which never goes to sleep.
    – Majenko
    Dec 15 '18 at 17:20
  • @Majenko is there an easy way to disable powering the USB interface chip?
    – Christian
    Dec 16 '18 at 8:27
  • Migrate to a standalone module without all the extra junk and use an external USB adapter.
    – Majenko
    Dec 16 '18 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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