DHT-sensor-library icon indicating copy to clipboard operation
DHT-sensor-library copied to clipboard

Estou com Problema com a minha ESP8266 (ESP01s) com o DHT22

Open IgorcMarchi opened this issue 2 years ago • 0 comments

Estou com problemas ao ativar um relé, eu estou utilizando esse sensor para quando a temperatura estiver maior que 30 ele ative o relé, além disso também estou utilizando a biblioteca adafruit para mostrar a temperatura e acionar o relé. Contudo mesmo aparecendo os dados do sensor no adafruit eu não consigo acionar usando a comparação do "if". Preciso de ajuda urgente! Capturar

Programação: #include "config.h" #ifdef ARDUINO_ARCH_ESP32 #include <WiFi.h> #else #include <ESP8266WiFi.h> #endif #include <Espalexa.h> #include "DHT.h" /*** Example Starts Here ****/

// digital pin 5 int returnu = 0; int returno = 0; #define DHTPIN 2
#define LED_PIN2 0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE, 15);
// button state

// set up the 'digital' feed AdafruitIO_Feed *digital1 = io.feed("temperatura"); AdafruitIO_Feed *digital2 = io.feed("umidade"); AdafruitIO_Feed *digital3 = io.feed("ventilador"); AdafruitIO_Feed *digital4 = io.feed("teste1"); AdafruitIO_Feed *digital5 = io.feed("teste2"); boolean connectWifi(); void Funcion_pino2(uint8_t brightness);

// Change this!! const char* ssid = "Sla"; const char* password = "11223344";

boolean wifiConnected = false;

Espalexa espalexa; void setup() { dht.begin(); pinMode(LED_PIN2, OUTPUT);
// set button pin as an input

// start the serial connection Serial.begin(115200);

// wait for serial monitor to open while(! Serial);

// connect to io.adafruit.com Serial.print("Connecting to Adafruit IO"); io.connect(); digital3->onMessage(handleMessage2); // wait for a connection while(io.status() < AIO_CONNECTED) { Serial.print("."); delay(500);

}

// we are connected Serial.println(); Serial.println(io.statusText()); digital3->get(); }

void loop() {

// io.run(); is required for all sketches. // it should always be present at the top of your loop // function. it keeps the client connected to // io.adafruit.com, and processes any incoming data. io.run(); espalexa.loop(); delay(1); int umid = (int)dht.readHumidity();
int tempe = (int)dht.readTemperature(); // grab the current state of the button. // we have to flip the logic because we are // using a pullup resistor.

// return if the value hasn't chan if(tempe != returnu){ digital1->save(tempe); digital2->save(umid); returnu = tempe; } if(umid != returno){ digital2->save(umid); returno = umid; } if(tempe > 30){ digitalWrite(LED_PIN2,LOW); } else{ digitalWrite(LED_PIN2,HIGH); } digital3->onMessage(handleMessage2); } void handleMessage2(AdafruitIO_Data *data) { digitalWrite(LED_PIN2, data->toPinLevel()); } boolean connectWifi(){ boolean state = true; int i = 0;

WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); Serial.println("Connecting to WiFi");

// Wait for connection Serial.print("Connecting..."); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (i > 20){ state = false; break; } i++; } Serial.println(""); if (state){ Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println("Connection failed."); } return state; } void Funcion_pino2(uint8_t brightness){ if(brightness){ digitalWrite(LED_PIN2,LOW);
} else { digitalWrite(LED_PIN2,HIGH); } }

IgorcMarchi avatar Nov 29 '23 22:11 IgorcMarchi