🛠 Sommeil profond et réveil sur broche WKP
Objectives
Extend battery autonomy: the Photon consumes approximately 80 mA during active Wi-Fi operation but only ~80 µA in deep sleep (datasheet, Power). You will put the board to sleep between measurements and wake it up via the WKP pin or through a remote cloud command.
Hardware
- 1 Particle Photon powered by battery (VIN pin 3.6–5.5 V, or micro-USB)
- 1 switch connected between WKP and 3V3 for hardware wake-up
- >
Complete code
// photon-sommeil-reveil.ino — mesure, sommeil profond, réveil WKP
#include <application.h>
void setup {
Serial.begin(9600);
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
int brut = analogRead(A0); // mesure avant de dormir
Particle.publish("capteur/brut", String(brut), PRIVATE);
digitalWrite(D7, LOW);
Serial.println("Endormissement...");
// >
// Device OS API reference (modes, delai, broche de reveil).
System.sleep(WKP, RISING, 3600, SLEEP_MODE_DEEP);
// Au reveil, le Photon redemarre : setup est rejoue.
}
void loop { }
Expected verification
After publishing, the board sleeps (consumption drops to ~80 µA); a state change on WKP (or the expiration of the delay) wakes it up: it restarts, reconnects, and publishes a new value. Remote wake-up is possible: curl https://api.particle.io/v1/devices/<ID>/wakeup -d arg=please -H "Authorization: Bearer $TOKEN" (endpoint confirmed by the datasheet).
Common errors
- Expecting the loop to resume: in deep sleep, wake-up is a complete restart, and all context is lost.
- Forgetting that Wi-Fi reconnects at each wake-up: allow several seconds before the first publish.
- Neglecting board-to-board variance: one documented case shows a difference between 1 day and 30 days of autonomy on three identical Photons.
- Weak power supply: during Wi-Fi peaks, you must be able to provide ~1 A at VIN.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-evenement.inoArduinofonction-distance.inoArduinocapteur-dht.inoArduinoruban-neopixel.inoArduinopwm-respiration.inoArduino