Currently this code allows me to read the level in percentage in my sump pit. thats great. however i need your help in modifying it so that it will notify me in case the level rises above a certain percent. also i would like it to continue sending notification every 1 min or so.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = " ";
SimpleTimer timer;
#define echoPin D7 // Echo Pin
#define trigPin D6 // Trigger Pin
long duration, distance; // Duration used to calculate distance
void setup()
{
Serial.begin (9600);
Blynk.begin(auth, " ", " ");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(1000L, program);
}
void program()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
distanceinches = distance*0.393701 //convert cm to inches
LevelPercent = distanceinches/28.5 //28.5 inches deep sump pit
}
BLYNK_READ(V8)
{
Blynk.virtualWrite(8,distance);// virtualpin 8 distance
}
void loop()
{
Blynk.run();
timer.run();
}