-
Notifications
You must be signed in to change notification settings - Fork 0
/
12HourApplication.py
executable file
·108 lines (89 loc) · 3.24 KB
/
12HourApplication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
import Phototransistor, Thermistor, Tensiometer
import RPi.GPIO as GPIO
import time
###########################
#12 HOUR APPLICATION
###########################
phototransPIN = 0;
thermistorPIN = 2;
tensiometerPIN = 4;
lightRELAY = 17
fanRELAY = 21#either 21, or 27; revision 1/2 respectivley
pumpRELAY = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup(lightRELAY, GPIO.OUT)
GPIO.setup(fanRELAY, GPIO.OUT)
GPIO.setup(pumpRELAY, GPIO.OUT)
#INITIALLY SET TO FALSE
GPIO.output(lightRELAY, False)
GPIO.output(fanRELAY, False)
GPIO.output(pumpRELAY, False)
#range of 0 to 240 lasts roughly 3 minutes
#half second delay on each relay setting change
#for watering, roughly estimate time intervals using variable 'i'
for i in range(0, 43200):
#################
#VALUES FOR LIGHT CONTROL
#print "Reading Phototransistor..."
phototransValue = sensorFunctions.readPhototransistor(phototransPIN)
#convert to lumens
lumens = sensorFunctions.convertToLumens(phototransValue)
print "Lumens: ", lumens, " ANALOG VALUE: ", phototransValue
#################
#VALUES FOR FAN CONTROL
#print "Reading Thermistor..."
thermistorValue = thermistorFunctions.readThermistor(thermistorPIN)
#convert to fahrenheit and celsius
temp_C = thermistorFunctions.convertToC(thermistorValue)
temp_F = thermistorFunctions.convertToF(thermistorValue)
print"Temperature in C: ", temp_C, " Temperature in F: ", temp_F, " ANALOG VALUE: ", thermistorValue
#################
#VALUES FOR PUMP CONTROL
#print "Reading Tensiometer..."
humidity = sensorFunctions.readTensiometer(tensiometerPIN)
print "RAW Tensiometer Reading: ", humidity
################
#RELAY CONTROL
################
#is greater than 700, turn on light relay
if (lumens < 700):
print "##################"
print "ERROR 1"
print "NOT ENOUGH LIGHT, TURNING ON LIGHTS"
print "##################"
GPIO.output(lightRELAY, True)
elif (lumens >700):
GPIO.output(lightRELAY, False)
#temperature above roughly 75F (NEEDS TUNING), turn on fan
if (temp_F > 75):
print "##################"
print "ERROR 2"
print "TEMPERATURE HOTTER THAN 75F, TURNING ON FAN"
print "##################"
GPIO.output(fanRELAY, True)
elif (temp_F < 72):
GPIO.output(fanRELAY, False)
#check analog values, at roughly 170 equals full conductivity/highest humidity
if (humidity < 50):
print "#################"
print "ERROR 3"
print "SOIL IS DRY, ACTIVATING WATER PUMP"
print "#################"
GPIO.output(pumpRELAY, True)
elif (humidity > 50):
GPIO.output(pumpRELAY, False)
#time keeping variables
timeElapsedHour = i/3600
timeElapsedMin = i/60
timeElapsedSec = i
#formatting for time
if (timeElapsedSec>=60):
timeElapsedSec= timeElapsedSec - (timeElapsedMin*60)
if (timeElapsedMin>=60):
timeElapsedMin= timeElapsedMin - (timeElapsedHour*60)
#delay for timekeeping, line breaks for formatting on terminal
print "Time Elapsed : ", timeElapsedHour, ":", timeElapsedMin,":", timeElapsedSec
print ""
print ""
time.sleep(1.0)