Long time no squeak!
So I decided to build an automation project for work. Mainly because I'm sick of seeing the water tank overflow and its a pain in the butt when it runs out.
The goal is to monitor a tanks water level using a sensor with a 4-20ma output. use this data to control a valve, send tank level in a percentage, valve state and trigger an alarm if the tank is not filling while the valve is open.
I am using a pair of HC-12's for communication
a simple LCD with a picaxe serial backpack
an "off the shelf " relay board to run the valve
The water sensor is a bit flash but its work supplied and runs 4-20ma
not sure if i go the 250ohm route and get 1-5v or go with a "ti RCV420jp" and get full 0-5v
I have written code that works and does what its meant to do. But I need some help with it.
So I readadc10 of a pin into w0 run it through a few if statements then bintoascii to send it to the hc-12 and out.
i need to set a 0% and 100% range in the coding and have it display as a percentage. at the moment I'm using a 10k pot to simulate the signal for testing so i can run the full range.
Here is the code for you to have a read through. I am still quite green to all this so if you can suggest or see any areas of improvement they would be well recived.
So I decided to build an automation project for work. Mainly because I'm sick of seeing the water tank overflow and its a pain in the butt when it runs out.
The goal is to monitor a tanks water level using a sensor with a 4-20ma output. use this data to control a valve, send tank level in a percentage, valve state and trigger an alarm if the tank is not filling while the valve is open.
I am using a pair of HC-12's for communication
a simple LCD with a picaxe serial backpack
an "off the shelf " relay board to run the valve
The water sensor is a bit flash but its work supplied and runs 4-20ma
not sure if i go the 250ohm route and get 1-5v or go with a "ti RCV420jp" and get full 0-5v
I have written code that works and does what its meant to do. But I need some help with it.
So I readadc10 of a pin into w0 run it through a few if statements then bintoascii to send it to the hc-12 and out.
i need to set a 0% and 100% range in the coding and have it display as a percentage. at the moment I'm using a 10k pot to simulate the signal for testing so i can run the full range.
Here is the code for you to have a read through. I am still quite green to all this so if you can suggest or see any areas of improvement they would be well recived.
Code:
TANK UNIT
#picaxe 08m2
;symbol spare = C.0
symbol tx = C.1
symbol level = C.2
;symbol spare = C.3
symbol valve = C.4
;symbol spare = C.5
Init:
Low valve
Main:
readadc10 Level,w0
bintoascii w0, b2,b3,b4,b5,b6
if w0 > 1000 then
low valve
b10 = 0
end if
if w0 < 500 then
high valve
b10 = 1
end if
if w0 > 400 then
b11 = 0
end if
If w0 < 400 then
b11 = 1
end if
serout tx,t2400,("AAA",b3,b4,b5,b6,b10,b11)
goto main
Code:
LCD DISPLAY
#picaxe 08m2
;symbol spare = C.0
symbol tx = C.1
symbol lcd = C.2
;symbol spare = C.3
symbol alarm = C.4
;symbol spare = C.5
Init:
Pause 500
serout lcd,n2400,(254,1)
pause 30
serout lcd,n2400,(254,128)
serout lcd,n2400,(" No Link ")
low alarm
Startup:
serin tx,t2400,("AAA")
serout lcd,n2400,(254,1)
pause 30
Main:
serin [500,Init], tx,t2400,("AAA"),b3,b4,b5,b6,b10,b11
if b11 = 0 then
low alarm
end if
If b11 = 1 then
high alarm
end if
if b10 = 0 then
goto Closed
end if
If b10 = 1 then
goto Open
end if
Open:
serout lcd,n2400,(254,128)
serout lcd,n2400,("Tank Level:%",b3,b4,b5,b6)
serout lcd,n2400,(254,192)
serout lcd,n2400,("Valve: Open ")
goto main
Closed:
serout lcd,n2400,(254,128)
serout lcd,n2400,("Tank Level:%",b3,b4,b5,b6)
serout lcd,n2400,(254,192)
serout lcd,n2400,("Valve: Closed ")
goto main