Issue with DHT11 and dht.h library

I am a beginner trying to create and Arduino project (Arduino Uno R3) for a chair occupancy sensor, that uses a photoresistor and a DHT11 module. When the person sits down, they will sit on the photoresistor, prompting measurements from the DHT11. The DHT11 (also being sat on) will take an initial humidity measurement, and then wait for 10 seconds, and if there has been significant change (value goes up), it will print that it has been occupied. This is part of a larger project that will send out this data eventually, but to begin with, I am just trying to make this first part of code work.

I keep getting the error :

 In function 'void loop()':

final:47:19: error: 'class dht' has no member named 'readHumidity'; did you mean 'humidity'?

 float read1 = DHT.readHumidity(DHTPIN); // giving values to read1 and read 2

                   ^~~~~~~~~~~~

                   humidity

I have two instances in the code where this error occurs.

Here is the code, I apologize if it is messy but I can fix anything if needed to make it clearer:

#include <dht.h>

#define DHTPIN A0   // Analog Pin sensor is connected to

#define ldr_Pin A1; // analogue photo resistor pin 

int photoval; //defining integers for readings 

float read1 = 0; 

float read2 = 0;

float diff = 0;

dht DHT;
 
void setup(){
 
  Serial.begin(9600);

  pinMode (A0,INPUT);//intializing pins
  pinMode (A1, INPUT);
  delay(500);//Delay to let system boot
  delay(1000);//Wait before accessing Sensor

  
 
}//end "setup()"
 
void loop(){
  //Start of Program 

float diff = read1 - read2; // adding value for diff


 photoval = analogRead(A1); //read photosensor
 
if (photoval < 0)


float read1 = DHT.readHumidity(DHTPIN); // giving values to read1 and read 2
 
 delay(10000);// 10 sec delay
float read2 = DHT.readHumidity(DHTPIN);
  


  if (photoval < 0 && diff > 5);// if both sensors are activated, prints "occupied" 
   
   Serial.println ("Occupied!");  
 
 
}// end loop  

>

Thank you in advance to anyone who can help.

That's how your sketch should go with the DHT methods and operators. I am not concerned with logic of your program.

#include <dht.h>
dht DHT;

#define DHTPIN A0   // Analog Pin sensor is connected to
#define ldr_Pin A1; // analogue photo resistor pin 

int photoval; //defining integers for readings
float read1 = 0;
float read2 = 0;
float diff = 0;

void setup()
{
  Serial.begin(9600);

  //pinMode (A0, INPUT); //intializing pins
  pinMode (A1, INPUT);
  //delay(500);//Delay to let system boot
  //delay(1000);//Wait before accessing Sensor
}//end "setup()"

void loop()
{
  float diff = read1 - read2; // adding value for diff
  photoval = analogRead(A1); //read photosensor
  if (photoval < 0)
  {
    int chk = DHT.read11(DHTPIN);
    float read1 = DHT.humidity; // giving values to read1 and read 2
  }
  delay(10000);// 10 sec delay
  float read2 = DHT.humidity;
  if ((photoval < 0) && (diff > 5))//;// if both sensors are activated, prints "occupied"
  {
    Serial.println ("Occupied!");
  }
}// end loop

You may read this link.

I recommend you to load, study and read the relevant Examples that come with every library you use. They show you the most common functions and how they work.

An

Another thing is that you should study the Arduino Reference. In particular, analogRead will never deliver a negative value. https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/

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