Skip to content

Instantly share code, notes, and snippets.

Created May 25, 2017 08:05
PICAXE Basic Program for Automatic Water Feeder Version 1.00
;
; Automatic Water Feeder
;
; Ver: 1.00
; Date: 2014.06.09
; Author: oyaji_roadrider
;
; Copyright 2014 oyaji_roadrider. All rights reserved.
;
; Function
; This system controls solenoid valve according to CdS sensor to feed water to plants.
;
#picaxe 08M2
;
; IO Port
; C.0: Serial OUT
; C.1: OUT for LED/FET
; C.2: IN for mode SW (ADC for Soil Sensor)
; C.3: IN for manual feed SW
; C.4: ADC for CdS
; C.5: Serial IN
;
; Memory Usage
; b0 (work) work
; b1 (day) day (not night) flag
; b2 (cds) CdS value
; b3 (hour) Hour counter
; b4 (key) key status
; w10 (stop_time) time to stop of water feed
;
symbol work = b0
symbol day = b1
symbol cds = b2
symbol hour = b3
symbol key = b4
symbol stop_time = w10
;
symbol yes = 1
symbol no = 0
symbol feed_duration = 60 ;water feed duration 60 sec
symbol cds_th_n2d = 50 ;CdS threshold from night to day
symbol cds_th_d2n = 100 ;CdS threshold from day to night
;
; Main Task
;
start0:
init:
pullup %00001100 ;internal pull up C.3/C.2
let day = no
let work = 0
let hour = 0
;
main:
pause 1000
let key = pins & %00001000 ;read C.3 status
if key = %00000000 then gosub feed ;manual feed switch on
if time >= 3600 then
inc hour
let time = 0
if hour = 1 and day = yes then gosub feed
let key = pins & %00000100 ;read C.2 status
if key = %00000100 then main ;twice a day mode off
if hour = 8 and day = yes then gosub feed
endif
;
debug
goto main
;
; Feed Water subroutine
feed:
suspend 1
let stop_time = time + feed_duration
high C.1 ;start water feed
do
pause 1000
let key = pins & %00001000 ;read C.3 status
if key = %00000000 then exit ;water feed process abort if manual switch pressed again
loop while time < stop_time
low C.1 ;stop water feed
resume 1
return
;
; Check day or night task
;
start1:
wait 60 ;check day or night every 60 seconds
readadc C.4, cds ;read CdS value
select case cds
case < cds_th_n2d ;enough sunny?
inc work ;count up
if work >= 3 then
if day = no then
let time = 0 ;reset timer when changeing from night to day
let hour = 0
endif
let day = yes
let work = 0
endif
case > cds_th_d2n ;enough dark?
inc work ;count up
if work >= 3 then
if day = yes then
let time = 0 ;reset timer when changeing from day to night
let hour = 0
endif
let day = no
let work = 0
endif
else
let work = 0
endselect
;
goto start1
;
;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment