Hardware: NodeMCU ESP8266-12E, pH sensor, digital waterproof temperature sensor
Issue: The triggered mail is continuously sent on email id. Is there any way which will send the email only once the change is encountered in the sensor value.
Improvisation of code is appreciable
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SimpleTimer.h>
SimpleTimer timer;
#define ONE_WIRE_BUS 2 //D4 of nodemcu
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxxx";
int V5variable;
int phValue;
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
sensors.begin();
timer.setInterval(10000L, sendTemps);
Blynk.email("xxxxxxxxx", "Aquarium Alert", "My Blynk project is online."); //sends email to this id
attachInterrupt(digitalPinToInterrupt(2), emailPush , CHANGE); // temp. sensor (digital)
attachInterrupt(digitalPinToInterrupt(17), emailPush , CHANGE); //pH sensor (analog)
Blynk.syncVirtual(V5);
Blynk.virtualWrite(V5, int(V5variable));
}
void emailPush()
{
if (V5variable > 400) // You can write any condition to trigger e-mail sending
{
Serial.println("Turbidity alert"); // This can be seen in the Serial Monitor
Blynk.email("xxxxxx", "Subject: turbidity", "Turbidity imbalance");
}
if (phValue <4 || phValue > 8) // You can write any condition to trigger e-mail sending
{
Serial.println("pH Alert"); // This can be seen in the Serial Monitor
Blynk.email("xxxxxxxx", "Subject: pH Alert", "pH imbalance");
}
if (temp < 23 ) // You can write any condition to trigger e-mail sending
{
Serial.println("Temperature Alert"); // This can be seen in the Serial Monitor
Blynk.email("xxxxxxxx", "Subject: Temperature Alert", "Temperature imbalance");
}
}
//BLYNK_READ(V5){
// int v_val = analogRead(A0);
// float v_volt = v_val*(5/1023);
// int v_tur = (int)(100 - (v_volt/5)*100);
// Blynk.virtualWrite(V5, v_val);
//}
BLYNK_READ(V5) {
int avg = analogRead(A0);
float pHVol = (avg * 5.0) / 1024;
phValue = 3.5 * pHVol + 0.56 ;
Blynk.virtualWrite(V5, phValue);
Serial.println(avg);
}
BLYNK_WRITE(V5)
{
V5variable = param.asInt();
}
void sendTemps()
{
sensors.requestTemperatures(); // Polls the sensors.
temp = sensors.getTempCByIndex(0); // Stores temperature.
Serial.println(temp);
Blynk.virtualWrite(10, temp); // Send temperature to Blynk app virtual pin 10.
}
void loop()
{
timer.run();
Blynk.run();
}