Hi Pete & Expert
I am having issue with my project, basically sending notification to my gmail when condition is match
NodeMCU to detect distance and send email
The same Node MCU to send email if fire is detected.
hardware that i used
NodeMCU
IR Flame sensor
Ultra sonic
If I use the code separately Ultra sonic (distance alert) & Fire sensor both are works well.
When I combined both code together I only get Blynk app alert & gmail for distance and not for fire alert.
Here is my code.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define trig D2
#define echo D1
long duration;
int distance;
// You should get Auth Token in the Blynk App.
char auth[] = "mycode";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "mywifi";
char pass[] = "mypwd";
int flag=0;
void notifyOnFire()
{
int isButtonPressed = digitalRead(D3);
if (isButtonPressed==1 && flag==0) {
Serial.println("Fire in the House");
Blynk.email("mymail@gmail.com", "Fire Alert", "Please Wear Your Safety Helmet!");
Blynk.notify("Alert : Fire in the House");
flag=1;
}
else if (isButtonPressed==0)
{
flag=0;
}
}
BlynkTimer timer;
void setup()
{
// Debug console
pinMode(trig, OUTPUT); // Sets the trigPin as an Output
pinMode(echo, INPUT); // Sets the echoPin as an Inpu
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(D3,INPUT_PULLUP);
timer.setInterval(1000L,notifyOnFire);
// Setup a function to be called every second
timer.setInterval(15000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
void sendSensor()
{
digitalWrite(trig, LOW); // Makes trigPin low
delayMicroseconds(2); // 2 micro second delay
digitalWrite(trig, HIGH); // tigPin high
delayMicroseconds(10); // trigPin high for 10 micro seconds
digitalWrite(trig, LOW); // trigPin low
duration = pulseIn(echo, HIGH); //Read echo pin, time in microseconds
distance = duration * 0.034 / 2; //Calculating actual/real distance
Serial.print("Distance = "); //Output distance on arduino serial monitor
Serial.println(distance);
if(distance >= 5)
{
Blynk.tweet("My Arduino project is tweeting using @blynk_app and it’s awesome!\n #arduino #IoT #blynk");
Blynk.email("mymail@gmail.com", "Distance Alert", "Disntance reached!");
Blynk.notify("Disntance reached! ");
}
Blynk.virtualWrite(V0, distance);
delay(1000); //Pause for 1 seconds and start measuring distance again
}
Thank you.
Regards
KM