WEATHER STATION USING DHT 11 WITHOUT LIBRARY

 



In this tutorial, we are going to develop a weather station using DHT 11 without a library using Arduino.

COMPONENTS USED:

·        ARDUINO UNO

·        DHT11

·        LCD 16 X 2

 

DHT11

The DHT 11 sensor is a 1 one wire module which is enabled by triggering the OUTPUT pin and also the data from the sensor is taken from same OUTPUT pin.

The OUTPUT of DHT 11 is in the form of,

  • First 8 bit is Integral part of Relative Humidity (RH)
  • Second 8 bit is Decimal part of Relative Humidity (RH)
  • Third 8 bit is Integral part of Temperature (T)
  • Fourth 8 bit is Decimal part of Temperature (T)
  • Fifth 8 bit is Summation of Integral 8 bit of (RH) and Integral 8 bit of  (T)

Here the total OUTPUT bits are 40.

Decimal part of RH and Temperature are always zero (0).

CODE EXPLANATION:

 HEADER FILE


 

The Code header macro # ifndef and #define  is added for code protection.

Arduino header file is added

In class Public

          void dht_read(int _pin);

    unsigned char temperature, RH ;

    unsigned volatile int dht_pin;

These functions and variables can be accessed outside the class members and accessed publically.

In class private

          char read_dht11();

    void begin();

    void find_response();

   unsigned char Check_bit, Temp_byte_1,Temp_byte_2,RH_byte_1,RH_byte_2,Sumation;

This functions and variables are set as private which means these members are accessed only within the class members, which cannot be accessed globally

 CPP FILE


Function:  dht_read()

  •  In this function first it gets the pin number as argument and it is assigned to dht_pin variable.
  •  It calls two functions 
          begin();
          find_response();
  • Once the functions are called,
  • It checks the Check bit is 1
  • Again it calls read_dht11(); function and stores 8 bit data in each variable.
  • Once it reads all 40 bit of data,the Integral part of RH and Integral part of temperature is stored.
  • Once the data is transmitted completely the DHT11 goes to sleep mode.
  • In case of errors or DHT11 is not connected properly it prints checksum error or No response in serial Monitor.

 

begin()


 

  • In this function, once the pin number is set ,
  • Intially the pin is set as OUTPUT and give a HIGH LOW pulse for 18 milliseconds
  • This is compulsory to trigger the DHT11 from sleep mode to operation mode.
  • Again the pin is set as INPUT for receiving the RH and Temperature data from DHT11. 

find_response() 

  • Once the pin is set as INPUT,It stands IDLE for 40 Microseconds and and checks the DHT pin is goes from LOW to HIGH of duration 80 Microseconds.
  •  The check_bit variable is set as 1.Once the check bit is set as 1, dht_read()  function starts reading the data.
 

MAIN CODE


 

In main code, first “dht11.h” is added

#include"dht11.h"

CLASSNAME OBJECT

DHT dht;

An object (dht )for a class DHT is created.

#include<LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

The LCD 16 x2 is added using LiquidCrystal header file

 void setup ()

Serial communication is enabled with 9600 baud rate

Lcd is assigned for 16 x 2

 void loop()

OBJECTNAME.FUNCTION NAME(ARGUMENT)

 Dht.dht_read(2);

Here dht is Object name.

Dht.read(2) is functuion name and 2 is pin number of ARDUINO  passed as argument.

Once the function is called all the operations are done and the value are stored in RH and temperature variables.

The values are printed in LCD by

lcd.print(dht.temperature);

lcd.print(dht.RH);

DHT11 CODE DOWNLOAD

Comments

Post a Comment