-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHob2Hood.ino
310 lines (251 loc) · 7.31 KB
/
Hob2Hood.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include <IRremote.h>
/*
Siehe: http://knx-user-forum.de/forum/%C3%B6ffentlicher-bereich/knx-eib-forum/diy-do-it-yourself/37790-hob2hood-ir-protokoll-arduino/page2
Lüftung Stufe1 0xE3C01BE2
Lüftung Stufe2 0xD051C301
Lüftung Stufe3 0xC22FFFD7
Lüftung Stufe4 0xB9121B29
Lüftung Aus 0x55303A3
Licht An 0xE208293C
Licht Aus 0x24ACF947
*/
// IR commands from AEG hob2hood device
const long IRCMD_VENT_1 = 0xE3C01BE2;
const long IRCMD_VENT_2 = 0xD051C301;
const long IRCMD_VENT_3 = 0xC22FFFD7;
const long IRCMD_VENT_4 = 0xB9121B29;
const long IRCMD_VENT_OFF = 0x55303A3;
const long IRCMD_LIGHT_ON = 0xE208293C;
const long IRCMD_LIGHT_OFF = 0x24ACF947;
// Pins for input switches/controls for manual control of the hood
const int PIN_IN_VENT_1 = A0;
const int PIN_IN_VENT_2 = A1;
const int PIN_IN_VENT_3 = A2;
const int PIN_IN_VENT_4 = A3;
const int PIN_IN_LIGHT = A4;
// Pins for the output which controls relais which finally control the hood
const int PIN_OUT_VENT_1 = 2;
const int PIN_OUT_VENT_2 = 3;
const int PIN_OUT_VENT_3 = 4; // war: 4
const int PIN_OUT_VENT_4 = 5;
const int PIN_OUT_LIGHT = 6; // war: 6
const int PIN_OUT_EXT1 = 7;
const int PIN_OUT_EXT2 = 8;
const int PIN_OUT_EXT3 = 9;
// IR Receiver PIN
const int PIN_IR_RECEIVER = 11;
const int MODE_HOB2HOOD = 0;
const int MODE_MANUAL = 1;
// ventilation, light and mode status
int ventilation = 0;
int last_ventilation = 0;
int light = 0;
int last_light = 0;
int mode = 0; // 0 = hob2hood control, 1 = manual control
IRrecv irrecv(PIN_IR_RECEIVER); // create instance of 'irrecv'
decode_results results;
#define OFF HIGH
#define ON LOW
void setup() {
// Setup relay-outputs
pinMode(PIN_OUT_VENT_1, OUTPUT);
pinMode(PIN_OUT_VENT_2, OUTPUT);
pinMode(PIN_OUT_VENT_3, OUTPUT);
pinMode(PIN_OUT_VENT_4, OUTPUT);
digitalWrite(PIN_OUT_VENT_1, OFF);
digitalWrite(PIN_OUT_VENT_2, OFF);
digitalWrite(PIN_OUT_VENT_3, OFF);
digitalWrite(PIN_OUT_VENT_4, OFF);
pinMode(PIN_OUT_LIGHT, OUTPUT);
pinMode(PIN_OUT_EXT1, OUTPUT);
pinMode(PIN_OUT_EXT2, OUTPUT);
pinMode(PIN_OUT_EXT3, OUTPUT);
// define startup-state
digitalWrite(PIN_OUT_LIGHT, OFF);
digitalWrite(PIN_OUT_EXT1, OFF);
digitalWrite(PIN_OUT_EXT2, OFF);
digitalWrite(PIN_OUT_EXT3, OFF);
Serial.begin(9600); // for serial monitor output
Serial.println("Hob2Hood Starting ...");
Serial.println(" ... Setup IR receiver");
irrecv.enableIRIn(); // Start the IR receiver
Serial.println("Hob2Hood ready ...");
}
void loop() {
// read manual control inputs
int inLight = analogRead(PIN_IN_LIGHT);
int inVentilation1 = analogRead(PIN_IN_VENT_1);
int inVentilation2 = analogRead(PIN_IN_VENT_2);
int inVentilation3 = analogRead(PIN_IN_VENT_3);
int inVentilation4 = analogRead(PIN_IN_VENT_4);
// if any of the manual control inputs is IN USE (analog value >512) --> manual mode
if (inLight >= 512 ||
inVentilation1 >= 512 ||
inVentilation2 >= 512 ||
inVentilation3 >= 512 ||
inVentilation4 >= 512 ) {
if (mode == MODE_HOB2HOOD) {
Serial.println("Switching to manual mode");
}
mode = MODE_MANUAL;
if (inLight > 512) {
// Beleuchtung einschalten:
last_light = light;
light = 1;
} else {
// Beleuchtung ausschalten:
last_light = light;
light = 0;
}
if (inVentilation1 > 512) {
// set ventilation speed 1
last_ventilation = ventilation;
ventilation = 1;
} else if (inVentilation2 > 512) {
// set ventilation speed 2
last_ventilation = ventilation;
ventilation = 2;
} else if (inVentilation3 > 512) {
// set ventilation speed 3
last_ventilation = ventilation;
ventilation = 3;
} else if (inVentilation4 > 512) {
// set ventilation speed 4
last_ventilation = ventilation;
ventilation = 4;
} else {
// set ventilation off
last_ventilation = ventilation;
ventilation = 0;
}
controlHood();
} else {
// now we are in HOB2HOOD-mode, because no manual control is in use
// check for previous mode
if (mode == MODE_MANUAL) {
Serial.println("Switching to Hob2Hood mode");
// set to initial state
ventilation = 0;
light = 0;
controlHood();
// and switch to hob2hood mode
mode = MODE_HOB2HOOD;
irrecv.resume();
}
receiveIRCommand();
}
}
// Receive and decode IR commands and control hood upon received command
void receiveIRCommand() {
// have we received an IR signal?
if (irrecv.decode(&results)) {
Serial.println("Received IR command: ");
Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal
switch (results.value) {
case IRCMD_LIGHT_ON:
light = 1;
break;
case IRCMD_LIGHT_OFF:
light = 0;
break;
case IRCMD_VENT_1:
ventilation = 1;
break;
case IRCMD_VENT_2:
ventilation = 2;
break;
case IRCMD_VENT_3:
ventilation = 3;
break;
case IRCMD_VENT_4:
ventilation = 4;
break;
case IRCMD_VENT_OFF:
ventilation = 0;
break;
default:
break;
}
controlHood();
irrecv.resume(); // receive the next value
}
}
// control hood based on 'light' and 'ventilation' variables
void controlHood() {
bool logLight = light!=last_light;
bool logVent = ventilation!=last_ventilation;
// control light
switch (light) {
// Light OFF
case 0:
if (logLight) Serial.println("Light: OFF");
digitalWrite(PIN_OUT_LIGHT, OFF);
delay(10);
break;
// Light ON
case 1:
if (logLight) Serial.println("Light: ON");
digitalWrite(PIN_OUT_LIGHT, ON);
delay(10);
break;
default:
break;
}
// control ventilation
switch (ventilation) {
// Ventilation OFF
case 0:
if (logVent) Serial.println("Ventilation: OFF");
digitalWrite(PIN_OUT_VENT_1, OFF);
digitalWrite(PIN_OUT_VENT_2, OFF);
digitalWrite(PIN_OUT_VENT_3, OFF);
digitalWrite(PIN_OUT_VENT_4, OFF);
delay(10);
break;
// Ventilation Speed 1
case 1:
if (logVent) Serial.println("Ventilation: 1");
digitalWrite(PIN_OUT_VENT_2, OFF);
digitalWrite(PIN_OUT_VENT_3, OFF);
digitalWrite(PIN_OUT_VENT_4, OFF);
delay(100);
digitalWrite(PIN_OUT_VENT_1, ON);
delay(10);
delay(10);
break;
// Ventilation Speed 2
case 2:
if (logVent) Serial.println("Ventilation: 2");
digitalWrite(PIN_OUT_VENT_1, OFF);
digitalWrite(PIN_OUT_VENT_3, OFF);
digitalWrite(PIN_OUT_VENT_4, OFF);
delay(100);
digitalWrite(PIN_OUT_VENT_2, ON);
delay(10);
break;
// Ventilation Speed 3
case 3:
if (logVent) Serial.println("Ventilation: 3");
digitalWrite(PIN_OUT_VENT_1, OFF);
digitalWrite(PIN_OUT_VENT_2, OFF);
digitalWrite(PIN_OUT_VENT_4, OFF);
delay(100);
digitalWrite(PIN_OUT_VENT_3, ON);
delay(10);
break;
// Ventilation Speed 4
case 4:
if (logVent) Serial.println("Ventilation: 4");
digitalWrite(PIN_OUT_VENT_1, OFF);
digitalWrite(PIN_OUT_VENT_2, OFF);
digitalWrite(PIN_OUT_VENT_3, OFF);
delay(100);
digitalWrite(PIN_OUT_VENT_4, ON);
delay(10);
break;
default:
break;
}
last_light = light;
last_ventilation = ventilation;
}