ESP8266 annex pump monitors

Place your projects here
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

ESP8266 annex pump monitors

Post by Zim »

Use at your own risk. High Voltage Hazard

Living on an acreage, I have a well and septic system. If a hose or pipe bursts, it can be undetected for some time and cause major damage.
This project senses current of the well pump and septic pump motors. It will send you a warning text if they run too long. Also, I have a habit of forgetting the bath water running. The project will give a buzzer warning if the well pump runs longer than 6 minutes(the length of time for normal bath level) The texts will be sent when the pump time settings are exceeded. (Don't laugh...you will be old some day too!...lol) Each time the pumps run, their on-time is recorded and displayed once they stop. (non-volatile) You must also uncomment the lines of code specified for the first run only, to create a memory file.


2021-03-14 17_20_43-Mozilla Firefox.jpg
esp8266 motor.jpg




Code: [Local Link Removed for Guests]


'Zim's Annex Pump monitor v1
onHtmlReload create_page
onhtmlchange update
EMAIL.SETUP "smtp.gmail.com", 465, "zim@gmail.com", "zim1234" 'replace with your login / password
D1 = 5:D2 = 4:D5 = 14:D6 = 12 
PIN.MODE D1, INPUT 'Water pump
PIN.MODE D2, INPUT 'Septic pump
PIN.MODE D5, OUTPUT 'buzzer
PIN.MODE D6, OUTPUT 'led
PIN(D5)= 1 'buzzer
PIN(D6)= 0  'led
'file.save "/SPhistory.txt", str$(1)   'for first run
'file.save "/WPhistory.txt", str$(1)   '     " 
Wpset = 10    'adjust when to alarm   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Spset = 8    'adjust when to alarm    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
tubset = 6
Wlook$ = file.read$("/WPhistory.txt")
Slook$ = file.read$("/SPhistory.txt")
WpumpC = 0  'waterpump counter
SpumpC = 0
WpumpD = 0   'waterpump displayed
SpumpD = 0
WPtrg = 0    'waterpump ALARM TRIGGERS
SPtrg = 0
tubtrig = 1
WpumpD$ = "0"  'used for conversion to string to get one decimal place in display
SpumpD$ = "0"  'used for conversion to string to get one decimal place in display
WPinmem$ = ""  
SPinmem$ = ""
stat$ = "Last Run Times"   'STAT WINDOW
ad$ = "zim@gmail.com":nu$ = "72451141113@msg.telus.com":ti$ = "Pumps"
txtbW$ = "text-align:center;display:block;width:75px;height:42px;font-size:30;font-weight:bold"
txtbS$ = "text-align:center;display:block;width:75px;height:42px;font-size:30;font-weight:bold"
txtbstat$ = "text-align:center;display:block;width:160px;height:26px;font-size:15;font-weight:bold"
gosub create_page
timer0 1000, update
wait

create_page:
cls
A$ = ""
A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:24px;}|
A$ = A$ + |</style>|
A$ = A$ + |</style><center>|
A$ = A$ + |<center>|
A$ = A$ + |<p><font color = 'white', font size = '6'>Pump Monitor</font></p>|
A$ = A$ + |</center>|
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>|
A$ = A$ + |<th>|
A$ = A$ + |<p>Well Pump<br>Running<br>Minutes</p></th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(WpumpD, "txt1")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt1", txtbW$)
A$ = A$ + |</table>|
HTML A$
A$ = ""
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>"|
A$ = A$ + |<center><th>|
A$ = A$ + |<p>Septic Pump<br>Running<br>Minutes</p>|
A$ = A$ + |</th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(SpumpD, "txt2") 
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt2", txtbS$)
A$ = A$ + |</table>|
A$ = A$ + |<table align='center' width='300' bgcolor='lightblue' border='1' cellpadding='8'>|
A$ = A$ + |<td><center>|
A$ = A$ + |<b><big>Pump Status</big></b>|
A$ = A$ + |</center><center>|
A$ = A$ + textbox$(stat$, "txt4")
A$ = A$ + cssid$("txt4", txtbstat$)
A$ = A$ + |</center></td></table>|
A$ = A$ + |<br><center>|
A$ = A$ + button$("<b><big>Turn OFF</big><b/>", offf)
A$ = A$ + |&nbsp;&nbsp;&nbsp;&nbsp;|
A$ = A$ + button$("<b><big>Reset</big><b/>", reset)
A$ = A$ + |</table>|
HTML A$
A$ = ""
if WpumpD >= Wpset then html cssid$("txt1", "box-shadow: 12px 0px red;") 'else html cssid$("txt1", "box-shadow: 12px 0px lightgreen;")
if SpumpD >= Spset then html cssid$("txt2", "box-shadow: 12px 0px red;") 'else html cssid$("txt2", "box-shadow: 12px 0px lightgreen;")
if WPtrg > 0 then stat$ = "Well Pump Alert" else stat$ = "Last Run Times"
if SPtrg > 0 then stat$ = "Septic Pump Alert" else stat$ = "Last Run Times"
autorefresh 1000
return

update:
PIN(D6)= 0

if (WpumpD >= Wpset)and(PIN(D1)= 1) then PIN(D5)= 0 else PIN(D5)= 1
if (SpumpD >= Spset)and(PIN(D2)= 1) then PIN(D5)= 0 else PIN(D5)= 1
if PIN(D1)= 1 then 
         WpumpC = WpumpC + 1
            WpumpD$ = STR$(WpumpC/60, "%2.1f")
               WPinmem$ = WpumpD$
             WpumpD = val(WpumpD$)
        endif

