0% found this document useful (0 votes)
24 views

DHT Code

The document describes code for reading temperature and humidity values from a DHT sensor and outputting the values over serial. The code initializes the DHT sensor, reads the temperature and humidity in Celsius and Fahrenheit in a loop, and computes the heat index.

Uploaded by

Suresh B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DHT Code

The document describes code for reading temperature and humidity values from a DHT sensor and outputting the values over serial. The code initializes the DHT sensor, reads the temperature and humidity in Celsius and Fahrenheit in a loop, and computes the heat index.

Uploaded by

Suresh B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "DHT.

h"
#define DHTPIN 2 //what pin we're conneccted to

#define DHTTYPE DHT11

// Initialize DHT sensor for normal 16mhz Arduino


DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very
slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Compute heat index


// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}

You might also like