-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUP.ino
192 lines (163 loc) · 4.38 KB
/
SUP.ino
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// assign each component to a pin
int buton = 12;
int led_r = 8; // if its too hot red led light up
int led_y = 9; // if its too dark yellow led light up
int led_g = 10; // if theres too much moisture led green light up
int sen_ldr = A0; // sensor of light dependent resistor
int sen_temp = A1; // sensor of temperature
// sensor value
int sv_temp = 0;
int sv_ldr = 0;
#include <LiquidCrystal.h>
const int rs = 13, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // set up for lcd display
#include<CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(3, 2); // set up for moisture sensor
// refrence value
int ref_temp = 25; // reference value to temp
int ref_ldr = 70; // reference value to ldr
int ref_mstr = 1000; // reference to moisture sensor
// lable modes
int crt_dis = 0; //whats currently being displayed (1 = temp, 2 = light, 3 = moisture)
int buton_stat = 0; // what the stat of button
int rled_r; // read LED of Red
int rled_y; // read LED of Yellow
int rled_g; // read LED of Green
void setup()
{
pinMode(led_r, OUTPUT);
pinMode(led_y, OUTPUT);
pinMode(led_g, OUTPUT);
pinMode(buton, INPUT);
Serial.begin(9600);
lcd.begin(6, 2);
lcd.clear();
lcd.print("Press Button to ");
lcd.setCursor(5, 2);
lcd.print("Start");
delay(500);
}
void loop()
{
// reading the value in sensors
sv_temp = analogRead(sen_temp);
sv_ldr = analogRead(sen_ldr);
buton_stat = digitalRead(buton);
long sv_mstr = capSensor.capacitiveSensor(30); // moisture sensor
// intput to tempreture
float vol = ( sv_temp / 1024.0 ) * 5.0;
float temp = ( vol - .5) * 100;
// what to display in the serial monintor
Serial.print("Temp = ");
Serial.println(temp);
Serial.print("Light = ");
Serial.println(sv_ldr);
Serial.print("Mosture = ");
Serial.println(sv_mstr);
// what heppen if button is pressed
if (buton_stat == HIGH)
{
crt_dis ++;
delay (500);
Serial.println ("button is High");
} else {
Serial.println ("button is Low");
}
// What to display in the top row of lcd
if (crt_dis == 1)
{
lcd.clear();
lcd.print ("Temp: ");
lcd.print (temp);
Serial.println ("LCD = Temp");
}
if (crt_dis == 2)
{
lcd.clear();
lcd.print ("Light: ");
lcd.print (sv_ldr);
Serial.println ("LCD = Light");
}
if (crt_dis == 3)
{
lcd.clear();
lcd.print ("Moist: ");
lcd.print (sv_mstr);
Serial.println ("LCD = Mousture");
}
if (crt_dis >= 4)
{
crt_dis = 1;
}
Serial.print ("Current display = ");
Serial.println (crt_dis);
// When does LED lights up
if (temp > ref_temp)
{
digitalWrite(led_r, HIGH);
} else {
digitalWrite(led_r, LOW);
}
if (sv_ldr < ref_ldr)
{
digitalWrite(led_y, HIGH);
} else {
digitalWrite(led_y, LOW);
}
if (sv_mstr > ref_mstr)
{
digitalWrite(led_g, HIGH);
} else {
digitalWrite(led_g, LOW);
}
// Read Value of LED (weather if its on or not
rled_r = digitalRead(led_r);
rled_g = digitalRead(led_g);
rled_y = digitalRead(led_y);
Serial.print ("LED RED = ");
Serial.println (rled_r);
Serial.print ("LED Yellow = ");
Serial.println (rled_y);
Serial.print ("LED Green = ");
Serial.println (rled_g);
// when deos lcd display "led on" or "led off"
if (rled_r == HIGH and rled_y == HIGH and rled_g == HIGH)
{
lcd.setCursor(0,2);
lcd.print("all LED is ON");
Serial.print("LCD Dis (all LED ON)");
} else if (rled_y == HIGH and rled_g == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("Y & G LED Is On");
Serial.print("LCD Dis (Yellow and Green LED ON)");
} else if (rled_y == HIGH and rled_r == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("Y & R LED is On");
Serial.print("LCD Dis (Yellow and Red LED ON)");
} else if (rled_g == HIGH and rled_r == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("G & R LED is On");
Serial.print("LCD Dis (Yellow and Red LED ON)");
} else if (rled_r == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("Red LED is On");
Serial.print("LCD Dis (Red LED ON)");
} else if (rled_g == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("Green LED is On");
Serial.print("LCD Dis (Green LED ON)");
} else if (rled_y == HIGH)
{
lcd.setCursor(0, 2);
lcd.print("Yellow LED is On");
Serial.print("LCD Dis (Yellow LED ON)");
}
// Enter 2 Blanks to consol to show time line
Serial.println();
Serial.println();
}