DHT11 Dew Point and Delay

I've gone down the Arduino rabbit hole, I spend all my time on this thing.
I'm building a box that controls humidity and temperature with a DHT11 sensor.

I have been trying to add dew point to my setup but not getting anywhere, is there a simple way to add it to my code?

I also have been working on how to make the code change after a few days, the same code for 4 days, then change the humidity and temp settings?

#include <SimpleDHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
dht DHT;

int pinDHT11 = 2;   // Declaring digital pin no 2 as the dht11  data pin
int DHTpower = 3;  // Power for DHT11
int intakefan = 4; //  Intake fan for Humid box and dry 
int humidv = 5;     //  Valve for humud intake
int dryv = 6; // dry box valve
int exfan = 7;  // exhaust fan
int exv = 8;  // exhaust valve
int returnfan = 9; // fan to bring air from inside box
int returnv = 10; //  return valve, air from inside box
SimpleDHT11  dht11;  
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16x2 display

void setup() {
  pinMode(intakefan, OUTPUT);
  pinMode(humidv, OUTPUT);
  pinMode(dryv, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(exv, OUTPUT);
  pinMode(returnfan, OUTPUT);
  pinMode(returnv, OUTPUT);
  pinMode(DHTpower, OUTPUT);
  digitalWrite(intakefan, LOW);
  digitalWrite(humidv, LOW);
  digitalWrite(dryv, LOW);
  digitalWrite(exfan, LOW);
  digitalWrite(exv, LOW);
  digitalWrite(returnfan, LOW);
  digitalWrite(returnv, LOW);
  digitalWrite(DHTpower, LOW);
  Serial.begin(9600);   
  lcd.init();      // Initialize the LCD
  lcd.backlight(); // Turn on the backlight
  lcd.clear();     // Clear the LCD screen
  lcd.setCursor(3, 0);
  lcd.print("Welcome");

}


void loop() {
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.print(DHT.temperature);
  Serial.print("*C");
  Serial.println();
  Serial.print("Humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%");
  Serial.println();
  double gamma = log(DHT.humidity / 100) + ((17.62 * DHT.temperature) / (243.5 + DHT.temperature));
  double dp = 243.5 * gamma / (17.62 - gamma);

  Serial.print("Dew point = ");
  Serial.print(dp);
  Serial.print(" *Celcius ");
  Serial.println();
  delay(3000);
}



void  RHcheck() {                    //Check Humidity Level Function
  digitalWrite(DHTpower,  HIGH);     //On Humidity Sensor
  delay(50);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Checking");
  lcd.setCursor(0,1);
  lcd.print("Humidity");


   
  byte temperature = 0;
  byte humidity = 0;
  int  err = SimpleDHTErrSuccess;

  //This bit will tell our Arduino what to do  if there is some sort of an error at getting readings from our sensor
  if ((err  = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("No reading , err="); Serial.println(err);delay(100);
    
  }
 
  if (((int)humidity > 60) && ((int)humidity < 65))  {     // Ok Humidity - Do nothing
    digitalWrite(intakefan, LOW);
    digitalWrite(humidv, LOW);
    digitalWrite(dryv, LOW);
    digitalWrite(exfan, LOW);
    digitalWrite(exv, LOW);
    digitalWrite(DHTpower, LOW);
    digitalWrite(returnfan, LOW);
    digitalWrite(returnv, LOW);
    lcd.clear();
    lcd.print("Fans OFF");
    lcd.setCursor(0,1);
    lcd.print("Valves Closed");
    delay(1500);
    lcd.clear();
    lcd.print((int)humidity); lcd.print(" % Humidity");
    lcd.setCursor(0,1);
    lcd.print((int)temperature); lcd.print(" Celcius");


  }if ((int)humidity < 55 ){

    digitalWrite(humidv, HIGH);
    digitalWrite(dryv, LOW);
    digitalWrite(exv, HIGH);
    digitalWrite(DHTpower, LOW);
    digitalWrite(returnfan, LOW);
    digitalWrite(returnv, LOW);
    delay(3000);
    digitalWrite(intakefan, HIGH);
    digitalWrite(exfan, HIGH);
    lcd.clear();
    lcd.print("Fans On");
    lcd.setCursor(0,1);
    lcd.print("Humid Box");
    delay(1000);
    lcd.clear();
    lcd.print((int)humidity); lcd.print(" % Humidity");
    lcd.setCursor(0,1);
    lcd.print((int)temperature); lcd.print(" Celcius");

  }if((int)humidity > 70 ){
    
    digitalWrite(humidv, LOW);
    digitalWrite(dryv, HIGH);
    digitalWrite(exv, HIGH);
    digitalWrite(DHTpower, LOW);
    digitalWrite(returnv, HIGH);
    digitalWrite(exfan, HIGH);
    delay(3000);
    digitalWrite(intakefan, HIGH);
    digitalWrite(returnfan, HIGH);
    lcd.clear();
    lcd.print("Fans On");
    lcd.setCursor(0,1);
    lcd.print("Dry Box");
    delay(1000);
    lcd.clear();
    lcd.print((int)humidity); lcd.print(" % Humidity");
    lcd.setCursor(0,1);
    lcd.print((int)temperature); lcd.print(" Celcius");
  
  }
}

Well I stuck together some code from other places and im getting there.

How do you use the "dew point" in an IF statement to set pins high?

#include <LiquidCrystal_I2C.h>


//
double dewPoint(double celsius, double humidity) {
  // (1) Saturation Vapor Pressure = ESGG(T)
  double RATIO = 373.15 / (273.15 + celsius);
  double RHS = -7.90298 * (RATIO - 1);
  RHS += 5.02808 * log10(RATIO);
  RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / RATIO))) - 1);
  RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1);
  RHS += log10(1013.246);

  // factor -3 is to adjust units - Vapor Pressure SVP * humidity
  double VP = pow(10, RHS - 3) * humidity;

  // (2) DEWPOINT = F(Vapor Pressure)
  double T = log(VP / 0.61078);  // temp var
  return (241.88 * T) / (17.558 - T);
}

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 7  // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11  // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold. It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value. The default for a 16mhz AVR is a value of 6. For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

