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

DHT 11

This document contains an Arduino sketch for interfacing with a DHT sensor to measure temperature and humidity. It initializes the sensor, reads data every two seconds, and prints the results to the serial monitor. The code supports different DHT sensor types by allowing the user to uncomment the appropriate line for their specific sensor model.

Uploaded by

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

DHT 11

This document contains an Arduino sketch for interfacing with a DHT sensor to measure temperature and humidity. It initializes the sensor, reads data every two seconds, and prints the results to the serial monitor. The code supports different DHT sensor types by allowing the user to uncomment the appropriate line for their specific sensor model.

Uploaded by

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

#include <DHT.

h>
#include <DHT_U.h>

#define DHTPIN 3 // what pin we're connected to

// Uncomment whatever type you're using!


#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// 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);

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;
}

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.println("");

You might also like