Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:43 16 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : 8 Relay timed alarm controller

Author Message
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 07:06pm 08 Jan 2017
Copy link to clipboard 
Print this post

Just commissioned my latest project , this one is set up as a an irrigation controller for the Garden and Greenhouse but it could be used for other timed repeatable tasks.

Mine has timed tasks for 2 garden areas and Greenhouse, misting for greenhouse, Exhaust fan for greenhouse, 2 water flow sensors and 10000 ltr tank level sensor.
Timed tasks can be up to 5 On/Off cycles per day/area, days of the week etc.
Total water usage monitoring, usage per day exceeded per day will trigger override.
Configuration Set up is via Wifi , sent by complete file or by single line.








Sample config file.
1,Z1-Bed.1,W,1,0123456,08:00,08:05,09:00,09:00,09:00,09:00,09:00,09:00
2,Z2-Bed.2,W,0,0123456,00:00,00:00,09:00,09:0
3,Z3-GH.Tank,En,
4,Z4-Spare.1
5,Z5-Spare.2
6,Z6-GH.Water,W,1,0123456,00:00,00:00,12:58,13:50
7,Z7-GH.Mist,,30,30
8,Z8-GH.Fan,En,30,27
9,Usage Greenhouse-House and Garden,0,0
10,Max Daily Usage,500


Main code for this application is below but is also supported by a bunch of code in the library and firmware in the ESP8266 Wifi module.

'http://www.codenquilts.com.au
'Michael Ogden June 2016
'screen functions Geoff Graham
'water flow code - TassyJim
'Greenhouse and Irrigation controller
'v1.2 fixed problem with Run/Stop toggling itself.
'Using MXWifi2.9 or 170MXwifi Library code
Option Explicit
Option Default Integer
Option autorun On

'Constants
const Sver$="Ver 1.2"
Const NumofMonth$="JAN,FEB,MAR,APR,MAY,JUN,JLY,AUG,SEP,OCT,NOV,DEC"
CONST STRB=24 : SETPIN STRB,DOUT:PIN(STRB)=1 'CONFIGURE i/o strobe pin
Dim wholedate$
'Define I/O
SETPIN 17, CIN 'House Flow
SETPIN 18, CIN 'GHouse Flow
'setpin 10, dout 'Redled
setpin 10,din,PULLUP 'water tank level High
setpin 9,din,PULLUP 'water tank level Low

'Global variables


Dim Integer key_coord(5, 5)
Dim String key_caption(5)
Dim Integer c
''Flag Variable
Dim integer flag(13)
'0=err
'1=timeout
'2=Relay memory
'3=display update
'4=Alarms On
'5=Alarms Off
'7=time
'8=ntp
'9=busy
'10=override
'11=Watersensors
'12=Flashsave
'13=TankFill
relay(0) ' ensure all relays are off

Dim Integer idpdata(10) 'general array
Dim string results(11) length 10 'data results array
'1=Ghouse temp
'2=ghouse Hum
'3=rain
'4=Tank Level
'5=House Flow
'6=GHouse Flow
'7=Tank Level
'8=GHouse Flow
'9=Total Tank Flow
'10=24hr Usage

Dim Secs
dim preset,x,Errorflag
dim ErrorMsg$
dim AlarmTime,NO_CLS,backup


'Print "Greenhouse & Irrigation Ctrl "+sver$
Pusc 'Power up system check
initWiFifile 1 'call initialise WiFi file transfer library, set comm port to use

'intialise I/O


Var Restore

cls
Text MM.HRes/2, MM.VRes/2, "INITIALISE", CM, 1,2, RGB(white)
'intialise modules


'Initialise Arrays
if Touch(x) <> -1 then
backup=0
Text MM.HRes/2, MM.VRes/2, "DEFAULTS RESTORED", CM, 1, 1, RGB(white)
end if
pause 1000

' restore the settings. If this is the first time set the defaults

If backup = 0 Then
backup=1
results(10)="0"
Var Save backup,results()
EndIf


for x=1 to 11
print "Results:";x;" ";results(x)
next
for x=1 to 10
print "Config:";x;" ";cfgdata(x)
next




