SunFounder 3in1 Kit
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (it's a very slow␣
˓→sensor)
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperture = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperture)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the humidity and temperature
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperture);
Serial.println(" *C");
}
• The dht.readHumidity() function is called to read the humidity value from the DHT sensor.
• The dht.readTemperature() function is called to read the temperature value from the DHT
sensor.
• The isnan() function is used to check if the readings are valid. If either the humidity or tem-
perature value is NaN (not a number), it indicates a failed reading from the sensor, and an error
message is printed.
4.5.12 5.12 Serial Read
You may have noticed this when using the Serial.print() function. Since there is printing, is there reading? What
is the text box on the Serial Monitor used for? Yes, you guessed it, there are ways to control programs and circuits by
entering information through the text box on the Serial Monitor.
In this project, we will use the I2C LCD1602 to display the text entered in the Serial Monitor in order to experience
the usage of Serial.read().
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
4.5. 5. More Syntax 179