adafruit / adafruit/DHT-sensor-library

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

Open
#210 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/adafruit/DHT-sensor-library/assets/152447294/73b74538-27c3-451d-a60c-bddd706c0857)

Programação:
#include "config.h"
#ifdef ARDUINO_ARCH_ESP32
#include
#else
#include
#endif
#include
#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);
}
}

Contributor guide

Open the contributing guide

Research direction

Start with the posted sketch, especially loop(), the DHT dht.readTemperature() call, the tempe > 30 condition, and digitalWrite() on LED_PIN2. Reproduce it on the ESP8266 with the DHT22 and relay while watching the serial output; the finished behavior should consistently activate the relay above 30°C and deactivate it otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.