'interupts
Settick 1000 ,T1,1 'establish seconds "Tick Timer"
settick 300000,SavetoFlash,3
flag(3)=1 'content update
flag(8)=1 'NTP flag


'debug=1
'*** start main program loop
Do
'StartTime = Timer
Watchdog 60000


Do While Touch(x) <> -1

Loop

' draw the main menu options

if NO_CLS=0 then CLS
if preset=0 then
Text 80, 10,"RLY1-8" , CM, 1,1, RGB(white)
showrelays
DrawButtonOnly 3, "ZONE",245,155,70
if flag(10)=0 then
DrawButtonOnly 0, "STOP!",5,155,90
else
DrawButtonOnly 0, " RUN ",5,155,90
end if
No_CLS=1

else
For x=1 To 8 'clear relay leds
Circle 100+x*25,10, 5, 0, 1, 0, rgb(black)
next
Text MM.HRes/2, 10,"Menu " + parse$(cfgdata(preset),1) , CM, 1,2, RGB(white)
DrawButtonOnly 0, "< ",5,155,70
DrawButtonOnly 1, "ON",85,155,70
DrawButtonOnly 2, "OFF",165,155,70
DrawButtonOnly 3, "ZONE",245,155,70
end if
Line 0, 25, MM.HRes, 25, 1, RGB(210, 210, 210)
Line 0, 175, MM.HRes, 175, 1, RGB(210, 210, 210)


if errorflag=1 then
Text MM.HRes/2,220, errormsg$,c , 1, 1, RGB(RED)
else
Text MM.HRES/2,220, "Greenhouse & Irrigation Ctrl "+sver$,c , 1, 1, RGB(white)
endif
' get the selected button and take action based on the button
'print "main loop"

Select Case CheckButtonPress(0, 3)
Case 0
if preset=0 then
'print "case zero"
if flag(10)=0 then 'if in free run
relay(0)
flag(10)=1 'set Override flag
else
flag(10)=0 'set Override flag
end if
else
PReset=0
end if
Case 1
if flag(10)=0 or preset=8 then relay(preset,1) 'relay on only in RUN or for Greenhouse Fan
Case 2
relay(preset,0)
Case 3
No_CLS=0 'clear CLS flag to allow clear screen
preset=preset+1
if preset>8 then
preset=0
end if
End Select
flag(3)=1 'ensure screen update
'Print "Loop elapsed time"; Timer-StartTime
Loop
'***** End main program loop
End


'T1 - 1second Tick interrupt
'set up some time flags
Sub T1
local x
secs=secs+1 'update seconds timer
if secs => 86400 then '24 hrs reached
secs = 0 'reset counter
results(10)="0" 'reset 24hr usage
EndIf
If flag(1)>0 Then flag(1)=flag(1)-1
if Flag(13)>0 then flag(13)=flag(13)+1
Text 105,35, wholedate$ + " " + time$,L , 1, 1, RGB(green)
if secs mod 25 = 0 Then 'every 25 secs
if flag(8)=1 then
print "Try to get NTP data"
xbsend "time:" 'try to get NTP time data
end if
end if

if secs mod 5 = 0 Then
FLAG(3)=1 'content update
endif

if secs mod 10 = 0 Then
FLAG(11)=1 'read water sensors
EndIf

if secs mod 3600 = 0 then 'every 60 mins
FLAG(8)=1 'set NTP flag
endif

if secs mod 15 = 0 then 'every 15 secs
if flag(4)=0 then FLAG(4)=1 'Check Alarms On
endif
if secs mod 17 = 0 then 'every 17 secs
if flag(5)=0 then FLAG(5)=1 'Check Alarms Off
endif
End Sub



'*************** Specific Subs/Functions **********



SUB WaterSensors
local integer flow1,flow2,range1
flow1=PIN(17)
flow2=PIN(18)
'flow2=19003 'bench testing
print "Flows ";flow1;" ";flow2
results(8)=str$(val(results(8))+(flow1/330 MOD 1000000),8,0," ")' ghouse
results(9)=str$(val(results(9))+(flow2/330 MOD 1000000),8,0," ")' tank
results(10)=str$(val(results(10))+(flow2/330 MOD 1000000),8,0," ")' 24hrs use
'reset flows
SETPIN 17, CIN 'House Flow
SETPIN 18, CIN 'GHouse Flow
range1=DISTANCE(26,16)' house tank
results(7)=str$(((270 - range1)*42),3,0," ") '~10080 full
xbsend "udp.send:||"+TIME$+","+results(7)+","+results(8)+","+results(9)+","+results(10)
END Sub

sub usage
results(8)=parse$(cfgdata(9),2)
results(9)=parse$(cfgdata(9),3)
end sub

Sub SavetoFlash
Print "Saving to Flash"
Var save cfgdata(),results()
End Sub

'Test Alarms against time and weekday
sub TestAlarms(Off%) As integer
local Integer MinuteTime,z,cr,nr
local day$
StartTime = Timer
'Get first two letters of weekday to compare
day$=str$(GetDOW(SDT("","","DT")))
MinuteTime = sdt("","","m")
'print day$;" ";minutetime
' TestAlarms
'if off%=1 then increment times pos by 1 for off time
print "test alarms"
if flag(8)=1 then exit sub 'dont test if Time flag is set
For z=1 to 8
Circle 10, 10, 5, 0, 1, 0, rgb(red)
select case parse$(cfgdata(z),2)
case "W" 'watering alarm cycles
cr=0
Print cfgdata(z)
nr= Val(parse$(cfgdata(z),3))
print "repeats:";nr
Do while cr<nr 'cycle through start and finish times upto the # of repeats
if instr(parse$(cfgdata(z),4),day$)>0 then
'check On Time for 00:00 if so then exit
If sdt("",parse$(cfgdata(z),5+(cr*2)+0),"m") =0 Then
print "Zero time alarm , Time Alarm OFF"
relay(z,0)
else
print "time Now?Alarm Time:";minutetime;"/"; sdt("",parse$(cfgdata(z),5+(cr*2)+off%),"m") 'offset is position+(repeats*2)+on or off(0 or 1)
If MinuteTime = sdt("",parse$(cfgdata(z),5+(cr*2)+off%),"m") Then
if off%=0 And flag(10)=0 Then 'if not in override
print "Time Alarm ON"
relay(z,1)
else
print "Time Alarm OFF"
relay(z,0)
end if
end if
end if
end if
cr=cr + 1 'increment repeat counter
Loop
case else
'if not using watering cycles set specific actions for each relay
print z;" ";parse$(cfgdata(z),2)
if z=8 and parse$(cfgdata(z),2)="En" then 'Enable Greenhouse fan
if val(results(1))=>val(parse$(cfgdata(z),3)) then 'temp high turn on fan
relay(z,1)
elseif val(results(1))=<val(parse$(cfgdata(z),4)) then 'temp low turn off fan
relay(z,0)
end if
end if
if z=7 and parse$(cfgdata(z),2)="En" And flag(10)=0 then 'Enable Greenhouse Mist
'misting code
end if
if z=3 and parse$(cfgdata(z),2)="En" And flag(10)=0 Then 'Enable Greenhouse Tank Fill
if pin(10)<>0 and flag(13)=0 then 'top sensor not made and delay has not been set, so top up water Reservoir
flag(13)=1 'start Tank Fill relay delay sequence
end if
if pin(10)=0 or flag(13)>100 then 'only turn off when top sensor is made again or timed out
relay(z,0)
flag(13)=0
end if
end if
end select
Circle 10, 10, 5, 0, 1, 0, rgb(black)
Next
Print "Alarm Loop elapsed time"; Timer-StartTime
Circle 10, 10, 5, 0, 1, 0, rgb(black)
End sub


