Hey all
So i am using blynk to monitor a temp/humidity sensor that was built for me. I am a little familiar with working with Arduino stuff, but i am not super experienced so i apologize if this is a dumb question.
Once connected, the sensor array works well, but at ~12 hours after connecting, i get a NaN reading on my Blynk GUI. On the advice of a more technical friend, i inseted the following line into the code:
float h = dht.readHumidity();
delay(200);
float t = dht.readTemperature();
// fahrenheit = t * 1.8 + 32.0;
if (t == NAN){
Blynk.email("EMAILADDRESS", "ALARM", "Temp is NaN");
Blynk.email("EMAILADDRESS", "ALARM", "Temp is NaN");
}
if (h == NAN){
Blynk.email("EMAILADDRESS", "ALARM", "Humid is NaN");
Blynk.email("EMAILADDRESS", "ALARM", "Humid is NaN");
}
If i understand this correctly, i should get an “ALARM” email if the board gets a NaN. I received no email. The lads at Contact Blynk said i would only get a NaN from the sensors themselves. Can anyone help me out? Thanks in advance.
Here follows the code flashed to the device in its entirety:
// display blynk information on serial monitor output
#define BLYNK_PRINT Serial
// set up esp, blynk, dht and timer libraries
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "authcode"; //insert here your token generated by Blynk
#include <SimpleTimer.h>
SimpleTimer timer;
#include <DHT.h>
#define DHTPIN 14 //dht22 data in
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float humidity, temp_f; // Values read from sensor
// create a function called "sendData" and repeat it every x minutes, refer to line 162
void sendData(){
float h = dht.readHumidity();
delay(200);
float t = dht.readTemperature();
// fahrenheit = t * 1.8 + 32.0;
if (t == NAN){
Blynk.email("email", "ALARM", "Temp is NaN");
Blynk.email("email", "ALARM", "Temp is NaN");
}
if (h == NAN){
Blynk.email("email", "ALARM", "Humid is NaN");
Blynk.email("email", "ALARM", "Humid is NaN");
}
Blynk.virtualWrite(11, h);
delay(200);
Blynk.virtualWrite(10, t);
delay(300);
// Blynk.virtualWrite(12, fahrenheit);
// delay(300);
// blink green LED on/off after upload to blynk server
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(200);
// print on serial monitor temp and humid values
Serial.print("temperature C");
Serial.println( t );
delay(500);
Serial.print("humidity %");
Serial.println( h );
delay(500);
// checking for too lows and highs
// email if necessary
// blink the yellow alarm led if necessary
if (t < 5){
Blynk.email("email", "ALARM", "Temp is below 5C");
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
}
delay(1000);
if (t > 40){
Blynk.email("email", "ALARM", "Temp is above 40C");
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
}
delay(1000);
if (h < 20){
Blynk.email("email", "ALARM", "Humid is below 20%");
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
}
delay(1000);
if (h > 90){
Blynk.email("email", "ALARM", "Humid is above 90%");
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
}
}
void setup(){
Serial.begin(9600);
dht.begin();
pinMode(4, OUTPUT); //yellow LED to test power
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
digitalWrite(4, HIGH);
delay(300);
digitalWrite(4, LOW);
delay(300);
pinMode(5, OUTPUT); //green LED for online
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(500);
Blynk.begin(auth, "SSID,pw"); //insert here your SSID and password
delay(500);
Serial.print("device alive, go to phone app");
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(300);
digitalWrite(5, LOW);
delay(300);
digitalWrite(5, HIGH);
delay(500);
// trigger sendData function above every x seconds
timer.setInterval(10000, sendData); // 10000 = 10 seconds (x/1000=seconds)
}
// everything is setup, now the system starts until power off
void loop(){
Blynk.run();
timer.run();
}