// This program monitors a washing machine with an ESP8266 and updates a smart phone, including a push notification when the "Done" LED turns on. The problem I am having is that the push notification keeps getting issued repeatedly, even though I have tried to make it a one-shot operation in the "notify" section. Probably my code but I can't figure it out. Any ideas?///
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "xxxxxxxxxxxxxxxxxx";
#define BLYNK_PRINT Serial
#define WIFI_SSID "xxxxxxxxxx"
#define WIFI_PASS "xxxxxxxx"
int done;
int sent;
SimpleTimer timer;
void check(){
int sense = !digitalRead(16);
if (sense == HIGH) {
Blynk.virtualWrite(V1, 65000);
}
else {
Blynk.virtualWrite(V1, 0);}
int wash = !digitalRead(12);
if (wash == HIGH) {
Blynk.virtualWrite(V9, 65000);}
else {
Blynk.virtualWrite(V9, 0);}
int rinse = !digitalRead(13);
if (rinse == HIGH) {
Blynk.virtualWrite(V3, 65000);
}
else {
Blynk.virtualWrite(V3, 0);}
int spin = !digitalRead(4);
if (spin == HIGH) {
Blynk.virtualWrite(V4, 65000);
}
else {
Blynk.virtualWrite(V4, 0);}
int complete = !digitalRead(0);
if (complete == HIGH) {
Blynk.virtualWrite(V5, 65000);
done = HIGH;
}
else {
Blynk.virtualWrite(V5, 0);
done = LOW;
}
if ((complete == LOW) && (spin == HIGH)){
sent = LOW;}
int locked = !digitalRead(5);
if (locked == HIGH) {
Blynk.virtualWrite(V8, 65000);}
else {
Blynk.virtualWrite(V8, 0);
}
}
void setup()
{
pinMode(0, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(13,INPUT);
pinMode(12,INPUT);
pinMode(16,INPUT);
Serial.begin(9600);
Blynk.begin(auth, WIFI_SSID, WIFI_PASS);
timer.setInterval(5000L,check);
}
void notify(){
if ((done == HIGH) && (sent == LOW)) {
Blynk.notify("Washer is Done");
sent = HIGH;
}
// else { Blynk.notify(" HUH");}
}
void loop()
{
Blynk.run();
timer.run();
notify();
}
Please use formatting </> it is hard to read your code.
Add Pulldown (10K or whatever) resistors on all Input pins of ESP. Also you can get rid of notify() in main loop by placing it in your check loop so it is only triggered when washing is done. In general I think you overcomplicated your code without any reason by placing Blynk.notify() in separate function.