'External command processing sub Routine if required
sub extCmd
local temp$,ext$
print "External Commands:";from$;cmd$;cfg$;strin$
select case cmd$
case "ntp"
wholedate$=parse$(strin$,1," ")+" "+parse$(strin$,3," ")+" "+parse$(strin$,2," ")+" "+parse$(strin$,5," ")
if wholedate$<>"" then
flag(7)=0 'got time reset flag
flag(8)=0 'reset NTP flag
time$=left$(parse$(strin$,4," "),5)
print time$
print wholedate$
temp$=ucase$(parse$(strin$,2," "))
date$=parse$(strin$,3," ")+"-"+Str$(moy(temp$),2)+"-"+parse$(strin$,5," ")
print date$
If IsDST()=1 Then IncTime
'time$="23:59:00" 'test for midnight
end if
case "Log"
results(1)=parse$(strin$,9)
results(2)=parse$(strin$,10)
results(3)=parse$(strin$,5)
case "uMsavetoflash"
SavetoFlash
case "uMusage"
usage
case "uMconfig"
For res=1 To cfgnum
Print cfgdata(res)
xbsend "udp.send:|"+from$+"|Config:"+cfgdata(res)
WaitforReady
Next
end Select
end sub

'update the main screen data
sub updatemain
Text 5,55, "Tank "+ results(7)+ "L" ,L , 1, 1, RGB(green)
Text 5,75, "Usage - House/Garden "+ results(9)+ "L" ,L , 1, 1, RGB(green)
Text 5,95, "Usage - Greenhouse "+ results(8)+ "L" ,L , 1, 1, RGB(green)
Text 5,115, "Greenhouse - Temperature " + str$(val(results(1)),3,1," ") + chr$(96)+"C" ,L , 1, 1, RGB(green)
Text 5,135, "Greenhouse - Humidity " + str$(val(results(2)),3,0," ")+ "%" ,L , 1, 1, RGB(green)
Text 5,155, "Rain " + str$(val(results(3)),3,0," ")+ "mm" ,L , 1, 1, RGB(green)
end sub

sub updatecycle(cz)
local bin$="1,2,4,8,16,32,64,128"
Text 5,55, "Days of Week (Sun=0) " + parse$(cfgdata(cz),4),L , 1, 1, RGB(White)
Text 5,75, "Cycle1 On:"+ parse$(cfgdata(cz),5) + " Off:" + parse$(cfgdata(cz),6),L , 1, 1, RGB(green)
Text 5,95, "Cycle1 On:"+ parse$(cfgdata(cz),7) + " Off:" + parse$(cfgdata(cz),8) ,L , 1, 1, RGB(green)
Text 5,115, "Cycle1 On:"+ parse$(cfgdata(cz),9) + " Off:" + parse$(cfgdata(cz),10) ,L , 1, 1, RGB(green)
if (val(parse$(bin$,cz)) and flag(2)) >0 then
Text 5,135, "Watering NOW! "
else
Text 5,135, "Watering Off "
end if
end sub


' check if a button has been touch and animate the button's image
' returns the buttin number
Function CheckButtonPress(startn As Integer, endn As Integer) As Integer
Local Integer keydwn, xt, yellowt, n,r
keydwn = 0
flag(1)=30 'set flag if not in main page waiting for input
' keep looping while waiting for a press and release
Do
'print "buttonpress loop"
'***** mxWiFi Hook ****
if userprocessflag=1 then
print "Userprocess"
StartTime = Timer
UserProcess
UserProcessFlag=0
xbsend "udp.send:|"+from$+"|"+chr$(4)+"|"
Print "Processing elapsed time"; Timer-StartTime
Watchdog 60000 'ensure watchdog is set to long time out again
continue do 'skip to a new loop immediately , there may be more external processing to do
endif
'***** End mxWiFi Hook ****
'check flags
'print "checkbutton loop"
if flag(4)=1 then 'Alarms On
testalarms(0)
FLAG(4)=0
end if

if flag(5)=1 then 'Alarms Off
testalarms(1)
FLAG(5)=0
end if
'return to main page
If flag(1)=0 Then
PReset=0 'switch to main page after pressflag period
flag(3)=1 'ensure screen update
checkbuttonpress=-1
print "checkbuttonpress:";checkbuttonpress
exit function
end If

if flag(13)>60 then 'Tank Fill delay reached so (60 sec delay)
relay(3,1) 'enable tank fill relay
end if

if flag(11)=1 then 'watersensors
WaterSensors
FLAG(11)=0
print "24Hr Water usage/Limit:";Val(results(10));"/";Val(parse$(cfgdata(10),2))
If Val(results(10))>Val(parse$(cfgdata(10),2))Then
'set overuse flag
flag(10)=1
if flag(12)=0 then
SaveToFlash
flag(12)=1 'single write to flash only
end if
PReset=0 'switch to main page after pressflag period
flag(3)=1 'ensure screen update
checkbuttonpress=-1
print "checkbuttonpress:";checkbuttonpress
exit function
End If
end If

'check page presets for screen updating etc are done here
if flag(3)=1 then
select case preset
case 0
updateMain
case 1
updatecycle(1)
case 2
updatecycle(2)
case 6
updatecycle(6)
case 7
Text 5,55, "Greenhouse - Temperature " + str$(val(results(1)),3,1," ") + chr$(96)+"C Humidity:" + str$(val(results(2)),3,0," ")+ "%" ,L , 1, 1, RGB(green)
Text 5,75, "Misting Temp On:" + parse$(cfgdata(preset),3)+ chr$(96)+"C" +" Hum On:" + parse$(cfgdata(preset),4)+ chr$(96)+"C",L , 1, 1, RGB(green)
if (64 and flag(2))=64 then
Text 5,105, "Misting is On "
else
Text 5,105, "Misting is Off"
end if
case 8
Text 5,55, "Greenhouse - Temperature " + str$(val(results(1)),3,1," ") + chr$(96)+"C" ,L , 1, 1, RGB(green)
Text 5,75, "Fan Temp On:" + parse$(cfgdata(preset),3)+ chr$(96)+"C" +" Temp Off:" + parse$(cfgdata(preset),4)+ chr$(96)+"C",L , 1, 1, RGB(green)
if (128 and flag(2))=128 then
Text 5,105, "Fan is Running"
else
Text 5,105, "Fan is Off "
end if
case 3
if pin(10)=0 then
Text 5,55, "Water Reservoir is Full " ,L , 1, 1, RGB(green)
else
if pin(9)=1 then
Text 5,55, "Water Reservoir is Empty" ,L , 1, 1, RGB(green)
else
Text 5,55, "Water Reservoir is Low " ,L , 1, 1, RGB(green)
end if
end if
if (4 and flag(2))=4 then
Text 5,105, "Tank is Filling "
else
Text 5,105, " "
end if
end select
if preset=0 then showrelays
end if

'Touch pad processing
If Touch(x) <> -1 And Not keydwn Then
' we have a touch
xt = Touch(x)
yellowt = Touch(y)
' scan the array key_coord() to see if the touch was within the
' boundaries of a button
For n = startn To endn
If xt > key_coord(n,0) And xt < key_coord(n,0) + key_coord(n,2) And yellowt > key_coord(n,1) And yellowt < key_coord(n,1) + key_coord(n,3) Then
' we have a button press
' draw the button as pressed

DrawButton n, 1
keydwn = 1
Exit For
EndIf
Next n
EndIf

' if a button is currently down check if it has been released
If Touch(x) = -1 And keydwn Then
' yes, the button has been released
' draw the button as normal (ie, not pressed)
DrawButton n, 0
CheckButtonPress = n
' return with the button's number
print "checkbuttonpress:";checkbuttonpress
Exit Function
EndIf
Loop
End Function

Sub ShowRelays
Local p
local bin$="1,2,4,8,16,32,64,128"
For p=1 To 8
if (val(parse$(bin$,p)) and flag(2)) >0 then
Circle 100+p*25,10, 5, 0, 1, 0, RGB(red)
else
Circle 100+p*25,10, 5, 0, 1, 0, rgb(green)
end If
next
End Sub

'i/o EXT relay driver
sub relay(p,o)
local J
local bin$="1,2,4,8,16,32,64,128"
if p=0 then
flag(2)=0 'reset all relays and relay memory flag
else
if o=1 Then 'switch relay On
flag(2)=flag(2) or val(parse$(bin$,P)) 'add new relay
Else 'switch relay Off
flag(2)=flag(2) and (flag(2) xor val(parse$(bin$,P))) 'minus relay
end if
end if
'switch relay
SPI OPEN 500000,0,8
PIN(STRB)=0
PAUSE 1
j=SPI(Flag(2)) 'switch relays
SPI CLOSE
PIN(STRB)=1
end Sub



Codenquilts
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 07:20pm 08 Jan 2017
Copy link to clipboard 
Print this post

Looks good Mike,

How do you measure (so accurately) the tank level?

My missus is nagging me to add a gauge to the water tank out side (about 2.5m tall and 2200 lt)

Kind Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 07:30pm 08 Jan 2017
Copy link to clipboard 
Print this post

  bigmik said  
How do you measure (so accurately) the tank level?

Mick

It looks like the same way I do mine.
Waterproof/resistant ultrasonic sensor in the top of the tank.
The sensor needs to be 250-300mm above high water mark.

The sensor can give 10mm reliably which in my 20000L tanks is about 90 litres.

search for "Ultrasonic Module Distance Measuring Transducer Sensor Perfect Waterproof DC 5V" They are about $12.


My code is not as 'finished' as Mikes.

Jim


VK7JH
MMedit   MMBasic Help
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 07:48pm 08 Jan 2017
Copy link to clipboard 
Print this post

Hi Guys, Yep Jim beat me to it! Yes its all Jim's code, the water man!! I agree I get about 40ltrs resolution in my 10000ltr tanks , it can go a bit awry up at the top if you don't have that clearance Jim mentioned. I guess you would get even better resolution in your smaller (dia) tank Mick.

Mike.



Codenquilts
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 08:16pm 08 Jan 2017
Copy link to clipboard 
Print this post

Mike, Jim,

Cool! I have a cheapo PCB with a pair (was it something like HC-05) that I bought about 12mths ago when it was being talked about distance measuring but they are probably not water proof... I will look at the waterproof ones.

I would be happy with 10% steps which is 220lt so 90 lt is better than 5%. I think the fact that my tank is high and skinny is a bonus for accuracy..

