-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreenhouse_automation.ino
87 lines (72 loc) · 1.55 KB
/
greenhouse_automation.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
#include <DHT.h>
#define Type DHT11
int DHTPin = 2;
DHT HT(DHTPin, Type);
float humidity;
float tempC;
float tempF;
int redPin = 10;
int LDRPin = A0;
float lightVal;
int yellowPin = 12;
int mPin = A2;
float mValue;
int bluePin = 11;
int delayTime = 500;
int setTime = 500;
void setup() {
Serial.begin(9600);
pinMode(LDRPin, INPUT);
pinMode(mPin, INPUT);
pinMode(yellowPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
HT.begin();
delay(setTime);
}
void lightControl(int Llimit) {
lightVal = analogRead(LDRPin);
lightVal = (lightVal)*100.0/1023.0;
if (lightVal < Llimit) {
digitalWrite(yellowPin, HIGH);
} else {
digitalWrite(yellowPin, LOW);
}
delay(delayTime);
}
void airControl(int Hlimit,int Tlimit) {
humidity = HT.readHumidity();
tempC = HT.readTemperature();
tempF = HT.readTemperature(true);
if (tempC > Tlimit) {
digitalWrite(redPin, HIGH);
} else {
digitalWrite(redPin, LOW);
}
delay(delayTime);
}
void waterControl(int Wlimit) {
mValue = analogRead(mPin); //1011 - 250 -> 0 - 100
mValue = 120 - 0.116*mValue; //formula depends on location (chennai)
if (mValue < 50) {
digitalWrite(bluePin, HIGH);
} else {
digitalWrite(bluePin, LOW);
}
delay(delayTime);
}
void loop() {
lightControl(20);
airControl(40,30);
waterControl(50);
Serial.print(lightVal);
Serial.print(" ");
Serial.print(humidity);
Serial.print(" ");
Serial.print(tempC);
Serial.print(" ");
Serial.print(tempF);
Serial.print(" ");
Serial.print(mValue);
Serial.println(" ");
}