0Pricing
Arduino & IoT Academy · Aula

Leia temperatura e umidade

Chame a biblioteca para obter dados reais do clima.

Leia temperatura e umidade é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em 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. 🎉

Perguntas Frequentes

A aula “Leia temperatura e umidade” é grátis?

Sim — o texto completo de “Leia temperatura e umidade” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.

O que vou aprender em “Leia temperatura e umidade”?

Chame a biblioteca para obter dados reais do clima. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Arduino & IoT Academy?

Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Leia temperatura e umidade”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Arduino & IoT Academy?

Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Conecte o DHT11/DHT22
  2. Instale a biblioteca do DHT
  3. Leia temperatura e umidade
  4. Trate leituras malsucedidas
← Voltar para Arduino & IoT Academy