Leer temperatura y humedad
Llame a la biblioteca para obtener datos climáticos reales.
Leer temperatura y humedad es una lección gratuita de Arduino & IoT Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Arduino & IoT Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 🎉
Preguntas frecuentes
¿La lección «Leer temperatura y humedad» es gratis?
Sí — el texto completo de «Leer temperatura y humedad» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Arduino & IoT Academy, actualiza a CoddyKit PRO. El curso de Arduino & IoT Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Leer temperatura y humedad»?
Llame a la biblioteca para obtener datos climáticos reales. Practicas Arduino & IoT Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Arduino & IoT Academy?
No se requiere experiencia previa. Arduino & IoT Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Leer temperatura y humedad»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Arduino & IoT Academy?
Sí. Cada lección de Arduino & IoT Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Conectar el DHT11/DHT22
- Instalar la biblioteca DHT
- Leer temperatura y humedad
- Gestionar lecturas fallidas