sommeil-basse-consommation.ino
The battery survival cycle: wake, DHT reading, cloud publish, then 60 s deep sleep with the radio off. Restarting each cycle simplifies the firmware at the cost of a cloud reconnect — the classic coin-cell sensor trade-off.
Hardware
A Particle Boron module (nRF52840, Wi-Fi + Bluetooth LE, cellular variant where applicable) with on-board antenna. 1 DHT11 sensor + LiPo battery (the module handles charging on its VUSB/VIN pin).
Wiring
DHT on D5 as in the sensor example; battery on the LiPo pads. External antenna if the enclosure is metal.
How it works
System.sleep(SLEEP_MODE_DEEP, 60) cuts everything but the wake timer; the board restarts from setup() on wake. WiFi.off/Cellular.off avoid residual radio draw.
Running it
Install the Particle CLI (particle setup), flash with particle flash --serial or OTA (particle flash <name> firmware.bin). The Device Cloud app or REST API complete the deployment.
Variants
External interrupt wake (interrupt on D2 for a detector), or adaptive: lengthen sleep while the reading is stable.
sommeil-basse-consommation.ino
// Cycle basse consommation : mesure, publication, Stop 60 s.
// Le lien cloud est coupe pendant le Stop (reconnexion au reveil).
#include "DHT.h"
DHT dht(D5, DHT11);
void setup() {
Serial.begin(9600);
dht.begin();
Particle.process(); // laisse la connexion s'etablir
}
void loop() {
// 1) Rejoindre le cloud (bloquant jusqu'a 10 s).
if (!Particle.connected()) Particle.connect();
// 2) Mesurer et publier.
dht.measure();
char trame[64];
snprintf(trame, sizeof(trame), "{\"t\":%.1f,\"h\":%.1f}",
dht.readTemperature(), dht.readHumidity());
Particle.publish("mesure-batterie", trame, 60, PRIVATE);
// 3) Endormissement : radio eteinte, courant divise.
Serial.println("Endormissement 60 s...");
Serial.flush();
WiFi.off();
Cellular.off(); // ignore sur les modeles sans cellulaire
delay(100);
System.sleep(SLEEP_MODE_DEEP, 60); // deep sleep 60 s
// Au reveil, la carte redemarre depuis setup() :
// le cycle complet se repete a chaque reveil.
}
// Sur batterie 180 mAh, le deep sleep entre deux publications
// fait tenir des semaines ; verifier le courant reel de sa variante.