1
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

1
  • 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 Commented Jul 3, 2021 at 10:36

1 Answer 1

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!"); return; } 

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.