Trouble with humidity controller.

So I have a DFRobot LCD keypad shield, and an Arduino UNO.
I want to make an outlet that's humidity controlled like the InkBird controllers.

I was trying to use this code https://create.arduino.cc/projecthub/Shaeroden/humidity-controller-c13dad but when trying to verify the sketch it just says dht.h no such file or directory.

I have installed the DHT library from the library manager within the IDE so I'm not sure what to do at this point to make it work.

the dht.h file is actually caps like DHT.h, and if I rename it to lower case then I get the error Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"

Shaeroden_Humidity_Controller:23:1: error: 'dht' does not name a type

dht DHT;

^~~

C:\Users\Verti\Documents\Arduino\Shaeroden_Humidity_Controller\Shaeroden_Humidity_Controller.ino: In function 'void setup()':

Shaeroden_Humidity_Controller:101:16: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11_PIN);

^

Shaeroden_Humidity_Controller:107:16: error: expected primary-expression before '.' token

lcd.print(DHT.humidity);

^

C:\Users\Verti\Documents\Arduino\Shaeroden_Humidity_Controller\Shaeroden_Humidity_Controller.ino: In function 'void loop()':

Shaeroden_Humidity_Controller:163:18: error: expected primary-expression before '.' token

int chk = DHT.read11(DHT11_PIN);

^

Shaeroden_Humidity_Controller:166:21: error: expected primary-expression before '.' token

Serial.print(DHT.humidity);

^

Shaeroden_Humidity_Controller:196:18: error: expected primary-expression before '.' token

lcd.print(DHT.humidity);

^

Shaeroden_Humidity_Controller:265:9: error: expected primary-expression before '.' token

if(DHT.humidity <= setpoint - 3 and syson == true){ //if humidity is 3% lower than setpoint

^

Shaeroden_Humidity_Controller:270:14: error: expected primary-expression before '.' token

else if(DHT.humidity >= setpoint + 3 and syson == true){ //if humidity is 3% above setpoint

^

exit status 1
'dht' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The are any number of libraries for the DHT11 and DHT22 sensors. Unfortunately, they are all named dht or DHT and code from one may not run using a different library. The one that you want may be this dht.h library.

That might have worked thanks. It seems to verify.

Well it uploads, but nothing happens on the screen on the arduino. I think it was written for a Nano not an UNO, would that make a difference?

Post the code in code tags?

I recommend that you use example code that comes with the library. That way it is known to work.

I found code that works, but still has a small issue, perhaps you could help with this instead.
This was originally for DHT22, but I changed it to DHT11 and it displays temp and humidity (maybe correctly) but when I press buttons they do the wrong thing.

Pressing select will adjust the temp up, pressing left adj. humidity down, pressing up adj. humidity up, pressing down adj. humidity down, pressing right adj. temp down.
But there's supposed to be "instr. on select"

/*Sky Control - Temperature and humidity sensor with relays made by ArkadiuszO2 v1
 * Please read comments 
 * Shopping list includes:
 * 1. Arduino Uno
 * 2. DHT22 sensor
 * 3. 2 channel relay - 5V
 * 4. DFRobot LCD Keypad Shield
 * 
 * In V2 i will add Air quality sensor based on Sharp's GP2Y1010AU0F 
 */

#include <LiquidCrystal.h>
#include <DFR_Key.h>
#include <DHT.h>

//Starting values after boot up, you can change them
int temp = 25;
int hum = 50;


//For DHT22 (AM2023)
#define DHTPIN 15
#define DHTTYPE DHT11
const int relay1 =  18;
const int relay2 =  19;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 
DFR_Key keypad;
int localKey = 0;
String keyString = "";
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){               
    adc_key_in = analogRead(0);
    if (adc_key_in > 1000) return btnNONE; 
    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 250)  return btnUP; 
    if (adc_key_in < 450)  return btnDOWN; 
    if (adc_key_in < 650)  return btnLEFT; 
    if (adc_key_in < 850)  return btnSELECT;  
    
}
              
void setup() 
{ 
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  //lcd.print("Sky control v1");
  lcd.setCursor(0, 1);
  lcd.print("Instr on Select");
  delay(250);
  Serial.begin(9600);
  dht.begin();
  delay(1000);
  lcd.clear();
    
  //Sample rate (default 10 ms)
  keypad.setRate(10);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);

}

void loop() 
{ 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(t) || isnan(h)) { //checking sensor operation
    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Sensor broken!!");
    delay(10000);
  } else {
    
    //You can change values (step) after each button press, default is 1'C for step and 5% humidity
    
    lcd_key = read_LCD_buttons();
    switch (lcd_key){
        
       case btnLEFT:{
             temp = temp +1;
             break;
       }
       case btnRIGHT:{
             temp = temp - 1;
             break;
       }
       case btnUP:{
             hum = hum + 5;
             break;
       }
       case btnDOWN:{
             hum = hum - 5;
             break;
       }
       case btnSELECT:{
            lcd.begin(16, 2);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Hum Up/Down +-5%");
            lcd.setCursor(0, 1);
            lcd.print("Temp L/R +-1");
            lcd.print((char)223);
            lcd.print("C");
            delay (5000);
            break;
     }
  }
    
    lcd.setCursor(0, 0);
    lcd.print("Hum: ");
    lcd.print(h);
    lcd.print("%");
    lcd.print("(");
    lcd.print(hum);
    lcd.print("%)");
    
    lcd.setCursor(0, 1);
    lcd.print("Tem: ");
    lcd.print(t);
    lcd.print((char)223);
    lcd.print("(");
    lcd.print(temp);
    lcd.print((char)223);
    lcd.print(")");

//adding this so the humidifier will not be powering on and off constantly (humidifier will exceed upper limit by 10% - IF YOU NEED EXACT VALUES COMMENT THIS SECTION AND UNCOMMENT NEXT !!      
      
      int H = hum + 10;    
      if(h < hum )
      digitalWrite(relay1, LOW);
      else if (h >= H)
      digitalWrite(relay1, HIGH);
      

      /* <- UNCOMMENT THIS IF YOU NEED EXACT VALUES BUT COMMENT 5 LINES ABOVE
      if(h < hum )
      digitalWrite(relay1, LOW);
      else
      digitalWrite(relay1, HIGH);
      */


      
      if(t < temp )
      digitalWrite(relay2, LOW);
      else
      digitalWrite(relay2, HIGH);
  
  
  }
}

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