tomwyonkman
Published © GPL3+

DHT11 Dew-Point Calculator

After talking to a friend about his electric tricycle and how the window fogs up when it's cool out I thought it would be fun to monitor it.

BeginnerShowcase (no instructions)10,217
DHT11 Dew-Point Calculator

Things used in this project

Story

Read more

Code

Bob's Dew-point Temp display

Arduino
/*     
 RedTar4
 Bobs_DewPoint_LCD_meter_DHT22_rev7
 10/18/18 - 3/10/19
 */  

     //  Library section
#include <LiquidCrystal.h>                // LCD library
  LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // (rs,e,d4,d5,d6,d7),initialize the LCD with the numbers of the interface pins
#include <DHT.h>                          // DHT22 library, delete any "DHT.U" files from library,or it wont run
 
     //  Definition section
#define DHTPIN 2            // what arduino pin we're connected to, arduino pin D2
  DHT dht(DHTPIN, DHT22);   // initialize DHT sensor and create sensor objects
#define DHTTYPE DHT22       // create DHT 22  (AM2302), AM2321 object
   
     //  pin assignment section
int alarmLed = 3; //  assigns alarmLed int to arduino pin D3
 
void setup()
  {
     //  initilize and start systems
  Serial.begin(9600); //  sets up serial comm's to 9600 baud
  dht.begin();        //  initialize the DHT22
  lcd.begin(16, 2);   //  initialize the LCD's number of columns and rows
 
     //  display and serial print initilization
  Serial.println("DHTxx test!");
  lcd.setCursor(0, 1); lcd.print("DHTxx test!");
  delay(1500);
  
     //  output pin setup section
  pinMode(alarmLed, OUTPUT);   //  assigns alarmLed (arduino pin 3) as an output
  digitalWrite(alarmLed, LOW); //  sets output alarmLed (arduino pin 3) low

  }
 
void loop()
  {
     // Reading temperature and humidity takes about 250 milliseconds
  float H = dht.readHumidity();        //  read humitity as %f
  float C = dht.readTemperature();     //  read temperature as Celsius (default)
  float F = dht.readTemperature(true); //  read temperature as Fahrenheit (if true)
 
     // DHT22 data error check section
  if (isnan(H) || isnan(C) || isnan(F))
     {
    Serial.println("Failed to read from DHT sensor!");
    lcd.setCursor(0, 0); lcd.print("                ");
    lcd.setCursor(0, 0); lcd.print(" Failed to read ");
    lcd.setCursor(0, 1); lcd.print("                ");
    lcd.setCursor(0, 1); lcd.print("DHT sensor Fail!");
    return;   //  returns to start of loop
     }

    //  calculations and conversions section
  float HiF = dht.computeHeatIndex(F, H); //  read and compute heat index in Fahrenheit (the default)
  float DewPoint = (C - (100 - H) / 5);   //  dewpoint calculation using Celsius value
  float DP = (DewPoint * 9 / 5) + 32;     //  converts dewPoint calculation to fahrenheit

     //  alarm output section
  if ((F - 2) <= DP)                 //  if the F value - 2 is <= to the DP value then this statement is true
     {digitalWrite(alarmLed, HIGH);} //  since statement is true set alarmLed (arduino pin D3) high
   else                              //  if statement is not true then
     {digitalWrite(alarmLed, LOW);}  //  set alarmLed (arduino pin D3) low

     //  serial monitor and debug section
  Serial.print("Sample OK: ");                                //  prints sample ok to serial monitor
  Serial.print((int)C);        Serial.print(" *C, ");         //  prints celsius value to serial monitor and returns cursor
  Serial.print((int)F);        Serial.print(" *F, ");         //  prints fahrenheit value to serial monitor and returns cursor
  Serial.print((int)H);        Serial.print(" %, ");          //  prints humidity value to serial monitor and returns cursor
  Serial.print((int)DP);       Serial.print(" DP, ");         //  prints dewpoint value to serial monitor and returns cursor to next line
  Serial.print((int)HiF);      Serial.print(" Heat index, "); //  prints humidity value to serial monitor and returns cursor
  Serial.print((int)DewPoint); Serial.println(" DewP, ");     //  prints dewpoint value to serial monitor and returns cursor to next line

     //  LCD print section
  lcd.setCursor(0,  0); lcd.print("Tmp");
  lcd.setCursor(4,  0); lcd.print(F);
  lcd.setCursor(6,  0); lcd.print((char)223); lcd.print("F"); //  prints the degree's symbol
  lcd.setCursor(8,  0); lcd.print("Dew");
  lcd.setCursor(12, 0); lcd.print(DP);
  lcd.setCursor(14, 0); lcd.print((char)223); lcd.print("F"); //  prints the degree's symbol
  lcd.setCursor(0,  1); lcd.print("Hum ");
  lcd.setCursor(4,  1); lcd.print(H);
  lcd.setCursor(6,  1); lcd.print(" % ");
  lcd.setCursor(8,  1); lcd.print("HId");
  lcd.setCursor(12, 1); lcd.print(HiF);
  lcd.setCursor(14, 1); lcd.print((char)223); lcd.print("F"); //  prints the degree's symbol
 
     // The DHT22 sampling rate is .5HZ (.5 Sec), this delay sets program sample rate to match so no errors happen
  delay(2000);

  }

The Circuit

Arduino
/*

  The circuit:

 Select - Arduino nano, board: select - ATmega328P (old Bootloader), processor
   5v to VCC
   gnd to GND

 LCD 16X2:
   LCD 1(VSS) pin to ground
   LCD 2(VDD) pin to vcc
 10K potentiometer:
   ends to +5V and ground
   LCD 3(VO)  pin to pot wiper
   LCD 4(RS)  pin to digital pin D7
   LCD 5(RW)  pin to ground
   LCD 6(E)   pin to digital pin D8
   LCD 11(D4) pin to digital pin D9
   LCD 12(D5) pin to digital pin D10
   LCD 13(D6) pin to digital pin D11
   LCD 14(D7) pin to digital pin D12
   LCD 15(A)  pin to vcc
   LCD 16(K)  pin to gnd
 
 DHT22:
   VCC:  pin 1 to +5v
   DATA: pin 2 to pin D2 nano
   GND:  pin 3 to ground

 LED:
   Nano pin D3 to led +
   led - to 2000 ohm res
   2000 res to ground

  after download start the serial monitor
  */

Credits

tomwyonkman

tomwyonkman

0 projects • 18 followers

Comments