Read Temperature & Humidity
Call the library to get real climate numbers.
Read Temperature & Humidity is a free Arduino & IoT Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Time to Read
Your sensor is wired and the library is ready. Now you will ask it for real numbers and print them to the Serial Monitor. 🌡️
Read Temperature
Call readTemperature() to get the current value in Celsius. Store it in a float because the reading often has decimals.
float t = dht.readTemperature();Read Humidity
Call readHumidity() to get the moisture in the air as a percentage. Like temperature, save it in a float variable.
float h = dht.readHumidity();Want Fahrenheit?
Pass true to readTemperature to get Fahrenheit instead of Celsius. One small argument switches the whole unit.
float f = dht.readTemperature(true);Print the Values
Send your readings to the Serial Monitor so you can watch them live. Labels next to numbers make the output easy to read.
Serial.print("Temp: ");
Serial.println(t);Show Both at Once
You can print temperature and humidity together on one line. A short label before each value keeps the data clear.
Serial.print(h);
Serial.println("% humidity");DHT Is Slow
A DHT updates only about once per second. Reading faster than that just returns stale or failed values, so be patient.
Pace Your Loop
Add a short delay() at the end of loop so you read at a sensible pace. Two seconds is a safe, comfortable gap.
delay(2000);Compute Heat Index
The library can also estimate the heat index, how hot it feels, from temperature and humidity together. It is one handy call.
float hi = dht.computeHeatIndex(t, h, false);Use the Readings
Once you have the numbers, you can act on them: turn on a fan above a threshold or log values for later analysis.
Read Once, Reuse
Save each reading into a variable once per loop, then reuse it. Calling the sensor many times in a row only slows you down.
Quick Check
You want the temperature in Fahrenheit. Which call returns it?
Recap
You read temperature and humidity into floats, printed them with labels, paced the loop, and even computed how hot it feels. 🎉
Frequently asked questions
Is the “Read Temperature & Humidity” lesson free?
Yes — the full text of “Read Temperature & Humidity” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “Read Temperature & Humidity”?
Call the library to get real climate numbers. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Read Temperature & Humidity” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Wire the DHT11/DHT22
- Install the DHT Library
- Read Temperature & Humidity
- Handle Failed Reads