DHT12 humidity temperature sensor and Arduino Uno example

DHT12 Digital temperature and humidity sensor is a calibrated digital output record of temperature and humidity, DHT11 The upgrade product. Application-specific digital temperature and humidity sensor module and semiconductor, ensure high reliability and excellent long-term stability.

DHT12 With a single bus, and standards I2C Two kinds of communication and single bus communication mode is fully compatible with DHT11。 Standard bus interface makes it simple and quick to system integration.

With super small size, low power consumption, suitable for a wide variety of applications. I2C Communication uses standard communication sequence, the user can directly I2C Communication on the bus, no additional wiring, simple to use. Two way switch, users are free to choose, easy to use, should be a broad range of areas. Products for the 4 Lead, convenient connection, provides special packages according to user needs.

Features:

Super compact size
Super low power consumption
Super low voltage operation
Standard I2C and 1-wire interface.
Semi conductor technology
Sensing range
Temperature: -20 ~ +60 C
Humidity: 20-95 RH
Humidity:
Resolution: 0.1%RH
Repeat: -+ 1%RH
Precision 25C @ -+5RH
Temperature:
Resolution: 0.1C
Repeat: -+0.2C
Precision: 25C @ -+0.5C
Power: DC 2.7-5.5V
Normal current 1mA
Standby current 60uA
Sample cycle: > 2 seconds

 

 

Layout

This shows how to connect the DHT12 to an Arduino Uno

 

Code

I used the following library  https://github.com/xreef/DHT12_sensor_library 

This is the built in example


 

#include "Arduino.h"
 
#include <DHT12.h>
 
// Set dht12 i2c comunication on default Wire pin
DHT12 dht12;
 
void setup()
{
Serial.begin(112560);
// Start sensor handshake
dht12.begin();
}
int timeSinceLastRead = 0;
 
void loop()
{
// Report every 2 seconds.
if(timeSinceLastRead > 2000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Read temperature as Celsius (the default)
float t12 = dht12.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f12 = dht12.readTemperature(true);
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h12 = dht12.readHumidity();
 
bool dht12Read = true;
// Check if any reads failed and exit early (to try again).
if (isnan(h12) || isnan(t12) || isnan(f12)) {
Serial.println("Failed to read from DHT12 sensor!");
 
dht12Read = false;
}
 
if (dht12Read){
// Compute heat index in Fahrenheit (the default)
float hif12 = dht12.computeHeatIndex(f12, h12);
// Compute heat index in Celsius (isFahreheit = false)
float hic12 = dht12.computeHeatIndex(t12, h12, false);
// Compute dew point in Fahrenheit (the default)
float dpf12 = dht12.dewPoint(f12, h12);
// Compute dew point in Celsius (isFahreheit = false)
float dpc12 = dht12.dewPoint(t12, h12, false);
 
Serial.print("DHT12=> Humidity: ");
Serial.print(h12);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t12);
Serial.print(" *C ");
Serial.print(f12);
Serial.print(" *F\t");
Serial.print(" Heat index: ");
Serial.print(hic12);
Serial.print(" *C ");
Serial.print(hif12);
Serial.print(" *F");
Serial.print(" Dew point: ");
Serial.print(dpc12);
Serial.print(" *C ");
Serial.print(dpf12);
Serial.println(" *F");
}
timeSinceLastRead = 0;
}
delay(100);
timeSinceLastRead += 100;
 
}

 

 

 

Output

DHT12=> Humidity: 33.70 % Temperature: 20.20 *C 68.36 *F Heat index: 19.16 *C 66.48 *F Dew point: 3.60 *C 38.48 *F
DHT12=> Humidity: 39.70 % Temperature: 20.60 *C 69.08 *F Heat index: 19.75 *C 67.55 *F Dew point: 6.34 *C 43.41 *F
DHT12=> Humidity: 44.60 % Temperature: 21.20 *C 70.16 *F Heat index: 20.54 *C 68.97 *F Dew point: 8.64 *C 47.55 *F
DHT12=> Humidity: 47.80 % Temperature: 21.80 *C 71.24 *F Heat index: 21.28 *C 70.31 *F Dew point: 10.25 *C 50.45 *F
DHT12=> Humidity: 48.90 % Temperature: 22.40 *C 72.32 *F Heat index: 21.97 *C 71.55 *F Dew point: 11.16 *C 52.08 *F
DHT12=> Humidity: 53.90 % Temperature: 22.90 *C 73.22 *F Heat index: 22.65 *C 72.78 *F Dew point: 13.14 *C 55.66 *F
DHT12=> Humidity: 55.10 % Temperature: 23.60 *C 74.48 *F Heat index: 23.45 *C 74.22 *F Dew point: 14.15 *C 57.46 *F
DHT12=> Humidity: 54.90 % Temperature: 23.90 *C 75.02 *F Heat index: 23.78 *C 74.80 *F Dew point: 14.37 *C 57.86 *F
DHT12=> Humidity: 45.30 % Temperature: 24.40 *C 75.92 *F Heat index: 24.08 *C 75.34 *F Dew point: 11.80 *C 53.24 *F
DHT12=> Humidity: 40.60 % Temperature: 24.60 *C 76.28 *F Heat index: 24.18 *C 75.52 *F Dew point: 10.28 *C 50.50 *F
DHT12=> Humidity: 37.10 % Temperature: 24.80 *C 76.64 *F Heat index: 24.30 *C 75.75 *F Dew point: 9.09 *C 48.35 *F

 

Link

Under $1 for one of these sensors

1pcs DHT-12 DHT12 sensor Digital output Temperature and Humidity Sensor high quality

Related