This is a simple project, I thought, but I have run into trouble again.
The board has been made already so I am committed to using the pins that are in the code.
The board uses a 18M2 chip, 6 power mosfets and has 6 switched inputs and an LDR that wont be used.
I have attempted the code to use 5 soil moisture sensors with digital outputs to give the signals to the input pins.
The mosfet outputs will activate 5 small pumps to deliver water to plant pots as required.
I added a timing sequence to the 6th mosfet to enable it to be off for about an hour and then on again for about 40 seconds, this wlll power the soil moisture sensors for only short periods of time to reduce the corrosion to the sensors.
The problem that I have found is that although all parts work, the do loops hold on when one is activated and will not allow the others to be checked until it has cleared, I need all the sensors to check at the same time because of the power on state for the sensors by the 6th mosfet.
The board has been made already so I am committed to using the pins that are in the code.
The board uses a 18M2 chip, 6 power mosfets and has 6 switched inputs and an LDR that wont be used.
I have attempted the code to use 5 soil moisture sensors with digital outputs to give the signals to the input pins.
The mosfet outputs will activate 5 small pumps to deliver water to plant pots as required.
I added a timing sequence to the 6th mosfet to enable it to be off for about an hour and then on again for about 40 seconds, this wlll power the soil moisture sensors for only short periods of time to reduce the corrosion to the sensors.
The problem that I have found is that although all parts work, the do loops hold on when one is activated and will not allow the others to be checked until it has cleared, I need all the sensors to check at the same time because of the power on state for the sensors by the 6th mosfet.
Code:
; *******************************
; Written by:
; Function: Test moisture content of soild and if low turn on pump.
; Target PICAXE: 18M2
; *******************************
;Outputs
; B.0, B.1. B.2, B.3, B.4, B.5 these are all mosfets
;Inputs
; C.0, C.1, C.6, C.7, B.6, B.7 these are all switched or digital inputs
; C.2 ADC LDR input
; LDR not used in this program.
; 5 inputs to be used for soil moisture sensors with digital output.
; 5 mosfets used to control 5 pumps.
; 1 mosfet to be used to power the soil sensors at regular intervals.
; To save the corrosion of the soil sensors the sampling will be made for a short time several times a day, otherwise the power will be off to the sensor.
Main:
symbol sensor1 = C.0
symbol sensor2 = C.1
symbol sensor3 = C.7
symbol sensor4 = C.6
symbol sensor5 = B.6
; B.7 spare input
symbol pump1 = B.0
symbol pump2 = B.1
symbol pump3 = B.2
symbol pump4 = B.3
symbol pump5 = B.4
symbol sensorpower = B.5 ; switch on power to sensors when testing soil.
soiltest:
gosub powersensor
do
if pinC.0 = 0 then exit
high pump1
loop while pinC.0 = 1
low pump1
do
if pinC.1 = 0 then exit
high pump2
loop while pinC.1 = 1
low pump2
do
if pinC.7 = 0 then exit
high pump3
loop while pinC.7 = 1
low pump3
do
if pinC.6 = 0 then exit
high pump4
loop while pinC.6 = 1
low pump4
do
if pinB.6 = 0 then exit
high pump5
loop while pinB.6 = 1
low pump5
goto main
powersensor:
; NOTE values have been reduced with a ; to speed up for testing purposes
; Routine for powering soil sensors.
Low sensorpower ; sensor power is off
for b0 = 1 to 2;00 ; define loop for 200 times
pause 5;000 ; wait for 20 seconds giving total of about 1 hour before turning on again.
next b0 ; end of loop
high sensorpower ; switch on output B.5
for b1 = 1 to 2;0 ; define loop for 20 times
pause 5;00 ; wait for 2 seconds total of about 40 seconds to test for moisture content on all sensors
next b1 ; end of loop
return
Last edited: