capteur-dht.ino
The DHT11 sensor delivers temperature and humidity, published to the cloud every 30 s as a private event. The pace respects the Particle rate limit and the battery; the JSON fits in 64 bytes.
Hardware
A Particle Photon module (2.4 GHz Wi-Fi, STM32 microcontroller, metal shielding) powered by USB or VIN. 1 DHT11 sensor (3-pin module) + 10 kΩ resistor for bare sensors.
Wiring
VDD to 3V3, GND to GND, DATA to D5 with a 10 kΩ pull-up to 3V3.
How it works
The Adafruit library drives the 1-wire protocol; the reading is formatted as JSON then Particle.publish uploads it as a private event (visible to your account only).
Running it
With the Particle CLI: particle flash --serial (DFU mode, double reset) or OTA flash once the board is online. Safe Mode (reset + WiFi) covers troubleshooting.
Variants
Move to DHT22 for ±0.5 °C, or buffer locally (SaveToSparkFile/SF25) when the cloud is unreachable.
capteur-dht.ino
// DHT11 sur D5 + publication periodique vers le cloud.
// Bibliotheque : "DHT sensor library" (Adafruit) via Particle Build.
#include "DHT.h"
#define TYPE_DHT DHT11
DHT dht(D5, TYPE_DHT);
unsigned long dernierePublication = 0;
const unsigned long PERIODE = 30000; // 30 s : menage la limite cloud
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
if (millis() - dernierePublication < PERIODE) return;
dernierePublication = millis();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("lecture DHT ratee"));
return;
}
char trame[64];
snprintf(trame, sizeof(trame),
"{\"t\":%.1f,\"h\":%.1f}", t, h);
Particle.publish("mesures", trame, 60, PRIVATE);
Serial.println(trame);
}
// getTemperature() (API systeme) donne aussi la temperature du MCU.