i need help on how to send a notification on my android phone whenever my sensor detect below 5 cm. im using esp 8266 + ultrasonic sensor + buzzer.
/*
* this program is under editing for push notification
*/
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLfaFdxJ4j"
#define BLYNK_DEVICE_NAME "TEST ESP8266"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"
#define echoPin D7
#define trigPin D6
#define buzzer D1
long duration;
int distance;
int safetyDistance;
void ultrasonic()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; //formula to calculate the distance for ultrasonic sensor
Serial.print("Distance: ");
Serial.println(distance);
Blynk.virtualWrite(V0, distance);
safetyDistance=distance;
if (safetyDistance <= 5 && safetyDistance != 0) // You can change safe distance from here changing value Ex. 20 , 40 , 60 , 80 , 100, all in cm
{
digitalWrite(buzzer, HIGH);
}
else{
digitalWrite(buzzer, LOW);
}
}
void setup()
{
Serial.begin(9600);
pinMode(34, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
BlynkEdgent.begin();
delay(2000);
}
void loop() {
BlynkEdgent.run();
ultrasonic();
}
pls do provide me with the code since i dont know very much about coding. thank you