Water Level Code Help
jom
Posts: 7
Hello Everyone,
Im currently working on a basic stamp project where I need to maintain water level at a certain set point. When the drain is opened the water valve needs to
I am using a water pressure sensor that sends 0 to 5v output depending on water level.
I also have an I/P connected to a water valve that works from 4 to 20mA.
Any Suggestions on which way I should direct my code to make this work.
Im currently working on a basic stamp project where I need to maintain water level at a certain set point. When the drain is opened the water valve needs to
I am using a water pressure sensor that sends 0 to 5v output depending on water level.
I also have an I/P connected to a water valve that works from 4 to 20mA.
Any Suggestions on which way I should direct my code to make this work.
Comments
Its always easier to get help if you tell us about what you have tried so far.
This can be in the form of code, pictures, schematics, etc and makes it much easier for us to give meaningful assistance.
In general terms, you will need to write three pieces of code:
1. read the value of the sensor. Probably will use a a/d converter.
2. send out a signal to drive the valve. Perhaps use a d/a converter.
3. a piece of code to know when the valve should go open or closed.
Cheers,
DO
IF IN3 = 0 THEN ' If 5 volt inputs
HIGH 12 ' Send Signal to I/P
ELSEIF IN3 = 1 THEN
LOW 12
It recognizes the input from the sensor when the water tank if full and sends 5v to the controller.
This is the I/P Converter im currently using:
http://www.abb.com/product/seitp330/26dbe8eacadeb6bec1256d3700451553.aspx
Similarly, your output 12 is either ON or OFF and so the I/P will be telling the valve to go full on or full off.
Now, many simple control systems will work perfectly fine with ON-OFF inputs and outputs. This is especially true of tank filling operations.
However, you might make things more responsive by doing two things:
1. use an analog/digital converter chip LTC1298, for example, so that you really can use the full range of the pressure sensor.
2. Secondly, use two or more Stamp outputs to give several discrete valve outputs. Perhaps OFF, 50% open, 75% open, Full open.
This way, the valve will slowly close as the level approaches the setpoint.
Cheers,
jorn:
'
I would use an ADC0831(analog to Digital converter) for the level input.
'StampWorks experiment #28 for an example code.
'
Heres the link to Stamp Works
http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
'
Next I would reconfigure the level transmitter to 1 to 5 volts,Not 0 to 5volts ( looks like it is a Rosemount xmitter in the jpeg)
'
5 volt = Full or upper level limit
1 volt = empty or lowest level limit.
0 volt = Fault/loop open/loop shorted/24v Power supply dead/etc.
'
Use an "IF" "THEN" "GOSUB" to test the loop condition.
" IF volt < 1 THEN GOSUB Fault
'' IF mA < 4 THEN GOSUB Fault
'''''''''ELSE ' Process the input
'
'
1 to 5 volts is relative to 4 to 20 ma.
'
With a 250ohm resister in the 24volt loop,
''With a 4ma current flow in the loop,You should read 1 volt across the 250 ohm resister."
''With a 20ma current flow in the loop,You Should read 5 volt across the 250 ohm resister."
'
'
Next You'll need a PID controller SUB routing
'''Heres a link on PID control.....Its simple math,Don't let it throw Ya!
http://en.wikipedia.org/wiki/PID_controller
'
'
I can't remember what I used to go from volts to current to drive a current device. (to drive Your I/P converter)[ DAC ? ](mAmps out)
'' I'll dig it up later,and post it.
'
'
Get the input end working good and go from there.
'''Take advantage of DEBUG .
How can I get the controller to recognize that when it reaches 5 volts as an input to stop the water valve?
I tried using
IF mVolts < 5 THEN
HIGH 15
but no luck.
Any Suggestions?
You sould not use 5 volt like that because that is at the end of the range of the ADC chip
IF result = some value THEN do something
IF result < some value AND resut > some value THEN do something
This is your best bet
Just bulletproof.
Edit: Of course you could use a PING sensor looking down to measure the distance to the surface and use that data to trip your valve. Then you could add HiFi Wifi Bluetooth...
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates reading a variable voltage with an ADC0831
' analog-to-digital converter chip. This program uses a Vref input of
' 5.000 volts (Vdd) for a bit resolution of 19.6 millivolts.
'
[ I/O Definitions ]
CS PIN 0 ' chip select (ADC0831.1)
Clock PIN 1 ' clock (ADC0831.7)
DataIn PIN 2 ' data (ADC0831.6)
'
[ Constants ]
Cnts2Mv CON $139C ' x 19.6 (to millivolts)
'
[ Variables ]
result VAR Byte ' result of conversion
mVolts VAR Word ' millivolts
v VAR Byte
n VAR Word
FOR n = 1 TO 199 STEP 9
PWM 4, n, 40
NEXT
GOSUB reset
GOSUB Main
'GOSUB Valve
GOSUB Display
'
[ Initialization ]
Reset:
DEBUG CLS, ' create report screen
"ADC.... ", CR,
"volts... "
'
[ Program Code ]
Main:
DO
GOSUB Read_0831 ' read the ADC
mVolts = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts DIG 3,
".", DEC3 mVolts
PAUSE 100
GOSUB Valve
LOOP
'
[ Subroutines ]
Read_0831:
LOW CS ' enable ADC
SHIFTIN DataIn, Clock, MSBPOST, [result\9] ' read ADC
HIGH CS ' disable ADC
RETURN
Valve:
v = 5 * result / 255
IF(v = 0)THEN
PWM 8, 100, 40
IF (v > 0) THEN PWM 8,255,40
ENDIF
RETURN
v = result / 255 ?
Have You check the voltage from the level sensor with the tank full at the ADC to see if it is 5volts?
'
If not you just need to calibrate the level senor loop.
'
You could increase the voltage into the senor to achieve 5volts at the ADC or just add and offset in Your software.
'
v = 5 * result / 255 + offset
Voltage started changing but with an input of 5 volt it never reaches and output 5 volts.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates reading a variable voltage with an ADC0831
' analog-to-digital converter chip. This program uses a Vref input of
' 5.000 volts (Vdd) for a bit resolution of 19.6 millivolts.
'
[ I/O Definitions ]
CS PIN 0 ' chip select (ADC0831.1)
Clock PIN 1 ' clock (ADC0831.7)
DataIn PIN 2 ' data (ADC0831.6)
'
[ Constants ]
Cnts2Mv CON $139C ' x 19.6 (to millivolts)
'
[ Variables ]
result VAR Byte ' result of conversion
mVolts VAR Word ' millivolts
v VAR Byte
n VAR Word
GOSUB reset
GOSUB Main
'GOSUB Valve
'
[ Initialization ]
Reset:
DEBUG CLS, ' create report screen
"ADC.... ", CR,
"volts... "
'
[ Program Code ]
Main:
DO
GOSUB Read_0831 ' read the ADC
mVolts = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts DIG 3,
".", DEC3 mVolts
PAUSE 100
GOSUB Valve
LOOP
'
[ Subroutines ]
Read_0831:
LOW CS ' enable ADC
SHIFTIN DataIn, Clock, MSBPOST, [result\9] ' read ADC
HIGH CS ' disable ADC
RETURN
Valve:
v = result / 255
IF(v > 0 AND v < 1) THEN PWM 8 ,51,40
IF (v > 1 AND v< 2) THEN PWM 8, 77, 40
IF (v > 2 AND v< 3) THEN PWM 8,102,40
IF (v >3 AND v< 4)THEN PWM 8, 153, 40
IF (v >4 AND v< 5) THEN PWM 8, 204, 40
IF ( v = 5) THEN
PWM 8 , 255, 40
ENDIF
RETURN
Im using an LM358 in the output.
Are You still using the Rosemount DP transmitter for the level senor?
If so,Have You set the zero and span in the transmitter to match the tank levels?