int intakefan = 4;  //  Intake fan for Humid box and dry box
int humidv = 5;     //  Valve for humud intake
int dryv = 6;       // dry box valve
int exfan = 7;      // exhaust fan
int exv = 8;        // exhaust valve
int returnfan = 9;  // fan to bring air from inside box
int returnv = 10;   //  return valve, air from inside box

LiquidCrystal_I2C lcd(0x27, 16, 2);  // Set the LCD address to 0x27 for a 16x2 display
void setup() {
  pinMode(intakefan, OUTPUT);
  pinMode(humidv, OUTPUT);
  pinMode(dryv, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(exv, OUTPUT);
  pinMode(returnfan, OUTPUT);
  pinMode(returnv, OUTPUT);

  digitalWrite(intakefan, LOW);
  digitalWrite(humidv, LOW);
  digitalWrite(dryv, LOW);
  digitalWrite(exfan, LOW);
  digitalWrite(exv, LOW);
  digitalWrite(returnfan, LOW);
  digitalWrite(returnv, LOW);

  Serial.begin(9600);
  lcd.init();       // Initialize the LCD
  lcd.backlight();  // Turn on the backlight
  lcd.clear();      // Clear the LCD screen
  lcd.setCursor(3, 0);
  lcd.print("The Green");
  lcd.setCursor(4, 1);
  lcd.print("Ninja");
  delay(2000);  // Display the startup message for 2 seconds
  lcd.clear();  // Clear the LCD screen
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);
  float hiDegC = dht.convertFtoC(hi);


  delay(50);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Checking");
  lcd.setCursor(0, 1);
  lcd.print("Humidity");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hiDegC);
  Serial.print(" *C ");
  Serial.print(hi);
  Serial.print(" *F ");
  Serial.print("Dew Point (*C): ");
  Serial.println(dewPoint(t, h));
}


Start by getting the dewpoint into a variable

float currentDew = dewPoint(t, h);

Then you can test the value of the variable

if (currentDew < 123)
{
  Serial.println("dewpoint is lower than 123");
}
else
{
  Serial.println("dewpoint is 123 or greater");
}

Replace the prints with the actions that you want to take and the value against which the dewpoint is tested to the value that you want

Try this link, it has a lot of information that will help you: Dew Point Formula, Dew Point Temperature Chart (+ Calculator) - LearnMetrics

Thank you sir, I was so close :smiley:

Thats awesome, thank you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.