-
Notifications
You must be signed in to change notification settings - Fork 3
/
arduino code.txt
114 lines (103 loc) · 2.03 KB
/
arduino code.txt
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
/* FYP2017
* Arduino code to send room conditions to pi via zigbee
* Command HVAC elements based on commands sent from pi via zigbee
* Author: Kunal Jagadeesh
* License: Public Domain
*/
#include <SoftwareSerial.h>
#include "DHT.h"
/* Connections
* Connect DHT22 data pin to pin 2
* Connect cooler vcc to pin 5
* Connect heater vcc to pin 7
* Connect humidifier vcc to pin 9
* Connect exhaust vcc to pin 11
* Make common ground
*/
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int cooler = 5;
int heater = 7;
int humidifier = 9;
int exhaust = 11;
SoftwareSerial Xbee(0,1);
void setup()
{
pinMode(cooler, OUTPUT);
pinMode(heater, OUTPUT);
pinMode(humidifier, OUTPUT);
pinMode(exhaust, OUTPUT);
dht.begin();
Serial.begin(9600);
Xbee.begin(9600);
}
void loop()
{
if(Xbee.available())
{
char ch = Xbee.read();
switch(ch)
{
case 's':
sendSensorData();
break;
case 'c':
run_cooler();
break;
case 'f':
run_heater();
break;
case 'h':
run_humidifier();
break;
case 'e':
run_exhaust();
break;
}
}
}
void sendSensorData()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(h);
Serial.println(t);
}
void run_cooler()
{
if (digitalRead(heater) == HIGH)
{
digitalWrite(heater, LOW);
delay(500);
}
digitalWrite(cooler, HIGH);
delay(500);
}
void run_heater()
{
digitalWrite(cooler, HIGH);
delay(500);
digitalWrite(heater, HIGH); /*both heater and fan should run for this case*/
delay(500);
}
void run_humidifier()
{
if(digitalRead(exhaust) == HIGH)
{
digitalWrite(exhaust, LOW);
delay(500);
}
digitalWrite(humidifier, HIGH);
delay(500);
}
void run_exhaust()
{
if(digitalRead(humidifier) == HIGH)
{
digitalWrite(humidifier, LOW);
delay(500);
}
digitalWrite(exhaust, HIGH);
delay(500);
}