Portfolio. BHSAD Arduino Prototyping | L4, Harduino: Drawing light | Page 5
DHT11
temperature and humidity
GRD
#include
#include
220 ohm
#include “DHT.h”
5V
#define DHTPIN 2
DHT dht(DHTPIN, DHT11);
void setup() {
Serial.begin(9600);
dht.begin();
}
OMNI
MAGAZINE
COULD HAVE
BEEN READ
IN 1978
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(“Error”);
return;
}
Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(“ %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.println(“ *C “);
}