Modulo sensore di temperatura e umidità DHT11
| Pin | Segnale | Descrizione |
|---|---|---|
VCC |
power | Top right edge header hole for VCC |
DAT |
data | Middle right edge header hole for data |
GND |
ground | Bottom right edge header hole for ground |
| Da | A | Filo |
|---|---|---|
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:DAT |
green |
Questo esempio è stato scritto e verificato in compilazione per arduino-uno. Codey Online lo adatta a qualsiasi altra scheda supportata.
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("DHT11 sensor module example");
}
void loop() {
delay(2000); // DHT11 needs a slow refresh rate
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
if (isnan(humidity) || isnan(temperatureC)) {
Serial.println("Failed to read from DHT11 sensor");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\tTemperature: ");
Serial.print(temperatureC);
Serial.println(" *C");
}
Descrivi cosa vuoi realizzare. Codey Online scrive il codice, disegna lo schema di collegamento, lo compila e programma la tua scheda direttamente dal browser.
Inizia gratis