Dear Blynk Community Members, I’m new to blank and find it very interesting and trying many different things.
I want to make an Incubator and want to get an e-mail notification only ONCE if Temp < 30 or Temp > 40 or Humidifity < 40%.
I wrote (basically modify) the following code. With this code I’m getting multiple (every 20 seconds)
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***"; //Enter the Auth code which was send by Blink
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***"; //Enter your WIFI Name
char pass[] = "***"; //Enter your WIFI Password
#define DHTPIN 2 // Digital pin 4
#define LITEPIN1 D1 //Light 1
#define LITEPIN2 D2 //Light 2
//Register Light to virtual pin 1 (V1)
WidgetLED led1(V1); //Virtual Pin V1 for light ON/OFF
//Register Light to virtual pin 2 (V2)
WidgetLED led2(V2); //Virtual Pin V1 for Humidity
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
Serial.println(t);
Serial.println(h);
if (t <= 37.5) // the temperature in your incubator should be maintained between 37 and 39 degrees Celcius.
{
digitalWrite(LITEPIN1,LOW);
digitalWrite(LITEPIN2,LOW);
led1.on();
Serial.println("Lights are ON");
}
else
{
digitalWrite(LITEPIN1,HIGH);
digitalWrite(LITEPIN2,HIGH);
led1.off();
Serial.println("Lights are OFF");
}
if (h <= 40) //The humidity levels should be between 50 and 55% and then increase to about 65% for the final three days of incubation.
{
led2.on();
Serial.println("Low Humidity");
Blynk.email("my_email@hotmail.com", "Subject: Low Humidity", "Humidity level is low");
}
else
{
led2.off();
Serial.println("Humidity Level is OK");
}
if (t > 40) // You can write any condition to trigger e-mail sending
{
Serial.println("Temperature is higher than 40oC"); // This can be seen in the Serial Monitor
Blynk.email("my_email@hotmail.com", "Subject: High Temp", "Temp is > 40");
}
if (t < 30) // You can write any condition to trigger e-mail sending
{
Serial.println("Temperature is Low than 30oC"); // This can be seen in the Serial Monitor
Blynk.email("my_email@hotmail.com", "Subject: Low Temp", "Temp is < 30");
}
delay(20000);
}
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("my_email@hotmail.com", "Subject: Blynk is Online", "hardware gets connected to Blynk Server");
dht.begin();
pinMode (LITEPIN1, OUTPUT);
pinMode (LITEPIN2, OUTPUT);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}