08M Christmas tree watering controller

KMoffett

Senior Member
I've been using Velleman K2639 Liquid Level Control kits for Hi/Lo level water pumps controllers: http://www.vellemanusa.com/us/enu/product/view/?id=350507
I've used these in roof drain sumps for "Green Roof" vs "Non-Green Roof" rain-runoff measurements, and they worked very well.

I was going to use one for an automated Christmas tree stand watering system. This was to replace my old, unreliable, float-switch (home brew) system. I've been thinking that this could be a good PICAXE 08M project. I used their concept of AC driven level sensor electrodes, that I've also seen in other designs. The common electrode was driven by an oscillator, through a DC blocking capacitor. The two sense electrodes detect the AC signal through the water and drive capacitor-coupled voltage-doublers to opamps and logic.

For the PICAXE design I drove the common electrode with a 50/50 50KHz PWM output through a capacitor and resistor. The sense electrodes, through two voltage-doublers, drive two ADC inputs. The output drives the LED in an SSR, to control a 120VAC pump.

I have not assembled it, except for the sensor probe, but the bench test gave me very satisfactory results. The output of the voltage-doublers was ~0.4vdc to ~3vdc, depending on depth of the electrode in contact with tap water.

Code:
'Picaxe 08M two-level-water-control-09.bas
'Ken Moffett 4/20/2009
'Pump starts when water is below lower sensor
'Pump will run until water is above the upper sensor.
'Pump will remain off until water is below lower sensor
'output 0 (leg 7) is pump driver
'input 1 (leg 6) is low level sense
'output 2 (leg 5) is sensor driver
'input 4 (leg 3) is high level sense


pwmout 2,19,40				'PWM output 50KHz@50%
low 0						'turn pump off


main:
b2=0						'0=empty, 1=not empty
b3=0						'0=not filled, 1=filled
readadc 1,b0				'read voltage at lower level probe
if b0 > 25 then gosub notempty	'<26 is empty	
readadc 4,b1				'read voltage at upper level probe
if b1 > 25 then gosub full		'>25 is full
if b2=0 and b3=0 then goto pumpon	'empty
if b3=1 then goto pumpoff		'full
goto main

notempty:					
	b2=b2+1				'increment level
	return
full:				
	b3=1					'indicate full
	return	
pumpon:					
	high 0				'turn on pump
	goto main
pumpoff:					
	low 0					'turn off pump
	goto main
Ken
 

Attachments

rWAVE

Member
How About Soil Moisture?

Was wondering how well this might work as a soil moisture sensor? Commercial units, such as Vegetronix (too expensive at $29.99) and WaterStik (too expensive at $14.95) are both based on "transmission line" techniques, which look good, but the price is too high for my needs as I would need many units. The WaterStik may be hackable, however.

Using your inexpensive approach, I was thinking about using a pair of parallel, equal length stainless steel rods. If the sensor lasted a couple of years before replacement, that would work for me.

It's the media that is the unknown. Whereas transmission line approaches should work on any media without the need for sensor calibration, I'm not so sure about this PWM approach using various "dirt" blends. And for my hydroponics systems, various media such as perlite/coco fiber and hydroton may prove problematic. I would really like to avoid a unique calibration for each media blend.

Any thoughts?

Richard
 

MPep

Senior Member
Another version

Hi Ken,

No criticism to your efforts, but after reading your code, I thought that there must be an easier way. I modified your code to the following:
Code:
#rem
Picaxe 08M two-level-water-control-09.bas
Ken Moffett, 20 April 2009
Pump starts when water is below lower sensor
Pump will run until water is above the upper sensor.
Pump will remain off until water is below lower sensor
output 0 (leg 7) is pump driver
input 1 (leg 6) is low level sense
output 2 (leg 5) is sensor driver
input 4 (leg 3) is high level sense
#endrem
symbol pump = 0
symbol LowSensor = 1
symbol HighSensor = 4
symbol LSval = b0
symbol HSval = b1
#picaxe 08m 
low 0      'turn pump off
pwmout 2,19,40    'PWM output [EMAIL="50kHz@50%"]50kHz@50%[/EMAIL]
main:
 readadc LowSensor,LSval  'read voltage at lower level probe
 
 readadc HighSensor,HSval 'read voltage at upper level probe
 if LSval < 25 then PumpOn
 if HSval > 25 then PumpOff
