How to Control Temperature with Arduino

DHT11 and DHT22 sensor is used for relative measurement of temperature and humidity. These sensors are pre-calibrated and extra components are not required for complete functionality. There is also a very basic chip inside, that does some analog to digital conversion and spits out a digital signal with the temperature and humidity. The digital signal is fairly easy to read using any microcontroller.

Industries and the field of automation are working on temperature control, for example, climate control option in cars for air conditioning, temperature gauge to observe engine temperature. In automation, suppose an example to control the speed of the ceiling fan or air conditioner in accordance to the environmental temperature.

 

Different Types of DHT Sensors

DHT sensors come in two different variants, DHT11 and DHT22. Both these sensors look the same and have the same configuration for pin out but they have different characteristics. 

DHT11

  • Ultra low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20-80% humidity readings with 5% accuracy
  • Good for 0-50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1″ spacing

DHT22

  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy>
  • Good for -40 to 80°C temperature readings ±0.5°C accuracy
  • No more than 0.5 Hz sampling rate (once every 2 seconds)
  • Body size 15.1mm x 25mm x 7.7mm
  • 4 pins with 0.1″ spacing

What is DHTT With a Module?

DHT11 with module

This DHT sensor comes with a chip which converts analog signals to digital and makes it easy to read values. The difference between DHT module sensor and a standalone DHT sensor is that the sensor pins are clearly defined. The module is not much reliable. Most of the time the sensor does not work with the module. Hence, unsold the sensor from the module chip or its better to buy a standalone DHT sensor.    

Requirements

  1. DHT11 or DHT22
  2. Arduino UNO
  3. Jumper wires
  4. Bread board

Schematics

How to Install DHT Sensor Library

Before uploading the code install the library for DHT. Open Arduino IDE, go to tools, click on manage library. The library manager will pop up. Search for DHT sensor library and install it. The figure below may help you. 

Code

				
					#include <dht.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
dht DHT; // Creats a DHT object

void setup() 
{
	Serial.begin(9600);
}
void loop() 
{
	//Uncomment whatever type you're using!
	//int readData = DHT.read22(dataPin); // DHT22/AM2302
	int readData = DHT.read11(dataPin); // DHT11

	float t = DHT.temperature; // Gets the values of the temperature
	float h = DHT.humidity; // Gets the values of the humidity

	// Printing the results on the serial monitor
	Serial.print("Temperature = ");
	Serial.print(t);
	Serial.print(" ");
	Serial.print((char)176);//shows degrees character
	Serial.print("C | ");
	Serial.print((t * 9.0) / 5.0 + 32.0);//print the temperature in Fahrenheit
	Serial.print(" ");
	Serial.print((char)176);
	Serial.println("F ");
	Serial.print("Humidity = ");
	Serial.print(h);
	Serial.println(" % ");
	Serial.println("");

	delay(2000); // Delays 2 secods
}
				
			

Once the code is uploaded, the output will look as below

Leave a Reply

Your email address will not be published.