capteur-dht11.ino

Arduino UNO R4 WiFi · File : capteur-dht11.ino · Language : Arduino · Use case : Relever température et humidité avec un DHT11

The DHT11 works identically on the R4: the Adafruit library is portable on the RENESAS core. The 2 s polling with error checking is the base pattern of any homemade weather station.

Hardware

An Arduino UNO R4 WiFi (Renesas RA4M1 @ 14 MHz + companion ESP32-S3 Wi-Fi/BLE, 12x8 LED matrix, RGB LED) powered by USB or 6-24 V. 1 DHT11 sensor (3-pin module) + 10 kΩ resistor for bare sensors.

Wiring

VDD to 5 V, GND to GND, DATA to D4 with a 10 kΩ pull-up to 5 V.

How it works

readTemperature/readHumidity trigger the 1-wire protocol; a NaN flags a lost frame, retried next cycle without blocking loop().

Running it

Arduino IDE 2.x with the « Arduino UNO R4 Boards » core, « Arduino UNO R4 WiFi » board, serial port then Upload. The ESP32-S3 coprocessor updates separately if the IDE asks.

Variants

Move to the DHT22 (±0.5 °C), or show the values on the R4 WiFi LED matrix in scrolling mode.

capteur-dht11.ino

// DHT11 sur D4 : temperature + humidite vers le moniteur serie.
#include <DHT.h>   // "DHT sensor library" (Adafruit) via le gestionnaire

#define TYPE_DHT DHT11
DHT dht(4, TYPE_DHT);

unsigned long t0 = 0;

void setup() {
  Serial.begin(9600);
  dht.begin();
  Serial.println(F("DHT pret"));
}

void loop() {
  if (millis() - t0 < 2000) return;   // cadence mini du capteur
  t0 = millis();

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println(F("lecture ratee (cabling ?)"));
    return;
  }
  Serial.print(F("T = ")); Serial.print(t, 1);
  Serial.print(F(" C | HR = ")); Serial.print(h, 1);
  Serial.println(F(" %"));
}

// Le RA4M1 est plus rapide que les AVR : les temporisations
// 1 fil du protocole restent generees correctement par la lib.

← Back to the board