[SOLVED] Request for Member 'humidity' in '2', which is of non-class ERROR

#include <DHT.h> 
#include <LiquidCrystal.h>
DHT DHT11;
#define DHTPIN 2
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);// Define the connection LCD pin void setup()
void setup ()
{
 lcd.begin(16, 2); 
 lcd.clear(); 
 delay(1000);
}
void loop() 

//set up the LCD's number of columns and rows:
//Clears the LCD screen and positions the cursor in the upper-left corner //delay 1000ms
{
 int chk = DHTPIN, read;
 lcd.setCursor (0, 0);
 lcd.print("Humidity:");
 lcd.print((float)DHTPIN. humidity 2;
 lcd.print("%");

 lcd.setCursor(0,1);
 lcd.print("Temp: ");
}

This is my code. But it always comes up with this error.

And the full error please :slight_smile:

And ow, this

lcd.print((float)DHTPIN. humidity 2;
//and 
int chk = DHTPIN, read;

Are not valid code. Open up the example again :wink:

exit status 1
request for member 'humidity' in '2', which is of non-class type 'int'

What do you mean by open up the example again?
And this is my circuit btw.

That is still NOT the complete error. Because the complete error has wayyyyyy more useful information. For example the line number where the error occurs :wink:

The example of the DHT sensor you use. Then you'll see they do it the correct way.

Sorry I didn't know that it wasn't the full because the full full is so long.
Here is some more...

In function 'void loop()':
Temp_and_Humidity_Sensor:20: error: request for member 'humidity' in '2', which is of non-class type 'int'
  lcd.print((float)DHTPIN.humidity, 2;
                          ^
Temp_and_Humidity_Sensor:20: error: expected ')' before ';' token
  lcd.print((float)DHTPIN.humidity, 2;
                                     ^
Using library DHT-sensor-library-master at version 1.3.0 in folder: /Applications/Arduino.app/Contents/Java/libraries/DHT-sensor-library-master 
Using library LiquidCrystal at version 1.0.5 in folder: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal 
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /Users/johanntorres/Documents/Arduino/libraries/Adafruit_Sensor-master 
exit status 1
request for member 'humidity' in '2', which is of non-class type 'int'

ThePhenomenalCheese:
Sorry I didn't know that it wasn't the full because the full full is so long.

That's because it gives you LOADS of information to find the bug :wink:

But like I said, open up the example. Because that line doesn't make sens :wink:

That’s because it gives you LOADS of information to find the bug :wink:

Like its over 9000 characters which isn’t allowed

This is the example.

 int chk = DHTPIN, read;

You REALLY need to think about what you are doing, and you need to explain why you are (ab)using the comma operator this way.

lcd.print((float)DHTPIN. humidity 2;

What do you think this rubbish is doing? Promoting an int to a float, and printing with two decimal places appears to be what you think you are doing. You are NOT.

Even if you add the missing comma (there was one from the previous snippet that you could move), and the missing close parentheses, the call STILL won't make sense.

Printing the int and then ".00" is just plain silly.

I don't need to look at it, YOU need to look at it. I pointed you to the line, now compare it character for character.

And I did look at it quickly, A LOT of changes between you code and the example...

Ok all fixed except now an error-Primary-Expression before '.' token
on this line-

lcd.print((float)DHT.humidity, 2;

ThePhenomenalCheese:
Ok all fixed except now an error-Primary-Expression before '.' token
on this line-

lcd.print((float)DHT.humidity, 2;

What do you think that line is supposed to do?
Did you write this code?
If you copied it, go back to where you got it and check that line.
Tom... :slight_smile:

While it's definitely not the only error with that line, if you can't tell that you're missing a closing parenthesis on that line then you need to put this away for a while and spend some time with some C++ tutorials and some Arduino examples before you try to move up to writing your own code.

Thank you for helping me but now I ask.
Can you change the value of like DHT to something else since it is a primary value which you can’t use.

Huh, what do you want to do? Primary value?

In this line

 int chk = DHT.read(dhtPIN);

you can't use DHT since it is a primary-expression it says...
So can you change DHT to another value so that it isn't?

Ahh, an error. Please post all code that gives you that error and the WHOLE error. Both in code tags.

#include <DHT.h> 
#include <LiquidCrystal.h>
#define dhtPIN 2
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);// Define the connection LCD pin void setup()
void setup ()
{
 lcd.begin(16, 2); 
 lcd.clear(); 
 delay(1000);
}
void loop() 

{
 int chk = DHT.read(dhtPIN);
 lcd.setCursor (0, 0);
 lcd.print("Humidity:");
 lcd.print((float)dhtPIN.humidity, 2);
 lcd.print("%");
 
 lcd.setCursor(0, 1);
 lcd.print("Temp: ");
 lcd.print((float)dhtPIN.temperature, 2);
 lcd.print(" C ");
 delay(1000);
}

And the error

/Users/johanntorres/Documents/Arduino/Temp_and_Humidity_Sensor/Temp_and_Humidity_Sensor.ino: In function 'void loop()':
Temp_and_Humidity_Sensor:17: error: expected primary-expression before '.' token
  int chk = DHT.read(dhtPIN);
               ^
Temp_and_Humidity_Sensor:20: error: request for member 'humidity' in '2', which is of non-class type 'int'
  lcd.print((float)dhtPIN.humidity, 2);
                          ^
Temp_and_Humidity_Sensor:25: error: request for member 'temperature' in '2', which is of non-class type 'int'
  lcd.print((float)dhtPIN.temperature, 2);
                          ^
Using library dht11 at version 1.3.0 in folder: /Applications/Arduino.app/Contents/Java/libraries/dht11 
Using library LiquidCrystal at version 1.0.5 in folder: /Applications/Arduino.app/Contents/Java/libraries/LiquidCrystal 
Using library Adafruit_Sensor-master at version 1.0.2 in folder: /Users/johanntorres/Documents/Arduino/libraries/Adafruit_Sensor-master 
exit status 1
expected primary-expression before '.' token

Where is your declaration off the DHT object? :wink: