Last active
August 12, 2020 18:48
-
-
Save Lucs1590/903146a91c98cb178480d03ca6cc1ebb to your computer and use it in GitHub Desktop.
This is an code to send informations of moisture, soil temperature and air temperature
This file contains 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 "DHT.h" | |
#define DHTPIN 14 | |
#define DHTTYPE DHT11 | |
const int pino_sinal_analogico = 25; | |
DHT dht(DHTPIN, DHTTYPE); | |
float localHum = 0; | |
float localTemp = 0; | |
float percentUm = 0; | |
int valor_analogico ; | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(pino_sinal_analogico, INPUT); | |
delay(1000); // give me time to bring up serial monitor | |
Serial.println(""); | |
Serial.println("ESP32 DHT Temperature and Humidity "); | |
Serial.println(""); | |
dht.begin(); | |
} | |
void loop() | |
{ | |
getDHT(); | |
Serial.print("Temp: ==> "); | |
Serial.print(localTemp); | |
Serial.print(" Hum ==> "); | |
Serial.println(localHum); | |
Serial.print(" Hum ==> "); | |
Serial.println(percentUm); | |
delay(2000); | |
//Le o valor do pino A0 do sensor | |
valor_analogico = analogRead(pino_sinal_analogico); | |
//Mostra o valor da porta analogica no serial monitor | |
//Solo umido, acende o led verde | |
if (valor_analogico > 0 && valor_analogico < 400) | |
{ | |
Serial.println(" Status: Solo umido"); | |
Serial.println(valor_analogico); | |
} | |
//Solo com umidade moderada, acende led amarelo | |
if (valor_analogico > 400 && valor_analogico < 800) | |
{ | |
Serial.println(" Status: Umidade moderada"); | |
Serial.println(valor_analogico); | |
} | |
//Solo seco, acende led vermelho | |
if (valor_analogico > 800 && valor_analogico < 1024) | |
{ | |
Serial.println(" Status: Solo seco"); | |
Serial.println(valor_analogico); | |
} | |
delay(100); | |
} | |
void getDHT() | |
{ | |
float tempIni = localTemp; | |
float humIni = localHum; | |
localTemp = dht.readTemperature(); | |
localHum = dht.readHumidity(); | |
if (isnan(localHum) || isnan(localTemp)) // Check if any reads failed and exit early (to try again). | |
{ | |
localTemp = tempIni; | |
localHum = humIni; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment