Home Uncategorized How to control Temperature & humidity levels with a DHT11/DHT22 relays and a FAN & Heater
How to control Temperature & humidity levels with a DHT11/DHT22 relays and a FAN & Heater

How to control Temperature & humidity levels with a DHT11/DHT22 relays and a FAN & Heater

2

So I have done a lot of projects that were meant to control and monitor temperature and humidity levels since writing the Virtuabotix DHT11 library and developing a lot of other sensor resources. Still the question often comes up how you would control humidity/temperature levels using this sensor with heaters and fans, and I wanted to share a simple solution with everyone so they can make better use of their sensors.

This project was specifically put together to answer a question by Matt on the Arduinoeverything.com blog about how to control humidity with a 4.5 volt fan and the DHT11.

This code was used with the following hardware:

The Versalino Uno (code compatible with the Arduino Uno)
The Versalino 6PIN Relay Board (you can make your own relay circuit too, or use just about any relay circuit out there)
The Virtuabotix DHT11/or easily adapted to the Virtuabotix DHT22
And a low power DC fan like this one: https://www.virtuabotix.com/product/40mm-5-volt-dc-ventilation-fan-electronics/ (The Versalino 6PIN Relay Board can run up to 5 amp fans though so don’t be shy about size :D)

Basically all you need to do is connect a relay for the fan and heater, and then to connect the 6PIN Relay Board to the Versalino/Arduino Uno on pin BUSA.D1, and BUSA.P1 or 2 and 3 respectively (same pin just in a slightly different place). You will also want to connect the Virtuabotix DHT11/DHT22 to pin  BUSA.D2 (on the Versalino) or pin 4 on the Arduino.

Now basically all you have to do is bring in a voltage that can control both (you may want to switch to ac fans and just use an AC heater in this case, but if you just want low power stuff you should be able to find a small DC heater).

/*####################################################
Temperature and Humidity control unit by Joseph Dattilo
LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
GET UPDATES: https://www.virtuabotix.com
####################################################*/
#include

dht11 DHT11;//change to dht22 DHT22; if using the dht22
//you will also need to change all instances of DHT11 to DHT22

byte fanrelaypin = 2;
byte heatrelaypin = 3;

void setup()
{
DHT11.attach(4);//Change
Serial.begin(9600);
Serial.println("Virtuabotix DHT11 FAN & Heater CONTROL");
pinMode(fanrelaypin, OUTPUT);
digitalWrite(fanrelaypin, LOW);//turn off the relay
pinMode(heatrelaypin, OUTPUT);
digitalWrite(heatrelaypin, LOW);//turn off the relay
}

void loop()
{
Serial.println("\n");

int chk = DHT11.read();

Serial.print("Read sensor: ");
switch (chk)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}

Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, DEC);

if(DHT11.humidity > 75)//change % to match your threshold.
{
digitalWrite(fanrelaypin, HIGH);//turn on the fan
}
else
{
digitalWrite(fanrelaypin, LOW);
}

Serial.print("Temperature (C): ");
Serial.println(DHT11.temperature, DEC);

if(DHT11.temperature < 30)//change to match your threshold in C. { digitalWrite(heatrelaypin, HIGH);//turn on the heater } else { digitalWrite(heatrelaypin, LOW); }delay(2000);}

 

The code above basically turns on the fans if the humidity goes over 75% and turns on the heater if it is less than 30 degrees Celcius. I hope the Arduino sketch above helps you solve some problems, and look forward to hearing back from you all with suggestions on the next project.

Joseph Dattilo Writer, Electrical Engineer, CEO and founder of Virtuabotix LLC, and completely crazy in every way.

Comment(2)

  1. Yes, the library was originally written for the Arduino Uno and Mega, and was adapted to be easy to use on the Versalino pinout as well. You can assign the data pin to any Arduino pin quite easily.

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *