I recently installed a Heat Pump Water heater. The new water heater produces condensate which has to be pumped out of my basement. The pump is the same as one installs for an AC system, and so now I have two such pumps in the basement. These pumps have a switch on them that is normally closed, and will be opened if the water in the pump gets too high, indicating that something has gone wrong with the pumping.
I created a quick Blynk app to alert me if with pump was experiencing a problem.
The Blynk app is simple enough, having two large LED widgets to show the status for each pump. It also has email and notification widgets. If either pump switch opens, I get an email and a notification on myphone. It also turns on the built-in LED light on the ESP8266. The two pump switches are connected to GND and D5 & D6.
The code running on an ESP8266 module:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "Alarm.h" // defines auth, ssid, password, version, email address and subject
// =========================================================
// pins
const byte AC = V1;
const byte WH = V2;
const byte WF = V3;
const byte ACpin = D5;
const byte WHpin = D6;
const byte LED = D4;
// colors
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
BlynkTimer timer;
WidgetLED ACled(AC);
WidgetLED WHled(WH);
boolean ACstate = true;
boolean WHstate = true;
void sendMail(String param) {
String emailcontent = param + " pump is having a problem";
Serial.println(emailcontent);
Blynk.notify(emailcontent); // send an app notification
//return; //xxx dont actually send mail during testing
Blynk.email(emailMe, emailsubject, emailcontent);
}
void readstates() // Read switches
{
//AC
boolean isOpen = (digitalRead(ACpin) == HIGH); // contacts are NC
if (isOpen != ACstate) {
if (isOpen) {
sendMail("AC");
ACled.on();
Blynk.setProperty(AC, "color", BLYNK_RED);
} else {
ACled.on();
Blynk.setProperty(AC, "color", BLYNK_GREEN);
}
ACstate = isOpen;
Serial.print("AC ");
Serial.println(ACstate);
}//changed
//WH
isOpen = (digitalRead(WHpin) == HIGH); // contacts are NC
if (isOpen != WHstate) {
if (isOpen) {
sendMail("Water heater");
WHled.on();
Blynk.setProperty(WH, "color", BLYNK_RED);
} else {
WHled.on();
Blynk.setProperty(WH, "color", BLYNK_GREEN);
}
WHstate = isOpen;
Serial.print("WH ");
Serial.println(WHstate);
} // changed
if (ACstate || WHstate) {
digitalWrite(LED,LOW); // reverse logic!
}else{
digitalWrite(LED,HIGH);
}
}
BLYNK_WRITE(WF) { // Network status
int ask = param.asInt() ; // assigning incoming value
if (ask == 1) {
shownetwork(WF);
}
} // V3
void showversion(int pin){
Blynk.setProperty(pin,"label","Ver " + String(FW_VERSION));
}
void shownetwork(int pin){
long rssi = WiFi.RSSI();
Blynk.setProperty(pin,"offLabel","đź“¶ " + String(rssi) + "dBm");
}
BLYNK_CONNECTED() {
// show version of firmware
showversion(V30);
shownetwork(WF);
// start reading
timer.setInterval(500L, readstates);
}
//============================================================
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass); // get onto wifi network
// set the switch pins as input
pinMode(ACpin,INPUT_PULLUP);
pinMode(WHpin,INPUT_PULLUP);
pinMode(LED,OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
}