How to remove damp from your home or premises: Part 1 of 2 - Arduino

Moisture extraction tube and external sensor

In this tutorial we will explain how to dehumidify a room in two steps; first we will detail the preparation and programming of the Arduino board. with which, by means of a relay and two inexpensive DHT11 sensors, we will control a small fan that will do all the work, checking temperatures and humidity. Then, in a second entry, we'll get our hands dirty by drilling holes in the wall and placing a PVC pipe with the fan connected to the Arduino. to extract the colder and more humid air from the lower part of the room, as well as placing the humidity sensors and the box with the Arduino, power supply, etc. I hope you enjoy reading it as much as I have enjoyed installing it; it has been a success; the humidity in a storage room that is in contact with the ground has dropped in one day from 90% to 70% saturation (while in the street there was a 65%).

Introduction and preparations

This forced ventilation system is commonly used when natural ventilation is not sufficient, such as in underground premises, with a fan that is permanently activated.

However, opening ventilation holes covered with louvres can usually be sufficient to ventilate a room, by installing a programmed ventilation system we will have several advantages over this systemWe can control the hours when it starts up, the operating time, we can prevent the premises or garage from getting too cold (normally it is during the day when the humidity drops more in the street), we can also place mobile grilles that open only when we activate the fan and prevent cold or heat from entering the premises, apart from the fact that as it is forced ventilation it is enough to open just one ventilation hole (the air will enter wherever it can, it is rare that the premises are completely airtight), etc...

And if we were using an electric dehumidifier before, the savings on our monthly energy bill will be significant; from €10 (for a 200W dehumidifier running 12 hours a day) upwards, and the cost will continue to rise year on year. As I always say, before getting the necessary material it is important to plan well what we are going to do; This is an example that can be taken to other cases with some modification, cases that I will discuss at the end of the entries. We need to know if we will use two sensors or just one inside, if we will use an Arduino UNO or a Nano (smaller and recommended once we have tested the program), etc.

Materials for the control part with Arduino

  • Arduino UNO Rev. 3You can use the Arduino you prefer; depending on the size you want to leave the box, you can use an Arduino Nano, same functionality but more compact; I have used a Leonardo, but the connections and operation are the same. If you are not familiar with this platform, it's about time you take the fear out of it, read for example this post by our Arduino expert, Isaac.
  • DHT11 Humidity SensorsIt is a very cheap and reliable sensor that measures both humidity and temperature. These that I have acquired already have their circuit with the necessary resistance, so they are for direct connection. Depending on the manufacturer, they may have the data pin in one position or another; these in particular have an S on the left (Output); +5V and ground. You will also need a pair of 3-pin female connectors to house the sensors, of the type used in 3-wire computer fans. Before using them, it is advisable to compare them with another sensor as they are not calibrated (we can adjust their reading using the Delta values in the program).

  • Relay with control board: Ideally, like the sensors, the relay already has the control circuit (with indicator LEDs, protection diode, etc.), so we only need to supply it with the voltage it needs and connect it to the Arduino pin with which we will activate it, and we will have it running. The one I have used has two relays (I only need one), and it works with 12V, but we only need to supply it with between 6 and 12V to activate it. The fan is low consumption (about 10W maximum), so the relay contacts will last for many years. You can use the same transformer that I will use to power the Arduino to power the relay.

  • 2 green LEDs and 1 red LED: At first I was going to put a display indicating the indoor and outdoor humidity, but in the end I have only used it to debug the program, for economy and simplicity, so in the final box there are only three LED indicators that will give us the information we need; a red one that will be activated in case of error in any of the sensors, another green one that flashes 2 times per second to indicate that the program is working correctly, and another LED that will be activated when the relay is activated (to check that the fan and relay are working correctly). To connect them we will also need at least a resistor of between 500 ohm and 1 Kohm, so that they are not damaged by the 5V of the Arduino's digital signal.
  • Transformer to power the Arduino and the relay: The Arduino UNO needs between 6 and 12V and so does the relay, so ideally you should use a 7.5V DC power supply, enough to power both with the same relay. Any power supply with at least 500mA that you have at home from an electronic device will do. It works fine for me with a 6V DC one (make sure it delivers DC and not AC).

Transformer 6V DC 2,1A

  • Watertight enclosure for electrical circuitsAvailable in electrical shops; it is not essential that it is watertight, but as I am going to place it in a place with a lot of humidity and the electronic circuits do not get on well with it, the least I want is that the Arduino gets damaged as soon as there is any problem and the fan stops doing its function. The cover has a rubber that makes it difficult for the humidity to pass through, and where the cables pass through, some cable glands are in charge of squeezing them, preventing water and humidity from getting inside.

Box for the elements

  • Thermo-gluing machine and glue sticksWhat would we handymen do without this invention, which allows us to semi-permanently join our pieces in a matter of seconds, insulate cables, etc. Not recommended for use in places where the temperature can rise above 60°C, as it could melt and become unusable.

Hotmelt gluing machine

Connection and programming of the board

Let's take a look at the programme. I have tried to make it parametric, that is to say, there are several variables that we can modify to our liking so that it adapts to our needs.

I have used two humidity sensors, one outside and one inside, which I will compare.. If you cannot place one outside, you can modify the programme so that, knowing the maximum humidity in the street according to the area (we can look for this information on the Internet), activating the fan every time this value is exceeded by 5 or 10%, would be enough to keep the humidity in the room under control.

The first thing to do is to prepare all the necessary elements on the breadboard and write the program. and with the help of a screen or the serial connection (I have used the cheap and versatile Nokia 5110 LCD screen with 84×48 pixels; you have on the internet tutorials on how to use it) we are debugging its operation; I am not going to explain how to program it because it goes beyond the objective of this entry, you have excellent tutorials on the internet. Anyway, in this tutorial I leave you the complete program, so you can set up a similar system:

Programme testing
Don't be scared off by the number of cables; without the screen, everything is much simpler.

I didn't use it in my final project, but if you prefer to use a screen of this type and avoid the work of the LEDs, we only need 5 resistors of 2K2 ohms to connect it to our board, and add a few lines to the programme (click on this link DHT11 with Nokia display you can download the version with the LCD screen libraries that I used to debug it). In it, apart from indicating the temperature and humidity values, there is room to indicate if the relay is activated, and other data; for me it is more versatile than the two-line screens that are usually used.

Detail of connections to test screen
This screen is excellent for displaying a large amount of information.
Detail of cable connections
Here testing a recycled red LED

After several tests, the final scheme has remained as follows:

Wiring of Arduino, sensors and LEDs
I use a single resistor on the negative side to simplify the LED circuit.

I have reduced the voltage to the diodes by placing a single resistor. on the negative common; it should be between 500 and 800 ohms to extend the life of the LEDs. On the other hand, DHT11 sensors usually need a resistor if they are not soldered to a circuit (they are a bit cheaper) but I prefer ready-made sensor boards.