goto main

PumpOn:     
 high pump    'turn on pump
 goto main  
PumpOff:     
 low pump    'turn off pump
 goto main
Only uses 32 bytes (vs 59 bytes). Does this work for you? Just a thought.
Thanks for sharing your code with us.

MPep
 

KMoffett

Senior Member
Sorry for the long time to get back. I used to get notified fo additions to subscribed posts, but that seems to have stopped. ?????

Thanks for the rewrite. Programming is not my strong suit. It's always interesting to see how many different ways you can accomplish the same task.

Ken
 
Last edited:

MPep

Senior Member
Hi Ken,

I like your use of PWM to generate AC, and then the use of charge-pumps to detect the level. Simple, straight-forward.
Neat job of sensor.

Well done.
 

KMoffett

Senior Member
I modified my original circuit and code.

1. I incorporated the simplifications suggested by MPep. (thanks again!)

2. I was getting some intermittent switching on the sense lines, that I traced to capacitive coupling between the drive wire and the sense wires inside the the cable. It was just a 3-wire cable with no shielding. This was producing a small, constant DC level on my sense inputs, even without touching the water. The PWM signal was reduced from 50KHz to 4KHz, which significantly reduced the DC signal. Also the ADC switchover levels were increased from 25 to 50. Problem solved.

3. The sensor probe was connected to the control box with an 1/8" stereo plug/jack. When the plug was inadvertently, partially pulled, the controller kept pumping. :( The jack was changed to one with switch-over contacts, and another voltage doubler was added between the jack's tip switch contact and the unused input 3 (when do you ever have a spare I/O on an 08M. ;) ). If the plug is pulled the sensor drive line is connected directly to pin 3's voltage doubler. An interrupt routine was inserted, so a high on pin 3 would kill the pump.

Ken

Code:
#rem
Picaxe 08M two-level-water-control-11.bas
Ken Moffett, 31 Dec 2009
Pump starts when water is below lower sensor
Pump will run until water is above the upper sensor.
Pump will remain off until water is below lower sensor
Pump will stop if the sensor plug is partially or compleatly pulled out
output 0 (leg 7) is pump driver
input 1 (leg 6) is low level sense
output 2 (leg 5) is sensor driver
input 3 (leg 4) is plug disconnect sense
input 4 (leg 3) is high level sense
#endrem

symbol pump = 0
symbol LowSensor = 1
symbol HighSensor = 4
symbol LSval = b0
symbol HSval = b1

#picaxe 08m 

low pump      				'turn pump off
pwmout 2,249,500    			'PWM output 4kHz@50% to sensor driver probe
setint %00001000,%00001000		'Check pin 3 for unplugged sensor

Main:
	readadc LowSensor,LSval  	'read voltage at lower level probe 
	readadc HighSensor,HSval 	'read voltage at upper level probe
	if LSval < 50 then PumpOn	'water is below lower probe
	if HSval > 50 then PumpOff	'water is above upper probe
	goto main

PumpOn:     
	high pump    			'turn on pump
	goto main
	
PumpOff:     
	low pump    			'turn off pump
	goto main
	
Interrupt:					'Sensor plug disconnected
	low pump				'turn off pump
	if pin3 = 1 then interrupt 	'loop here until the interupt clears
	setint %00001000,%00001000	're-activate interrupt
	return				'return from sub
Thought I might as well throw in the PCB layout (ExpressPCB) too. For small one-offs I do the layout on 0.1" grid, then just do a perfboard with point-to point wiring with #30 Kynar wire-wrap wire. Their schematic-to-PCB links makes verifying the layout easier.
 

Attachments

Last edited:

lbenson

Senior Member
Nice update, Ken. Regarding the ExpressPCB PCB, did you draw in the .1" tic marks or is there a way to generate them automatically?
 

KMoffett

