void Sensor_value()
{   server.handleClient();
    humidity = dht.readHumidity();
    temperature = dht.readTemperature();     

I want to make condition if temperature = null and Humidity= null that means the sensor fails to take reading so I want to return and take value again

  • both functions readHumidity() and readTemperature() have float as return type. NULL is a value of type pointer, so you will never get NULL as a result from these functions. I think the library returns NAN if it fails to read from the sensor
    – Lefteris E
    Jul 3, 2021 at 10:36

1 Answer 1


The way to do this is:

float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);

if (isnan(h) || isnan(t) || isnan(f)) {
  Serial.println("Failed to read from DHT sensor!");

See https://www.hackster.io/MisterBotBreak/how-to-use-temperature-and-humidity-dht-sensors-9e5975 and https://stackoverflow.com/questions/40874880/getting-nan-readings-from-dht-11-sensor.

NULL should only be used with pointers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.