For easy control of one or more DHT11 sensors we need a library that we will have to unzip in our Arduino-libraries folder (the one created by the IDE in "my documents"; you can download it from the following link: DHT11 together with the program used (in the "DHT11 Comparator" folder). It is the most compact and simple library I have found for reading sensors of this type.

The programme looks as follows; those variables that we can adjust to our needs are indicated with the text "Customisable"; you can copy the text into the Arduino IDE where it will be easier to read and understand it. (for any questions or suggestions please leave a comment):

//Program to compare 2 DHT11 humidity and temperature sensors and activate a relay VERSION 1.0
//Based on work by sucotronic and Regata
//Customised by Ringmaster for
// This program is set to activate the relay only if it is worthwhile, avoiding unnecessary power consumption and extending the life of the fan;
// in this case in the hottest hours of the day (it is assumed that there is also less humidity in the street), but less than XºC,
// the most reasonable values for delta_temp and delta_hum is to activate it when we have between 5 and 10% more humidity indoors (adjust the customisable values
// a little bit depending on the situation), and whenever the outside temperature is higher (but lower than XºC) I turn the fan on for at least half an hour.
dht11 DHT11;
#define DHT11PIN 2 //Inner sensor goes to DIGITAL pin 2; indicate here which one you use
#define DHT11DOS 8 //Outside sensor goes to DIGITAL pin 8; indicate here which one you use
int relePin=10; //Customisable; Digital output for relay , I use 10
int errorPin=11; //Customisable; To activate the error LED, I use digital 11.
int onPin=12; //Customisable; To indicate "on"; pin 12 digital
int onRele=9; //Customisable; To indicate that the relay is activated.
int tempint; //Variables for storing values for comparison
int tempext;
int humint;
int humext;
int delta_temp=5; //Customisable; Will be activated when the outdoor temperature is at least this much higher (and will stop when there is no longer this difference).
int delta_hum=10; //Customisable; The relay will be activated when the outside temperature is at least this high (and will stop when there is no longer this difference). I indicate 9 because the sensor
//Outdoor has an error of 4% less than indoor with the same humidity; we can use these values also to "calibrate" the sensors.
boolean data_error; //Store the error in this variable
boolean rele_act=false; //Save here if the relay was activated in the previous loop.
long counter;
long time=30; //Customisable; minimum time in minutes that the relay must be activated, regardless of whether the humidity drops or not; we prevent it from starting and stopping continuously.
int tempmax=25; //Customisable; maximum outside temperature at which I activate the relay, in case we do not want to heat up the room too much. Enter 99 to deactivate it
int temp;
void setup() {
pinMode(relePin, OUTPUT); // sets the digital pin as output
pinMode(errorPin, OUTPUT);
pinMode(onPin, OUTPUT);
pinMode(onRele, OUTPUT);
delay(2000); //We wait 2 sec before reading the sensors.
void loop() {
data_error=false; //reset check byte
int chk =;
switch (chk){
//If OK, we take data
//case DHTLIB_ERROR_CHECKSUM: //Disable these options, they are not of practical interest in this case.
// display.println("Checksum error");
//display.println("Time out error");
default: //in case of any other result (default); unknown error
data_error=true; //activate error LED
chk =; //check external sensor
switch (chk){ //Check that the data is valid
//If it is OK we take the data from external
//If not OK, we activate the error LED.
if (data_error==true) //at least one of the sensors does not work; error message and fan off and counters reset (as if resetting the program)
digitalWrite(relePin, LOW);
digitalWrite(errorPin, HIGH);
digitalWrite(onRele, LOW);
digitalWrite(errorPin, LOW);
//Compare values to activate or deactivate the relay
{ if (relay_act) //if the relay is activated, we check every hour whether it is worthwhile to keep it running.
{ if (counter>0) {-counter;} //we remove 1 from the counter only in case it is >0
tempint=tempint+2; //Then we add a margin of error value (depending on the accuracy of the sensors); I put 2ºC.
humext=humext+5; //Error margin for humidity
if ((((tempext tempmax) && humext>=humint) || humext>=humint) //Deactivate when we are not interested in the outdoor temperature or the outdoor humidity.
digitalWrite(relePin, LOW); //we turn off the fan and the indicators.
digitalWrite(onRele, LOW);
{tempint=tempint+delta_temp; //add the switch-off temperature delta; the relay will only be activated if the ext. temp. is higher than this Delta value
humext=humext+delta_hum; //Activate only when outside there is at least one {value of Delta_hum} less humidity.
if ((tempext >= tempint && tempext<tempmax) || humext<=humint) //starts running when the humidity or temperature difference has reached the Delta value.
digitalWrite(relePin, HIGH);
digitalWrite(onRele, HIGH);
counter=time; //we reset minimum time
for (int i=0; i <= 61; i++){//Flash the on led for 60 seconds (run the loop once every 60 seconds)
digitalWrite(onPin, HIGH); //active ON led
delay(500); //Stop for half a second
digitalWrite(onPin, LOW); //disable led from on

As I indicated in the programme's comments, as it was a local that dealt with the house, I I was interested in activating the fan under the following conditions: When the humidity exceeds an indicated Delta percentage, or when the outside temperature exceeds the inside temperature (but is below 25ºC). to keep the room cool and dry, so you will probably have to adapt it a bit.

Summarising how the programme worksEvery 60 seconds the value of the sensors is obtained; if the activation conditions are met, we activate the fan for a minimum time; when this minimum time is over, we check if the conditions are still met, but if not, we switch off the relay, and we start again, making the ON LED blink to indicate that everything is going well and the programme has not been blocked.

The programme is ready, it's time to start assembling the box with the diodes, Arduino and relay.. In the lid I drilled 3 small holes just for the status diodes and once soldered to the resistor(s) I fixed and insulated them with the hot-melt glue gun:

Placing leds on the lid
View of the cover where I have placed the three LEDs.
Cover with the two LEDs
With an indelible marker pen I have marked the meaning of each LED; in this picture the "relay on" LED is missing.

To put both the Arduino (Leonardo in my case) in the box together with the relay board, it was necessary to isolate the relay circuit baseThe best way to do this is to apply a layer of glue with the hot-melt glue gun (which can be removed later if necessary):

The circuit wouldn't fit in the box connected to the transformer, so I had to unplug the power jack from the Arduino board (invalidating the warranty). There is always one of these unforeseen events... but there is always a solution.

In the following image you can see how both the relay and the board are connected to the same power cable.

The finished box
Programming the Arduino for the last time before putting it in place.

As the case will be close to the fan (but far enough away not to be disturbed by the airflow), I have placed the internal temperature sensor by gluing its base with hot-melt glue to the side of the case:

We connect all the cables; I have taken out the connection to the relay with the gold coloured cable that can be seen in the following image, once the box is screwed to the wall this cable will activate the fan.

The sensor that will go outside taking the humidity and temperature values from the street can be seen on the right, you have to extend those three cables to the place where we will place it definitively:

Detail of the box with ON and Error LEDs
Final appearance of the box with all the elements connected (note the external sensor on the right).

Finally, I test everything before putting it in place.I release one of the sensors and wait a minute; the error light comes on so everything seems to be fine!

If you have noticed, the third LED for the activated relay status, which I placed later, is still to be fitted. to know if the fan and relay assembly work correctly, and that in later photos it does appear. All we have left is the acid test: Connect it to the fan in its place and see if everything goes according to plan... but that will be in the next entry gentlemen...

Red error led test
Houston testing testing testing... Eureka!

10 thoughts on “Cómo eliminar la humedad de tu casa o local: Parte 1 de 2 – Arduino”

  1. very good brico! i love arduino and its possibilities.... you have done very well
    I'm in the same situation...I have a basement that is very humid in summer...95%.... and I'm trying to build a fan system....

  2. Ing. Ramón Anguera Galindo

    Good morning, I think it is wonderful that there are people who make technology available to everyone, congratulations.

  3. Carlos Guzman

    Really congratulations for the post, very good and very well explained. Greetings and thanks

Leave a Comment

Your email address will not be published.

Scroll to Top