🛠 Station météo autonome en deep sleep

ESP32 (original, ESP32-WROOM-32 class) · avance · Schéma : IMG-esp32-avance-1-deep-sleep-station-meteo.svg — Station météo ESP32 sur batterie avec capteur SHT31, courbe de consommation alternant pics de mesure et sommeil à 150 µA

Objectives

Build an autonomous weather station: measure temperature and humidity with an SHT31, then put the ESP32 to sleep between measurements. In deep sleep, the ESP32 drops to approximately 150 µA — only the timer and RTC remain active, and RTC memory preserves variables marked with RTC_DATA_ATTR. You will master wake-up causes, I2C, and power management discipline.

Hardware

Complete code

#include <Wire.h>
#include <Adafruit_SHT31.h>

Adafruit_SHT31 sht31 = Adafruit_SHT31;
RTC_DATA_ATTR uint32_t compteur = 0;   // survit au deep sleep

void setup {
  Serial.begin(115200);
  delay(200);
  esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause;
  Serial.printf("\nReveil : %d (4 = timer)\n", (int)cause);

  Wire.begin(21, 22);
  sht31.begin(0x44);
  float t = sht31.readTemperature;
  float h = sht31.readHumidity;
  compteur++;
  Serial.printf("Mesure %u : %.2f C, %.1f %%\n", compteur, t, h);

  esp_sleep_enable_timer_wakeup(900ULL * 1000000ULL); // 15 min
  Serial.println(F("Endormissement..."));
  Serial.flush;
  esp_deep_sleep_start;
}

void loop {}   // jamais atteint : tout se passe dans setup

Expected verification

At each wake-up, the console displays a measurement with an increasing counter (RTC memory is indeed preserved), then the board stays silent for 15 minutes. With a micro-ammeter, you measure approximately 40 mA during measurement and approximately 150 µA during deep sleep.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials