0% found this document useful (0 votes)
8 views1 page

DHT11 Sensor Arduino 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)
8 views1 page

DHT11 Sensor Arduino 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

#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() {
[Link](9600);
[Link]("DHTxx test!");
[Link]();
}
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 = [Link]();
// Read temperature as Celsius
float t = [Link]();
// Read temperature as Fahrenheit
float f = [Link](true);

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

// Compute heat index


// Must send in temp in Fahrenheit!
float hi = [Link](f, h);

[Link]("Humidity: ");
[Link](h);
[Link](" %\t");
[Link]("Temperature: ");
[Link](t);
[Link](" *C ");
[Link](f);
[Link](" *F\t");
[Link]("Heat index: ");
[Link](hi);
[Link](" *F");
}

You might also like