Temperature and Humidity Sensor Lesson
Temperature and Humidity Sensor Lesson
sensor
the surrounding
environment.
These sensors are designed
Temperature as a thermistor or an
integrated temperature
sensor. It converts the
What is
component measures the
relative humidity (RH) in the
air. This is typically done
using a capacitive humidity
Integrated
modules available that
combine the temperature
and humidity sensing
components into a single
Serial.begin(9600);
}
void loop() {
// wait a few seconds between
measurements.
delay(2000);
// read humidity
float humi = dht.readHumidity(); //
read temperature as Celsius
float tempC = dht.readTemperature();
// read temperature as
Fahrenheit
float tempF =
dht.readTemperature(true); //
check if any reads failed
if (isnan(humi) || isnan(tempC) ||
isnan(tempF)) {
Serial.println("Failed to read from
DHT sensor!");
The line if (isnan(humi) || isnan(tempC) ||
isnan(tempF)) in Arduino is a conditional statement
that checks if any of the variables humi, tempC, or
tempF contains the value NaN (Not a Number).
what is if
(isnan(humi) || In Arduino programming, the function isnan() is used
to check if a floating-point value is NaN. NaN is a
isnan(tempC) || special value that represents the result of an invalid
or undefined mathematical operation, such as the
isnan(tempF)) square root of a negative number.