Add details :
• Hardware model + communication type: WEMOS D1 mini connected to Home Wi-Fi Router
• Smartphone: Google Pixel 3
• Blynk server
Problem description:
• Reading DHT22 sensor with interruption. First, I believe that the sensor have problems, I change the sensor with one identical and the result are the same. I think that the code is the problem, please if someone with experience can help me to identify the problem. I add also the measurement from Serial Monitor.
Serial Monitor Result:
Code:
/*ESP8266 PIN: VIRTUAL PIN
* D0-->Relay_Fan V0
* D1-->Relay_Hot V1
* D2-->DHT Sensor V2 -t, V3 -h
* D4-->LED bord V4
*
* Setare Temperatura V5
* Manual/Automat V6
* Led Ventilatie V7
* Led Incalzire V8
* Ventilator V9
* Calorifer V10
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
///////////////////////////////////////////////////////////////////////
char auth[] = ;
char ssid[] = ;
char pass[] = ;
///////////////////////////////////////////////////////////////////////
#define DHTPIN D3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
WidgetLED ledV(V7);
WidgetLED ledC(V8);
int relayPinC = D7;
int relayPinV = D8;
int ledBlink = D4; //LED Blink
int temp_threshold;
int manual_auto;
int pinCalorifer;
int pinVentilator;
////////////////////////////////////////////////////////////////////////
void printInformation()
{
Serial.print("Temperatura= ");
Serial.print(dht.readTemperature());
Serial.print("°C");
Serial.print("\t");
Serial.print("Umiditate= ");
Serial.print(dht.readHumidity());
Serial.print("%");
Serial.println();
}
////////////////////////////////////////////////////////////////////////
void sendAwekening()
{
Blynk.syncVirtual(V5);
Blynk.syncVirtual(V6);
}
/////////////////////////////////////////////////////////////////////////
void sendAlarmInfo()
{
if (isnan(dht.readTemperature()) || isnan(dht.readHumidity()))
{
Serial.println("Eroare la citire Senzor !");
Blynk.notify("Eroare la citire Senzor !");
return;
}
if ((dht.readTemperature()) < 16)
{
Serial.println("ATENTIE, temperatura scazuta !");
Blynk.notify("ATENTIE, temperatura scazuta !");
return;
}
if ((dht.readTemperature()) > 28)
{
Serial.println("ATENTIE, temperatura crescuta !");
Blynk.notify("ATENTIE, temperatura crescuta !");
return;
}
if (manual_auto == 0)
{
Serial.println("ATENTIE, mod MANUAL selectat !");
Blynk.notify("ATENTIE, mod MANUAL selectat !");
return;
}
}
////////////////////////////////////////////////////////////////////////
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(V3, h);
Blynk.virtualWrite(V2, t);
if(manual_auto == 1)
{
if ((t) > temp_threshold)
{
digitalWrite(relayPinV, HIGH);
ledV.on();
}
else
{
digitalWrite(relayPinV, LOW);
ledV.off();
}
if ((t) < temp_threshold)
{
digitalWrite(relayPinC, HIGH);
ledC.on();
}
else {
digitalWrite(relayPinC, LOW);
ledC.off();
}
}
else
{
if (pinVentilator == 1)
{
digitalWrite(relayPinV, HIGH);
pinCalorifer=0;
}
else
{
digitalWrite(relayPinV, LOW);
pinCalorifer=1;
}
if (pinCalorifer == 1)
{
digitalWrite(relayPinC, HIGH);
pinVentilator=0;
}
else
{
digitalWrite(relayPinC, LOW);
pinVentilator=1;
}
}
}
///////////////////////////////////////////////////////////////////////////
//Releu Calorider/Incalzire
BLYNK_WRITE(V9)
{
pinCalorifer = param.asInt();
}
//Releu Ventilator/Racire
BLYNK_WRITE(V10)
{
pinVentilator = param.asInt();
}
//Citire Valoare de Referinta
BLYNK_WRITE(V5)
{
temp_threshold = param.asInt();
}
//Setare Manual-Automat
BLYNK_WRITE(V6)
{
manual_auto = param.asInt();
}
///////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
pinMode(relayPinC, OUTPUT);
pinMode(relayPinV, OUTPUT);
pinMode(ledBlink, OUTPUT);
digitalWrite(relayPinC, LOW);
digitalWrite(relayPinV, LOW);
digitalWrite(ledBlink, LOW);
manual_auto=1;
timer.setInterval(1000L, sendSensor);
timer.setInterval(1000L, sendAwekening);
timer.setInterval(1000L, sendAlarmInfo);
timer.setInterval(1000L, printInformation);
}
////////////////////////////////////////////////////////////////////////////
void loop()
{
Blynk.run();
timer.run();
}
Thanks a lot !