25-30cm distance Minimum?? Hmm, the bottom of the overflow pipe I guess is about 150mm from the highest structural part of the tank. How wide will any `plinth' have to be so that I can raise the sensors? ie. will a bit of 90mm pipe be wide enough or should I construct a box? Also if I decide that I just mount on the top of the tank (150mm from Max water level) what would happen to the readings in the circumstance of the water being too high to measure..?? ie. Can I determine that the water is too close?? For this job I am happy to report that the tank is FULL even if I cannot measure exactly the top 150mm of water.

@Jim, Care to share your code (as all know I cant program to save my life)?

I would like to have a graph display on a 2.4" screen which shows water level in Green/Red/Yellow and a % text box.. but I might end up with a simple 10 segment display.. Anyway thanks for waking my brain from its stupor. Thinking about it a simple 10 step LED isn't too bad an idea.

Kind Regards,

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
busa
Regular Member

Joined: 12/02/2015
Location: Australia
Posts: 81
Posted: 08:25pm 08 Jan 2017
Copy link to clipboard 
Print this post

That is very impressive, good job!! Is that some loose pins I can see in the bottom left hand corner of the first pic?? If it is you might want to get them out of there, would hate to hear you had a short and ruined some of that great work.
 
MikeO
Senior Member

Joined: 11/09/2011
Location: Australia
Posts: 275
Posted: 09:15pm 08 Jan 2017
Copy link to clipboard 
Print this post

Jim I have tested down a 90mm pipe and was able to measure at 600mm quite accurately. Yes you need the waterproof (they are actually car sensors) type as you will find lots of condensation ends up on them.

Busa, Yes they were hangover from during testing, some tidying up to do! Thanks.
Codenquilts
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 09:28pm 08 Jan 2017
Copy link to clipboard 
Print this post

OK Mick
Here is my current test code.
Since the big lightning event, I have started from scratch.
Much of this code was written for the MX150 and was before Integers etc. I will change it soon
I have just purchased an Arlec remote switch so I can turn the bore pump on and off without having to remember to go down to the shed.
The pump house is not in the shed where the bore pump is controlled from so the wireless Arlec is the answer.

  Quote   ' PumpHouse
' Feb 2015
OPTION CLOCKTRIM -4
SETPIN 15, CIN
SETPIN 16, CIN
SETPIN 17, CIN
SETPIN 18, CIN

SETTICK 30000, doread ' read every 30 seconds

doread
DO
k$=
INKEY$
IF k$<>"" THEN doKey
LOOP
END

SUB doKey
DO
k$=
INKEY$
LOOP UNTIL k$=""
PAUSE 100
DoHeader
Doread
END SUB

SUB Doread
oldL1=L1
oldL2=L2
oldL3=L3
oldL4=l4
flow1=
PIN(15)
flow2=
PIN(16)
flow3=
PIN(17)
flow4=
PIN(18)
L1=scale(flow1)
' garden accumulated volume pumped since a reset.
L2=scale(flow2)' padock
L3=scale(flow3)' bore pump
L4=scale(flow4)' house water
Rate1=(L1-oldL1)* 2 ' flow rate in litres / min
Rate2=(L2-oldL2)* 2
Rate3=(L3-oldL3)*
2
Rate4=(L4-oldL4)*
2
range1 =
DISTANCE(26,24)' house tank, full = ~25.0
PAUSE 100
range2 =
DISTANCE(26,25)' garden tank, full = 29.0
vol1 = (227 - range1)*94
vol2 = (
260 - range2)*80
PRINT TIME$+","+STR$(range2,4,1," ")+","+STR$(range1,4,1," ")+","+STR$(vol2,6,0," ")+","+STR$(vol1,6,0," ")+",";
PRINT STR$(L1,8,0," ")+","+STR$(L2,8,0," ")+","+STR$(L3,8,0," ")+","+STR$(L4,8,0," ");
PRINT ","+STR$(Rate1,3,1," ")+","+STR$(Rate2,3,1," ")+","+STR$(Rate3,3,1," ")+","+STR$(Rate4,3,1," ")
'PRINT
END SUB
' end

SUB DoHeader
PRINT CHR$(13)+CHR$(10)+"Time Gdn House Gdn House Gdn Stock Bore House"
END SUB

FUNCTION scale(raw)
scale = raw/
330
DO WHILE scale > 1000000 ' keep the value within the floating point range
scale = scale - 1000000
LOOP
END FUNCTION

This code has 4 flow meters and two level sensors.
I trigger both level sensors at the same time using pin 26 and read either pin 24 or pin 25 depending on which tank I want to read.

The code simply spits out a reading every 30 seconds or an extra reading with headers if I send a CR (or anything)
The micromite is hanging of a Raspbery Pi with ser2net - a serial to telnet program so I can watch the flows from the air-conditioned lounge room.

In these lines
vol1 = (227 - range1)*94
vol2 = (260 - range2)*80
I get the depth of water by subtracting the range reading from the distance to an empty tank. 227 and 260 cm for the two tanks.
I then multiply the reading by the number of litres in 1 cm. 94 and 80 for the two tanks.
They are slightly different heights and diameters hence the different calibration figures.

My flow meters are 330 pulses per litre, the same as Mikes. I have found that really low flows are a bit out but these ebay meters are much better than the first ones I used (from Jaycar).

Because the thread is not tapered, you need a big roll of teflon tape to get a good seal.

Jim


VK7JH
MMedit   MMBasic Help
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 07:37pm 29 Jan 2017
Copy link to clipboard 
Print this post

Hi Mike, Jim, All,

Now it is well known I do not program very well at all.. BUT with MMBasic i dont need to be very good.

My distance sensor arrived today (thanks for the tip JIM) and I hooked it up and the following lines of code was all I needed to get a constant distance measurement from the unit (displayed on the console)

trig=15
echo=16

main:
d = DISTANCE(trig, echo)
? d
pause 300
goto main:


I cant believe it.. It seems to be accurate to within a cm or less and worked without any problems down to around 22cm distance where it started to get inaccurate readings and then eventually return -1.. As it should.. The specs are accurate to within 5mm down to 25cm.

Initially I intend to just have a bar graph LED (or discrete LEDs --- most likely) as the readout and press a button to read off the water level.. In my application each LED will show approx 200lt of water in the tank.. I might go to a nice SPI display but seriously for my application that is a waste of a display.

Thank you all again this has been an exciting learning exercise..

Kind Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 08:23pm 29 Jan 2017
Copy link to clipboard 
Print this post

Good to see it working for you.
(We know it's really to keep track of the level in the whisky barrel)

Jim

VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024