Senior Member
The 0.1" tick marks are automatic in the program. If you change the background and the tick mark colors, or any of the others, to anything you like. The ruler is just a component I made to keep track of sizes and locations.

Ken
 

MPep

Senior Member
Hi Ken,

Well done on the re-re-write :D!
Just one thought has occured, how do you know when the sensor is out of circuit?

You have switched the Pump Off, which saves mopping up water off the carpet, but the tree will not last as long, until you realise that the pump hasn't worked for some time.

You could use the 'HighSensor' input to output to a small siren alerting you to the fact.
As the chargepump has a diode connected to Pin4, you can set it to be be an output without upsetting the probe.

Using a self-oscillating siren (one that only requires DC applied) is the easiest way to go.
I realise that this may load the ADC input as there is now an extra load in parallel with the 100kR.
Maybe using a 4013 FlipFlop setup in toggle mode and have the output drive the siren. This way a "pulse out" could be used. And another to switch the siren off again.
As the input to a 4013 is high impedance, no extra (or at least not much) loading is present on the ADC input.

Just a thought.

Code that inludes my suggestion.
Code:
#rem

Picaxe 08M two-level-water-control-11.bas
Ken Moffett, 31 Dec 2009

Extra code inserted by MPep, 3 Jan 2010

Pump starts when water is below lower sensor
Pump will run until water is above the upper sensor.
Pump will remain off until water is below lower sensor
Pump will stop if the sensor plug is partially or completely pulled out

output 0 (leg 7) is pump driver
input 1 (leg 6) is low level sense
output 2 (leg 5) is sensor driver
input 3 (leg 4) is plug disconnect sense
input 4 (leg 3) is high level sense

#endrem

symbol pump = 0
symbol LowSensor = 1
symbol HighSensor = 4
symbol LSval = b0
symbol HSval = b1

#picaxe 08m 

low pump                      'turn pump off
pwmout 2,249,500                'PWM output 4kHz@50% to sensor driver probe
setint %00001000,%00001000        'Check pin 3 for unplugged sensor

Main:
    readadc LowSensor,LSval      'read voltage at lower level probe 
    readadc HighSensor,HSval     'read voltage at upper level probe
    if LSval < 50 then PumpOn    'water is below lower probe
    if HSval > 50 then PumpOff    'water is above upper probe
    goto main

PumpOn:     
    high pump                'turn on pump
    goto main
    
PumpOff:     
    low pump                'turn off pump
    goto main
    
Interrupt:                    'Sensor plug disconnected
    low pump                'turn off pump
    pulsout 4,1000            'Toggle the Alert Siren On(should be off)
CheckPin:
    if pin3 = 1 then CheckPin     'loop here until the interupt clears
    pulsout 4,1000            'Toggle the Alert Siren Off
    setint %00001000,%00001000    're-activate interrupt
    return
 
Last edited:

KMoffett

Senior Member
I'd thought about that too, but let it slide because I didn't have another output, and wasn't feeling very inspired. ;) But, now that you mention it I can see how important it would to the shut-down function. So, I bench tested an option. Add a 100K resistor from P3, to the base of a 2N4401 NPN transistor driver for a Sonalert to +5V. Change the capacitor (C6) on the input P3 to from 0.1uF to 1.0uF, to reduce ripple under the slightly higher load. It works! And no need to change the program at all.

Thanks MPep, for you contributions to the New!...And!....Improved!...Computer Controlled, MARK III, Automated Christmas Tree Stand Watering System. :)

Ken
 

Attachments

Last edited:

MPep

Senior Member
Hi Ken,

Am pleased to read that. A simple solution is usually best. Well done :).

MPep.

Note:
Realistically, I am kicking myself for overlooking the obvious!!!
 
Last edited:

JPU

Senior Member
Hi

It's probably a daft question but can someone tell me what JP1 on the schematic is please.

Thanks.
 

MPep

Senior Member
JP1 is a jumper required for the cicuit board that KMoffett made. It 'jumps' over another trace.
Schematically, it is not required to be there. Only there for clarification of the components on the physical board. :)

Hope this helps.
 
Top