Leggere temperatura e umidità
Utilizzi la libreria per ottenere valori climatici reali.
Leggere temperatura e umidità è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🎉
Domande Frequenti
La lezione «Leggere temperatura e umidità» è gratuita?
Sì — il testo completo di «Leggere temperatura e umidità» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «Leggere temperatura e umidità»?
Utilizzi la libreria per ottenere valori climatici reali. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.
Quanto tempo richiede la lezione «Leggere temperatura e umidità»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Collegare DHT11/DHT22
- Installare la libreria DHT
- Leggere temperatura e umidità
- Gestire le letture non riuscite