Created
October 15, 2020 21:55
-
-
Save lennonjesus/c9714b1082c606aa01c29cbadcfe63f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <TinyDHT.h> | |
#define DHTPIN A1 // pino que estamos conectado | |
#define DHTTYPE DHT11 // DHT 11 | |
// Conecte pino 1 do sensor (esquerda) ao +5V | |
// Conecte pino 2 do sensor ao pino de dados definido em seu Arduino | |
// Conecte pino 4 do sensor ao GND | |
// Conecte o resistor de 10K entre pin 2 (dados) | |
// e ao pino 1 (VCC) do sensor | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println("DHTxx test!"); | |
dht.begin(); | |
} | |
void loop() | |
{ | |
delay(1000); | |
// A leitura da temperatura e umidade pode levar 250ms! | |
// O atraso do sensor pode chegar a 2 segundos. | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
// testa se retorno é valido, caso contrário algo está errado. | |
if (isnan(t) || isnan(h)) | |
{ | |
Serial.println("Failed to read from DHT"); | |
} | |
else | |
{ | |
Serial.print("Umidade: "); | |
Serial.print(h); | |
Serial.print(" %t"); | |
Serial.print("Temperatura: "); | |
Serial.print(t); | |
Serial.println(" *C"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment