I have the DHT11 temperature sensor and I am trying convert the humidity into a number I can use in compare statments.
If I use:
Serial.print("Humidity (%): ");
Serial.println((int)DHT11.humidity, DEC);
//Prints: 38 for the humidity
However if I use
int tempHum;
tempHum = ((int)DHT11.humidity, DEC);
Serial.print("Humidity (%): ");
Serial.println(tempHum);
//Always Prints: 10
How can I make the humidity into an accurate number other than the serial?
Next time you’re posting, please add a link to the library you’re using – that way we’re sure to talk about the same. You haven’t posted all of your code, but looking at this, it seems to me, that this line
tempHum = ((int)DHT11.humidity, DEC);is cause your problems.If you try to use
tempHum = DHT11.humidityinstead, you might have better results. This is because the cast you’re doing and adding theDECparameter seems to be to the println function, so that the underlying system knows which type it should print.Of course you all need to remember to do a
int retval = DHT11.read(DHT11PIN)and check on your retval that nothing went wrong – this should make it work.