A simple library for using DHT-type sensors (DHT11, DHT22, etc.).
Download and import the library in your IDE.
Go to Sketch |> Include Library |> Add .ZIP Library...
#include <DHT_N128.h>
#define PIN 7
DHT dht(PIN, DHTSensorType::DHT22);
void setup() {
Serial.begin(9600);
Serial.println("Humidity/Temperature Sensor Example");
dht.begin();
}
void loop() {
float rh = dht.readHumidity(); // Relative Humidity
float temp = dht.readTemperature(); // Default: TempScale::Celsius
if (isnan(rh) || isnan(temp)) {
Serial.println("Error (Not-A-Number) when trying to read humidity and temperature.");
} else {
Serial.print(rh); Serial.println(" %RH");
Serial.print(temp); Serial.println(" ˚C");
}
delay(2000);
}You can find more usages examples in examples/.
- Eduardo Gomez (Professor. Head of "Robotics and Automation" subject).
- Luciano Yurquina (Testing and Research).