sommeil-profond.ino

ESP8266 (ESP-12E module) · File : sommeil-profond.ino · Language : Arduino · Use case : Réveiller l'ESP8266 toutes les minutes (deep sleep)

In deep sleep the ESP8266 drops under 20 µA: ideal for a battery sensor. Wake-up happens via the GPIO16→RST bridge, and RTC memory keeps the cycle counter across resets.

Hardware required

An ESP-12E module (ESP8266EX, 2.4 GHz Wi-Fi) mounted on a NodeMCU / Wemos D1 mini board, powered over micro-USB. Wire bridge between GPIO16 (D0) and RST on the module (internal on Wemos D1 mini).

Wiring

GPIO16 wired to RST. On battery, power the module directly: the NodeMCU board LDO sips more than the sleeping 8266.

How it works

ESP.deepSleep cuts everything but the RTC; on wake the chip restarts as at power-on — only the 4 KB RTC memory survives, hosting the counter. WAKE_RF_DEFAULT keeps the radio initialized. In the Arduino IDE, install the « esp8266 » package, select « NodeMCU 1.0 (ESP-12E Module) » then Upload (hold GPIO0 LOW if flashing fails). The A0 ADC reads 0-1 V (NodeMCU divider: 0-3.3 V).

Going further

Wake on a button press (RC circuit on RST), or adapt the period to measurement criticality.

sommeil-profond.ino

// Deep sleep 60 s — RST relie a GPIO16/D0 sur le module.
// Le compteur de cycles survit dans la RTC memory (4 Ko alimentee).
extern "C" {
#include "user_interface.h"
}

RTC_MEM uint32_t cycles;    // RTC memory : conservee en deep sleep

void setup() {
  Serial.begin(115200);
  delay(100);
  cycles++;
  Serial.printf("\nCycle n°%u — lecture capteur, envoi, puis dodo\n", cycles);

  // (mesure + envoi reseau courts ici)

  Serial.println("Deep sleep 60 s...");
  Serial.flush();
  delay(10);
  ESP.deepSleep(60 * 1000000ULL, WAKE_RF_DEFAULT);
  // le module est REINITIALISE au reveil : setup() repart
}

void loop() {}

← Back to the board