0Pricing
Arduino & IoT Academy · Урок

Считывание температуры и влажности

Вызовите библиотеку, чтобы получить реальные показатели климата.

«Считывание температуры и влажности» — бесплатный урок Arduino & IoT Academy на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Arduino & IoT Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Arduino & IoT Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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

Часто задаваемые вопросы

Урок «Считывание температуры и влажности» бесплатный?

Да — полный текст урока «Считывание температуры и влажности» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Arduino & IoT Academy, подпишись на CoddyKit PRO. Курс Arduino & IoT Academy содержит 4 уроков всего.

Чему я научусь в уроке «Считывание температуры и влажности»?

Вызовите библиотеку, чтобы получить реальные показатели климата. Ты практикуешь Arduino & IoT Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Arduino & IoT Academy?

Предыдущий опыт не требуется. Arduino & IoT Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «Считывание температуры и влажности»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Arduino & IoT Academy?

Да. Каждый урок Arduino & IoT Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Подключение DHT11/DHT22
  2. Установка библиотеки DHT
  3. Считывание температуры и влажности
  4. Обработка неудачных считываний
← Назад к Arduino & IoT Academy