-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAirConditioning.ino
190 lines (167 loc) · 4.49 KB
/
AirConditioning.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
/*
AUTOMATION TURN ON/OFF SYSTEM FOLLOW TEMPERATURE FOR DAIKIN AIR CONDITIONING
Author: namdothanh ([email protected])
Date: 5/2017
Hardware:
+ Arduino Uno Rev3
+ DS18B20 sensor
+ IR Transmit LED
Software: Arduino IDE
*/
#include <IRremote.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/* SYSTEM STATUS (FSM) */
#define STATUS_OFF 0
#define STATUS_ON 1
int status = STATUS_OFF; // Warning: Default status is OFF
const double TEMP_TURN_ON = 33.0f;
const double TEMP_TURN_OFF = 28.0f;
/* IR REMOTE SENDER */
const int PIN_SEND_IR = 3; //Default
IRsend irsend;
/* DAIKIN CONDITION AIR - 64 bit*/
static const unsigned int DAIKIN_CONDITION_POWER_RAW[] = {
9800, 9800, 9800, 9800,
4640, 2540,
390, 390, //0
390, 925, //1
390, 925, //1
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 925, //1
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 390, //0
390, 925, //1
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 390, //0
390, 925, //1
390, 925, //1
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 925, //1
390, 925, //1
390, 925, //1
390, 390, //0
390, 390, //0
390, 925, //1
390, 390, //0
390, 20200,
4640};
/* DS18B20 Sensor */
#define NUMBER_MEASURE_TEMP 10
#define ONE_WIRE_BUS 2 // Data wire is plugged into port 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
void pressPowerKey() {
irsend.sendRaw( DAIKIN_CONDITION_POWER_RAW,
sizeof(DAIKIN_CONDITION_POWER_RAW)/sizeof(unsigned int),
38 /* kHz */);
delay(1000);
}
double measureTemperature() {
double temp = 0.0f;
for(int i=0; i < NUMBER_MEASURE_TEMP; ++i) {
sensors.requestTemperatures(); // Send the command to get temperatures
temp += sensors.getTempCByIndex(0);
}
temp /= NUMBER_MEASURE_TEMP;
Serial.print("Temperature = ");
Serial.print(temp);
Serial.println(" (C)");
//if met an error with ds18b20 sensor, alway turn off condition air
//if(temp <= DEVICE_DISCONNECTED_C /* -127 */) {
if((temp < 15) || (temp > 45)) {
Serial.println("DS18B20 sensor is disconnected or error.");
return (TEMP_TURN_OFF - 1);
}
return temp;
}
void processSystem() {
switch(status) {
case STATUS_OFF:
if(measureTemperature() > TEMP_TURN_ON) {
pressPowerKey();
status = STATUS_ON;
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Action: Turn on");
}
break;
case STATUS_ON:
if(measureTemperature() < TEMP_TURN_OFF) {
pressPowerKey();
status = STATUS_OFF;
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Action: Turn off");
}
break;
default:
break;
};
if(status == STATUS_ON) {
Serial.println("Status: ON");
}
else {
Serial.println("Status: OFF");
}
}
void setup() {
//start Serial port
Serial.begin(115200);
Serial.println("------------------------------------------------------\r\n"
"Automation Turn On/Off System for DAIKIN Air Conditioning");
//start LED indicator
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// Start up the DS18b20 & Onewire library
sensors.begin();
sensors.setResolution(12);
}
void loop() {
//transmit uart
Serial.println("......");
//process system
processSystem();
}