if (PIN(D1)= 0) then Wlook$ = file.read$("/WPhistory.txt")
if (PIN(D1)= 0)and(val(WPinmem$) <> val(Wlook$))and(val(WPinmem$) <> 0) then  file.save "/WPhistory.txt", WPinmem$ 'only writes file when different
if (PIN(D1)= 0) then 
          WpumpC = 0
           WpumpD = val(Wlook$)
         endif        

if PIN(D2)= 1 then 
         SpumpC = SpumpC + 1
          SpumpD$ = STR$(SpumpC/60, "%2.1f")
           SPinmem$ = SpumpD$
          SpumpD = val(SpumpD$)  
        endif

if (PIN(D2)= 0) then Slook$ = file.read$("/SPhistory.txt")
if (PIN(D2)= 0)and(val(SPinmem$) <> val(Slook$))and(val(SPinmem$) <> 0) then  file.save "/SPhistory.txt", SPinmem$ 'only writes file when different
if (PIN(D2)= 0) then 
          SpumpC = 0
           SpumpD = val(Slook$)
       endif 

if (PIN(D1)= 1)and(WpumpD < Wpset) then stat$ = "Water Pump is ON" 
if (PIN(D2)= 1)and(SpumpD < Spset) then stat$ = "Septic Pump is ON"
if (PIN(D1)= 0)and(PIN(D2)= 0)and(WpumpD < Wpset)and(SpumpD < Spset) then let stat$ = "Last Run Times"

PIN(D6)= 1
'if WpumpD <> 6 then tubtrig = 0
'
if WpumpD > Wpset gosub alert_WP
if SpumpD > Spset gosub alert_SP
refresh
if WpumpD = 6 then 
            PIN(D5)= 0 'buzzer
              pause 100
                PIN(D5)= 1 'buzzer
                  pause 1000
                    PIN(D5)= 0 'buzzer
                      pause 100
                        PIN(D5)= 1 'buzzer
                     endif
return

alert_WP:
WPtrg = WPtrg + 1
if WPtrg > 0 then stat$ = "Well Pump Alert" else stat$ = "Last Run Times"
if WPtrg >= 3600 then WPtrg = 0  'will email every hour
if WPtrg <> 1 return
html cssid$("txt1", "box-shadow: 12px 0px red;")
print EMAIL (ad$, nu$, ti$, "Well Pump Running Long")
pause 100
'wlog "Well pump running long"
return

alert_SP:
SPtrg = SPtrg + 1
if SPtrg > 0 then stat$ = "Septic Pump Alert" else stat$ = "Last Run Times"
if SPtrg >= 3600 then SPtrg = 0  'will email every hour
if SPtrg <> 1 return
html cssid$("txt2", "box-shadow: 12px 0px red;")
print EMAIL (ad$, nu$, ti$, "Septic Pump Running Long")
pause 100
'wlog "Septic Pump Running Long"
return

reset:
SpumpD = 0:WpumpD = 0:WpumpC = 0:SpumpC = 0:WPtrg = 0:SPtrg = 0:WPinmem$ = "":SPinmem$ = ""
PIN(D5)= 1 
file.save "/SPhistory.txt", str$(0)   
file.save "/WPhistory.txt", str$(0)
goto create_page
return 


tubalert:
if tubtrip = 1 return
PIN(D5)= 0 'buzzer
pause 1000
PIN(D5)= 1 'buzzer
pause 1000
PIN(D5)= 0 'buzzer
pause 1000
PIN(D5)= 1 'buzzer
pause 1000
PIN(D5)= 0 'buzzer
pause 1000
PIN(D5)= 1 'buzzer
tubtrip = 1

return



offf:
PIN(D5)= 1 
timer0 0 
cls
butt$ = "background-color:lightblue;text-align:center;display:block;width:180px;height:80px;font-size:40;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height:1"

A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:36px;}|
A$ = A$ + |</style>|
A$ = A$ + |<br><center>|
A$ = A$ + BUTTON$("Restart", turnon, "but1")
A$ = A$ + cssid$("but1", butt$)
A$ = A$ + |</center>|
A$ = A$ + |</body>|
A$ = A$ + |</html>|
HTML A$
A$ = ""
autorefresh 1000
PIN(D2)= 1
onHtmlReload offf
return

turnon:
PIN(D2)= 0
cls
reboot


You do not have the required permissions to view the files attached to this post.
Last edited by Zim on Sun Mar 03, 2024 9:35 pm, edited 1 time in total.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: ESP8266 annex pump monitors

Post by Electroguard »

Nice project Zim.
I think burdon resistors depend on the current rating of the current transformers, and probably the mains voltage also - so what current transformers are you using, and do you know what would need changing for use on 220V 50Hz AC ?
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

Re: ESP8266 annex pump monitors

Post by Zim »

This is the current transformer that I used. On ebay for $3.
4070020649.jpg

To use on 220vac, I would start with this, presuming your pump current is around 5 amps. The leds are necessary.

Untitled-1.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

Re: ESP8266 annex pump monitors

Post by Electroguard »

Yep, found it on Ali for peanuts, 2000 to 1 ratio, ta.
Mains current sensing has been something I've wanted to do for quite a while - initially to turn on a dust extractor when any of the wood-working equipment is used) - but I have plenty of other uses for monitoring mains current.
I even bought some split transformers to use ages ago, but there has always been something higher priority taking up my time... so now you've paved the way for me to do something much quicker, thanks.
Post Reply