0Pricing
Arduino & IoT Academy · Lekcja

Odczytywanie temperatury i wilgotności

Wywoływać bibliotekę, aby uzyskać rzeczywiste dane o warunkach otoczenia.

Odczytywanie temperatury i wilgotności to bezpłatna lekcja Arduino & IoT Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Arduino & IoT Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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. 🎉

Często zadawane pytania

Czy lekcja „Odczytywanie temperatury i wilgotności” jest bezpłatna?

Tak — pełny tekst „Odczytywanie temperatury i wilgotności” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Arduino & IoT Academy, przejdź na CoddyKit PRO. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Odczytywanie temperatury i wilgotności”?

Wywoływać bibliotekę, aby uzyskać rzeczywiste dane o warunkach otoczenia. Ćwiczysz Arduino & IoT Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Arduino & IoT Academy?

Nie wymagamy żadnego doświadczenia. Arduino & IoT Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.

Ile czasu zajmuje lekcja „Odczytywanie temperatury i wilgotności”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Arduino & IoT Academy?

Tak. Każda lekcja Arduino & IoT Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Podłączanie DHT11/DHT22
  2. Instalowanie biblioteki DHT
  3. Odczytywanie temperatury i wilgotności
  4. Obsługa nieudanych odczytów
← Powrót do Arduino & IoT Academy