Menu

all about electronic and microcontrollers

Saturday, November 17, 2018

DHT22 & LCD Shield

In this article I will describe to you, how to develop a home weather station using the DHT22 temperature/humidity sensor.

TECHNICAL DETAILS

Model:
Power supply:
DHT22
3.3-6V DC (2.5mA max current use during conversion (while requesting data))
Output signal:
Digital signal via single-bus
Sensing element:
Polymer capacitor
Operating range:
Humidity: 0-100%RH;
Temperature: -40~80Celsius
Accuracy:
Humidity +-2%RH(Max +-5%RH);
Temperature <+-0.5 Celsius
Resolution or sensitivity:
Humidity 0.1%RH;
Temperature 0.1Celsius
Repeatability:
Humidity +-1%RH;
Temperature+-0.2Celsius
Humidity hysteresis:
+-0.3%RH
Long-term Stability:
+-0.5%RH/year
Sensing period:
Average: 2s
Interchangeability:
fully interchangeable
Dimensions:
Small size 14*18*5.5mm;
Big size 22*28*5mm
Weight (just the DHT22):
2.4g

Hardware setup:
The development board used for this experiment will be the Arduino UNO and the measured values will be displayed on 1602 LCD Keypad Shield board.

DHT22 is a low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and generate out a digital signal on the data pin (which means no analog input pins needed). It's fairly simple to use, but requires careful timing to collect data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using DHT22 library, sensor readings can be up to 2 seconds old.

Simply connect the first pin on the left to 3-5V power, the second pin to your data input pin and the rightmost pin to ground. Although it uses a single-wire to send data it is not Dallas One Wire compatible! If you want multiple sensors, each one must have its own data pin.

In my particular case 1602 LCD Keypad Shield ICSP connector (VCC, D11, GND) was the easiest way to connect my DHT22 sensor. Keypad functionality wouldn’t be used on this article.




Some pictures from the surgery.


On below video we can see the Arduino UNO board in action.


Software:
The program is written in Arduino IDE software (version v1.8.7).

Libraries used:

Below is presented the software approach for this project:

/*
'*******************************************************************************
'  Project name: DHT22 & LCD Shield
'  Description:
'   In this experiment i will describe to you, how to develop a home weather 
'   station using the DHT22 temperature/humidity sensor.       
'   Temperature will be displayed in Celsius Degree and the Umidity in percent
'   The delay between two consecutive reads is set to about 2.1 seconds.
'          Ex. of viewing display: 
'               ________________                         
'              |TEMP.: 24.60 C  |     
'              |Humy.: 54.40 %__|
'
'   Hardware configuration is:
'             DHS22 is connected to 1602 LCD Keypad Shield ICSP connector (vdc, d11,gnd).
'             The 1602 LCD Keypad Shield board is inserted into Arduino UNO standard connectors.
'
'  Written by:
'          Aureliu Raducu Macovei, 2018 (www.electronicexperiments.blogspot.com).
'
'  Test configuration:
'    MCU:                        ATmega328P;
'    Test.Board:                 Arduino UNO;
'    SW:                         Arduino IDE software (version v1.8.7);
'                                DHT Library from Arduino official website:
'                                https://playground.arduino.cc/Main/DHTLib
'*******************************************************************************
 */
 
#include LiquidCrystal.h // includes the LiquidCrystal Library
#include DHT22.h         // includes the DHT22 Library

#define DHT22_PIN 11

// Setup a DHT22 instance
DHT22 myDHT22(DHT22_PIN);

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("    -DHT22 &-   ");
  lcd.setCursor(0,1);
  lcd.print("  --LCD 2x16--  ");
  delay(5000);
  lcd.setCursor(0,0);
  lcd.print("                ");
  delay(100);
  lcd.setCursor(0,1);
  lcd.print("                ");
  delay(500);
}

void loop(void)
{ 
  DHT22_ERROR_t errorCode;
  // The sensor can only be read from every 1-2s, and requires a minimum
  // 2s warm-up after power-on.
  delay(2100);

  errorCode = myDHT22.readData();
  switch(errorCode)
  {
    case DHT_ERROR_NONE:
      lcd.setCursor(0,0);     // Set the first row (location at which subsequent text written to the LCD will be displayed)
      lcd.print("Temp.: ");   // Print "Temp.:" on the LCD
      lcd.print(myDHT22.getTemperatureC());     // Print string temperature
      lcd.print(" C");                          // Prints "C" on the LCD
      lcd.setCursor(0,1);     // Set the second row (location at which subsequent text written to the LCD will be displayed)
      lcd.print("Humi.: ");   // Print "Humi.:" on the LCD
      lcd.print(myDHT22.getHumidity());         // Print string humidity
      lcd.print(" %");        // Prints "%" on the LCD
      break;
    case DHT_ERROR_CHECKSUM:
      lcd.print("check sum error ");
      lcd.print(myDHT22.getTemperatureC());
      lcd.print("C ");
      lcd.print(myDHT22.getHumidity());
       lcd.println("%");
      break;
    case DHT_BUS_HUNG:
      lcd.println("BUS Hung ");
      break;
    case DHT_ERROR_NOT_PRESENT:
      lcd.println("Not Present ");
      break;
    case DHT_ERROR_ACK_TOO_LONG:
      lcd.println("ACK time out ");
      break;
    case DHT_ERROR_SYNC_TIMEOUT:
      lcd.println("Sync Timeout ");
      break;
    case DHT_ERROR_DATA_TIMEOUT:
      lcd.println("Data Timeout ");
      break;
    case DHT_ERROR_TOOQUICK:
      lcd.println("Polled to quick ");
      break;
  }
}

No comments:

Post a Comment

If you do not understand something, or if you make some aplication helped by this blog, let me know.