loading

These 7 steps will drive you through the "construction" of a thermo-hygrometer with clock on Arduino UNO.

Data and time, humidity and temperature will be shown on a LCD 16x2 display .If you have purchased a LCD display and want to know how to properly solder a pin header to it, take a look at our tutorial "Yet another tutorial on how to solder".

Each step of this tutorial is independent from the others. So, if you are looking for an easy way to make your DS3231 work (for example) this tutorial is also suitable for you.

What you need to follow all steps of this tutorial is:

    • Arduino UNO
    • A USB cable
    • The Arduino IDE installed on your computer
    • A MB-102 breadboard
    • Set of Dupont cables
    • DHT22(humidity and temperature sensor)
    • DS-3231 (A cheap but accurate real time clock)
    • LCD 16x2 display
    • A 10k Ohm linear potentiometer
    • A 2N3904 transistor (or a 2N2222)
    • Number 3 10k Ohm resistors (1/4 Watt)
    • A pushbutton
    • Preferably, a better text editor than Arduino IDE

    Another very useful thing (but not strictly required) is a small wooden board where fixing Arduinio and breadboard. Get some short self tapping screws if you decide to follow this advice.

    Even if this tutorial seems to be not easy, it can be done by newbies as well if followed step-by-step,

    YOUR COMMENTS AND SUGGESTIONS ARE WELCOME!

    Step 1: Make Your DHT22 Work

    Downloading and installing the DHT22 library

    The first step is downloading and installing the library needed by DHT22 sensors.

    Download the zip file attached in this step. Into this folder there are two files which have to stay into the sub-folder \DHT. If you are on Windows, install the library by putting the \DHT folder into the directory:

    C:\Program Files (x86)\Arduino\libraries

    So, the two files dht.cpp and dht.h have to be contained in a folder named DHT and no other sub-folders have to be made. Click here for more info about adding new libraries.

    DHT22 connections

    Before uploading the code to your Arduino, you need to connect the DHT22 sensor properly.

    Vcc ---> 10k Ohm resistor ---> 5V

    DATA ---> 10k Ohm resistor ---> Pin 9

    NC (not connected)

    GND ---> GND

    Anyway, see the Fritzing scheme attached above for a better understanding.

    ALWAYS CHECK TWICE YOUR CONNECTIONS BEFORE TURNING ON ARDUINO!

    TIP: If you want to recognize quickly the function of a wire, use a standard for colours. Red and black should be respectively associated to Vcc and GND. We use a white Dupont cable for the DATA pin of the DHT22.

    Put the components exactly as we do, later there won't be too much space on your breadboard!

    Uploading the code

    Now, download the file dht22.ino and then double click on it. Arduino IDE will ask you to save the new sketch into a folder whose name will be the same used for the .ino file. Save the file where you prefer.

    Take a look at our code. What's the difference between the code on Arduino's official website (available here) and ours? First of all, we deleted all the lines which are not needed: 15 and 16...

    	#define DHT11_PIN 4
    	#define DHT21_PIN 5
    

    ...and the lines from 55 to 105:

    	// READ DATA
      Serial.print("DHT21, \t");
      chk = DHT.read21(DHT21_PIN);
      switch (chk)
      {
        case DHTLIB_OK:  
    		Serial.print("OK,\t"); 
    		break;
        case DHTLIB_ERROR_CHECKSUM: 
    		Serial.print("Checksum error,\t"); 
    		break;
        case DHTLIB_ERROR_TIMEOUT: 
    		Serial.print("Time out error,\t"); 
    		break;
        default: 
    		Serial.print("Unknown error,\t"); 
    		break;
      }
      // DISPLAY DATA
      Serial.print(DHT.humidity, 1);
      Serial.print(",\t");
      Serial.println(DHT.temperature, 1);
    
      delay(1000);
    
      // READ DATA
      Serial.print("DHT11, \t");
      chk = DHT.read11(DHT11_PIN);
      switch (chk)
      {
        case DHTLIB_OK:  
    		Serial.print("OK,\t"); 
    		break;
        case DHTLIB_ERROR_CHECKSUM: 
    		Serial.print("Checksum error,\t"); 
    		break;
        case DHTLIB_ERROR_TIMEOUT: 
    		Serial.print("Time out error,\t"); 
    		break;
        default: 
    		Serial.print("Unknown error,\t"); 
    		break;
      }
     // DISPLAY DATA
      Serial.print(DHT.humidity,1);
      Serial.print(",\t");
      Serial.println(DHT.temperature,1);
    
      delay(1000)
    

    In fact, they are only needed if you have a different sensor from the DHT22.

    The second difference consists of the changing of the DATA pin used. We set the 9 instead of the 6, chosen by default (because the 6 pin is used by the LCD display).

    Upload the code to your Arduino and then open the system monitor (magnifying glass on the Arduino IDE toolbar). The system monitor should print these lines as an output (see also the screenshot above):

    DHT TEST PROGRAM
    LIBRARY VERSION: 0.1.14
    
    Type, status, Humidity (%), Temperature (C) 
    DHT22, OK, 52.4, 25.9
    

    Congratulations, your DHT22 is working!

    If you don't get this output, check your connections and repeat the whole procedure again.

    <p>Great Explanation, great tutorial.</p><p>Its much easier to use the board <a href="http://www.arduIoT.com/U1." rel="nofollow"> www.arduIoT.com/U1.</a></p><p>you olny have to connect the DHT22 and you are done. </p>
    <p>Great tutorial.</p><p>Thanks.</p><p>Keep up the good work.</p>
    <p>Hi Misticspell, Congratulations for your work.</p><p>Thanks a lot for your comment :)</p>
    <p>Thanks. I didn't made the entire project, just the parts i was interested on.</p><p>Here's a picture of all i made.</p>
    <p>hello, can you send me this your project code?</p>
    <p>Hi, here is the code I used.</p><p>Hope it helps you.</p><p>//Carrega librarias<br>#include &lt;dht.h&gt;<br>dht DHT;<br>#include &lt;Wire.h&gt;<br>#include &lt;LCD.h&gt;<br>#include &lt;LiquidCrystal_I2C.h&gt;</p><p>//Define variaveis </p><p>#define I2C_ADDR 0x27 //Define endere&ccedil;o I2C onde o PCF8574A est&aacute;<br>#define BACKLIGHT_PIN 3<br>#define En_pin 2<br>#define Rw_pin 1<br>#define Rs_pin 0<br>#define D4_pin 4<br>#define D5_pin 5<br>#define D6_pin 6<br>#define D7_pin 7<br>#define DHT22_PIN 9</p><p>//Inicializa o LCD<br>LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);</p><p>void setup()<br> {<br> //Define o LCD como 20 colunas por 4 linhas<br> lcd.begin (20,4);<br> <br> //Liga ilumina&ccedil;&atilde;o do LCD<br> lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);<br> lcd.setBacklight(HIGH);<br> <br> <br> <br> }<br> <br> <br>void loop(){<br> <br> <br> // READ DATA<br> Serial.print(&quot;DHT22, \t&quot;);<br> int chk = DHT.read22(DHT22_PIN);<br> switch (chk)<br> {<br> case DHTLIB_OK: <br> //Serial.print(&quot;OK,\t&quot;); <br> break;<br> case DHTLIB_ERROR_CHECKSUM: <br> //Serial.print(&quot;Checksum error,\t&quot;); <br> break;<br> case DHTLIB_ERROR_TIMEOUT: <br> //Serial.print(&quot;Time out error,\t&quot;); <br> break;<br> default: <br> //Serial.print(&quot;Unknown error,\t&quot;); <br> break;<br> }<br> //ir para primeira coluna (coluna 0) e primeira linha (Linha 0)<br> lcd.setCursor(0,0);<br> lcd.print(&quot;Humidade (%)&quot;);<br> <br> lcd.setCursor(0,1);<br> lcd.print(DHT.humidity, 1);</p><div> lcd.setCursor(0,2);<br> lcd.print(&quot;Temperatura (C)&quot;);<br> <br> lcd.setCursor(0,3);<br> lcd.print(DHT.temperature, 1);<br> <br> delay(1000);<br> }</div>
    <p>Great job!</p>
    <p>Hi, great Tutorial, been looking for something just like this.</p><p>ive made it all up but have some problems, with the code, i used yours, i have an error compiling with the line </p><p>dht DHT;</p><p>and further down in the void dht22() its not compiling</p><p>lcd.print(DHT.temperature, 1);</p><p>and</p><p>lcd.print(DHT.humidity, 1);</p><p>any help here would be greatly appriciated</p>
    <p>Hi TaylorL27, seems the compiler does not see the DHT library.</p><p>Did you installed it?</p>
    <p>i hav installed a DHT library yes. i am using the DHT 11 but i think i have made all the riht chnges, i dont know if ive missed a line of code or something.</p>
    <p>can you attach the error log here?</p>
    <p>Arduino: 1.6.5 (Windows 8.1), Board: &quot;Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)&quot;</p><p>thermohygrometer:18: error: 'dht' does not name a type</p><p>thermohygrometer.ino: In function 'void dht11()':</p><p>thermohygrometer:177: error: request for member 'temperature' in '11', which is of non-class type 'int'</p><p>thermohygrometer.ino: In function 'void loop()':</p><p>thermohygrometer:218: error: 'dht22' was not declared in this scope</p><p>'dht' does not name a type</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p>
    <p>thermohygrometer:18: error: 'dht' does not name a type says that the compiler can not see the library</p><p>there is anothe error: thermohygrometer:218: error: 'dht22' was not declared in this scope . If you are using a DHT11 you must put dht11, not dht22</p>
    <p>ok, the compiler has moved on to he problems in the void dht()</p><p>Arduino: 1.6.5 (Windows 8.1), Board: &quot;Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)&quot;</p><p>In file included from thermohygrometer.ino:1:0:</p><p>C:\Users\System-1\Documents\Arduino\libraries\DHT-sensor-library-master/DHT.h:32:15: error: expected unqualified-id before numeric constant</p><p> #define DHT11 11</p><p> ^</p><p>thermohygrometer.ino:20:5: note: in expansion of macro 'DHT11'</p><p>thermohygrometer.ino: In function 'void dht11()':</p><p>thermohygrometer:179: error: request for member 'temperature' in '11', which is of non-class type 'int'</p><p>thermohygrometer:184: error: request for member 'humidity' in '11', which is of non-class type 'int'</p><p>thermohygrometer.ino: In function 'void loop()':</p><p>thermohygrometer:220: error: 'dht22' was not declared in this scope</p><p>request for member 'temperature' in '11', which is of non-class type 'int'</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p>
    <p>Maybe there is some syntax error in your code</p>
    <p>Great tutorial! I managed to fit it all on the breadboard I got with the Arduino starter kit (sorry for the grainy picture, it's pretty late). Only I don't think the part where you explain how to connect the DHT22 is correct:</p><p>&quot;Vcc ---&gt; 10k Ohm resistor ---&gt; 5V</p><p>DATA ---&gt; 10k Ohm resistor ---&gt; Pin 9</p><p>NC (not connected)</p><p>GND ---&gt; GND&quot;</p><p>This didn't work for me. The Fritzing picture did though, just thought I'd let you know!</p>
    <p>Hi MrDam404, thanks a lot for your comment. We connected the pin1 of the DHT22 to Vcc, the pin2 to the Arduino DATA input and the pin4 to GND. Between pin1 and pin2 we put a 10KOhm resistor. </p><p>Congratulations for your work.</p>
    <p>Awesome instructable,by installing a battery,you can actually take it along and go out^_^</p>
    <p>The DS3231 runs fine on 3.3 Volt from the Arduino. It is 4am in the morning and I have finally found this Instructable. Just what I was looking for. Good work.</p>
    <p>Hi arduinomaster, thanks a lot for your comment. We have always supplied 5V to the ds3231 without any problem. Actually, as we read in its datasheet it can work within a range of 2.3 to 5.5V and 3.3V is the voltage suggested. We are going to write an annotation about.</p>
    <p>Nice job, thanks for sharing! </p>
    <p>thank you! ;)</p>
    <p>Excellent tutorial, thank you!</p>
    <p>thank you! ;)</p>

    About This Instructable

    18,020views

    163favorites

    License:

    More by techrm:A Simple Hydroponic System With MediaTek LinkIt™ ONE Getting started with BTE13-010 - Arduino Mini clone Simple calculator based on Arduino MEGA 
    Add instructable to: