This repository was archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
537 lines (486 loc) · 18.3 KB
/
Code
File metadata and controls
537 lines (486 loc) · 18.3 KB
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
// ------------------------- ZONE COMMAND ---------------------
// ---------------------6 ZONE CONTROL BOARD-------------------
// -------------------DESIGNED AND PROGRAMMED BY:--------------
// ----------------------------COREY EARL-----------------------
// -------------------REVISION 1 (SEPT 20TH, 2020)--------------
// --------------All Zones Appear to Function And Debug---------
// ------------------------More Testing Needed------------------
// print debug messages or not to serial
const bool serialDisplay = true;
/// ---------------SETTINGS-----------------
// Which zones are active. If a zone is active set as true, if a zone is deactived or not needed set to false.
const bool zone1Active = true;
const bool zone2Active = true;
const bool zone3Active = true;
const bool zone4Active = true;
const bool zone5Active = true;
const bool zone6Active = true;
// If the relay goes active when driven low set this to true, if the relays go active when drive high set to false
const bool relayLow = true;
// Sensor trigger points to trigger each zones output on. High or low "on" decided by relayLow setting
// Zone 1 setpoints
int trigger1On = 100;
int trigger1Off = 400;
// Zone 2 setpoints
int trigger2On = 100;
int trigger2Off = 400;
// Zone 3 setpoints
int trigger3On = 100;
int trigger3Off = 400;
// Zone 4 setpoints
int trigger4On = 100;
int trigger4Off = 400;
// Zone 5 setpoints
int trigger5On = 100;
int trigger5Off = 400;
// Zone 6 setpoints
int trigger6On = 100;
int trigger6Off = 400;
//// -------------------CODE----------------------
// ---Pin Assignments--
// Set Pin Assignments for Zone Status LED's
const int zone1 = 8;
const int zone2 = 9;
const int zone3 = 10;
const int zone4 = 11;
const int zone5 = 12;
const int zone6 = 13;
// Set pin assignments for OUT pins
const int out1 = 2;
const int out2 = 3;
const int out3 = 4;
const int out4 = 5;
const int out5 = 6;
const int out6 = 7;
// Set pin asignments for sensor inputs and read delays (done with millis, not delay)
const byte sens1 = A0;
const byte sens2 = A1;
const byte sens3 = A2;
const byte sens4 = A3;
const byte sens5 = A4;
const byte sens6 = A5;
// --Variables--
// Delay Variables
unsigned long sensorReadDelay = 500; // delay between sensor readings in millis
unsigned long lastSensorReadTime = 0; //the last time a sensor was read
unsigned long serialDelay = 3000; // delay between printing to serial monitor in millis
unsigned long lastSerialPrintTime = 0; // the last time the serial monitor was printed too
// Analog sensor reading values sensors 1-6
int sensor1;
int sensor2;
int sensor3;
int sensor4;
int sensor5;
int sensor6;
// Sensor pins 1-6 states ("1" = Low, "2" = Neutral, "3" = High)
int reading1;
int reading2;
int reading3;
int reading4;
int reading5;
int reading6;
// Output pin values outputs 1-6
int outRead1;
int outRead2;
int outRead3;
int outRead4;
int outRead5;
int outRead6;
// Output LED pin values outputs 1-6
int outReadLED1;
int outReadLED2;
int outReadLED3;
int outReadLED4;
int outReadLED5;
int outReadLED6;
void setup() {
// start the serial monitor and display welcome message
Serial.begin(9600);
Serial.println( " Processes Started ");
Serial.println(" --ZONE COMMAND VERSION 1-- ");
Serial.println(" --6 ZONE CONTROL BOARD-- ");
Serial.println(" -- ");
// set LED indicator pins to output.
pinMode(zone1, OUTPUT);
pinMode(zone2, OUTPUT);
pinMode(zone3, OUTPUT);
pinMode(zone4, OUTPUT);
pinMode(zone5, OUTPUT);
pinMode(zone6, OUTPUT);
// set OUT pins to output
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
pinMode(out3, OUTPUT);
pinMode(out4, OUTPUT);
pinMode(out5, OUTPUT);
pinMode(out6, OUTPUT);
// set sensor pins to input
pinMode(sens1, INPUT);
pinMode(sens2, INPUT);
pinMode(sens3, INPUT);
pinMode(sens4, INPUT);
pinMode(sens5, INPUT);
pinMode(sens6, INPUT);
}
// Read Zone 1 sensor and control output if zone is active
void zone1Control() {
if (zone1Active) { //if the zone is active
sensor1 = analogRead(sens1);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor1 <= trigger1On) {
reading1 = 1; // Reading is below trigger, turn on relay
}
else if (sensor1 >= trigger1On && sensor1 <= trigger1Off) {
reading1 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor1 >= trigger1Off) {
reading1 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading1 == 1) { // if the output needs to be turned on
digitalWrite(out1, LOW);
digitalWrite(zone1, HIGH); //Turn Zone Indicator LED On
}
else if (reading1 == 3) { //if the output needs to be turned off
digitalWrite(out1, HIGH);
digitalWrite(zone1, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading1 == 1) { // if the output needs to be turned on
digitalWrite(out1, HIGH);
digitalWrite(zone1, HIGH); //Turn Zone Indicator LED On
}
else if (reading1 == 3) { //if the output needs to be turned off
digitalWrite(out1, LOW);
digitalWrite(zone1, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Read Zone 2 sensor and control output if zone is active
void zone2Control() {
if (zone2Active) { //if the zone is active
sensor2 = analogRead(sens2);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor2 <= trigger2On) {
reading2 = 1; // Reading is below trigger, turn on relay
}
else if (sensor2 >= trigger2On && sensor2 <= trigger2Off) {
reading2 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor2 >= trigger2Off) {
reading2 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading2 == 1) { // if the output needs to be turned on
digitalWrite(out2, LOW);
digitalWrite(zone2, HIGH); //Turn Zone Indicator LED On
}
else if (reading2 == 3) { //if the output needs to be turned off
digitalWrite(out2, HIGH);
digitalWrite(zone2, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading2 == 1) { // if the output needs to be turned on
digitalWrite(out2, HIGH);
digitalWrite(zone2, HIGH);//Turn Zone Indicator LED On
}
else if (reading2 == 3) { //if the output needs to be turned off
digitalWrite(out2, LOW);
digitalWrite(zone2, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Read Zone 3 sensor and control output if zone is active
void zone3Control() {
if (zone3Active) { //if the zone is active
sensor3 = analogRead(sens3);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor3 <= trigger3On) {
reading3 = 1; // Reading is below trigger, turn on relay
}
else if (sensor3 >= trigger3On && sensor3 <= trigger3Off) {
reading3 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor3 >= trigger3Off) {
reading3 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading3 == 1) { // if the output needs to be turned on
digitalWrite(out3, LOW);
digitalWrite(zone3, HIGH); //Turn Zone Indicator LED On
}
else if (reading3 == 3) { //if the output needs to be turned off
digitalWrite(out3, HIGH);
digitalWrite(zone3, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading3 == 1) { // if the output needs to be turned on
digitalWrite(out3, HIGH);
digitalWrite(zone3, HIGH);//Turn Zone Indicator LED On
}
else if (reading3 == 3) { //if the output needs to be turned off
digitalWrite(out3, LOW);
digitalWrite(zone3, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Read Zone 4 sensor and control output if zone is active
void zone4Control() {
if (zone4Active) { //if the zone is active
sensor4 = analogRead(sens4);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor4 <= trigger4On) {
reading4 = 1; // Reading is below trigger, turn on relay
}
else if (sensor4 >= trigger4On && sensor4 <= trigger4Off) {
reading4 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor4 >= trigger4Off) {
reading4 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading4 == 1) { // if the output needs to be turned on
digitalWrite(out4, LOW);
digitalWrite(zone4, HIGH); //Turn Zone Indicator LED On
}
else if (reading4 == 3) { //if the output needs to be turned off
digitalWrite(out4, HIGH);
digitalWrite(zone4, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading4 == 1) { // if the output needs to be turned on
digitalWrite(out4, HIGH);
digitalWrite(zone4, HIGH);//Turn Zone Indicator LED On
}
else if (reading4 == 3) { //if the output needs to be turned off
digitalWrite(out4, LOW);
digitalWrite(zone4, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Read Zone 5 sensor and control output if zone is active
void zone5Control() {
if (zone5Active) { //if the zone is active
sensor5 = analogRead(sens5);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor5 <= trigger5On) {
reading5 = 1; // Reading is below trigger, turn on relay
}
else if (sensor5 >= trigger5On && sensor5 <= trigger5Off) {
reading5 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor5 >= trigger5Off) {
reading5 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading5 == 1) { // if the output needs to be turned on
digitalWrite(out5, LOW);
digitalWrite(zone5, HIGH); //Turn Zone Indicator LED On
}
else if (reading5 == 3) { //if the output needs to be turned off
digitalWrite(out5, HIGH);
digitalWrite(zone5, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading5 == 1) { // if the output needs to be turned on
digitalWrite(out5, HIGH);
digitalWrite(zone5, HIGH);//Turn Zone Indicator LED On
}
else if (reading5 == 3) { //if the output needs to be turned off
digitalWrite(out5, LOW);
digitalWrite(zone5, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Read Zone 6 sensor and control output if zone is active
void zone6Control() {
if (zone6Active) { //if the zone is active
sensor6 = analogRead(sens6);
if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
lastSensorReadTime = millis();
// Set the sensor reading levels for the output trigger for sensor1
if (sensor6 <= trigger6On) {
reading6 = 1; // Reading is below trigger, turn on relay
}
else if (sensor6 >= trigger6On && sensor6 <= trigger6Off) {
reading6 = 2; // Reading is in between triggers, maintain relay state
}
else if (sensor6 >= trigger6Off) {
reading6 = 3; // Reading is above trigger, turn off relay
}
}
if (relayLow) { //if the relays are activated by being driven low
if (reading6 == 1) { // if the output needs to be turned on
digitalWrite(out6, LOW);
digitalWrite(zone6, HIGH); //Turn Zone Indicator LED On
}
else if (reading6 == 3) { //if the output needs to be turned off
digitalWrite(out6, HIGH);
digitalWrite(zone6, LOW); //Turn Zone Indicator LED Off
}
}
else if (!relayLow) { //if the relays are actived by being driven high
if (reading6 == 1) { // if the output needs to be turned on
digitalWrite(out6, HIGH);
digitalWrite(zone6, HIGH);//Turn Zone Indicator LED On
}
else if (reading6 == 3) { //if the output needs to be turned off
digitalWrite(out6, LOW);
digitalWrite(zone6, LOW); //Turn Zone Indicator LED Off
}
}
}
}
// Display Serial debugging messages to serial monitor if serialDisplay set to true
void serialDebug() {
if (serialDisplay) { // if debug mode is turned on
if ((unsigned long)(millis() - lastSerialPrintTime) >= serialDelay) {
lastSerialPrintTime = millis();
if (relayLow) { // if the Relays are activated by a low signal
Serial.println(" Relays are set to be activated by a LOW (0V) signal ");
}
else if (!relayLow) { // if the Relays are activated by a high signal
Serial.println(" Relays are set to be activated by a HIGH (5V) signal ");
}
Serial.println(" ZONE STATUS ");
Serial.println(" -- ");
// ZONE 1 DETAILS
if (zone1Active) { // if the zone is active
outRead1 = digitalRead(out1); //check state of output 1
outReadLED1 = digitalRead(zone1); //check state of zone 1 indicator LED
Serial.println(" out1 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead1);
Serial.println("");
Serial.println(" Zone 1 LED: ");
Serial.print(outReadLED1);
Serial.println("");
Serial.println(" Sensor1 Value: ");
Serial.print(sensor1);
Serial.println("");
Serial.println(" Reading1 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading1);
Serial.println("");
}
// ZONE 2 DETAILS
if (zone2Active) { // if the zone is active
outRead2 = digitalRead(out2); //check state of output 2
outReadLED2 = digitalRead(zone2); //check state of zone 2 indicator LED
Serial.println(" out2 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead2);
Serial.println("");
Serial.println(" Zone 2 LED: ");
Serial.print(outReadLED2);
Serial.println("");
Serial.println(" Sensor2 Value: ");
Serial.print(sensor2);
Serial.println("");
Serial.println(" Reading2 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading2);
Serial.println("");
}
// ZONE 3 DETAILS
if (zone3Active) { // if the zone is active
outRead3 = digitalRead(out3); //check state of output 3
outReadLED3 = digitalRead(zone3); //check state of zone 3 indicator LED
Serial.println(" out3 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead3);
Serial.println("");
Serial.println(" Zone 3 LED: ");
Serial.print(outReadLED3);
Serial.println("");
Serial.println(" Sensor3 Value: ");
Serial.print(sensor3);
Serial.println("");
Serial.println(" Reading3 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading3);
Serial.println("");
}
// ZONE 4 DETAILS
if (zone4Active) { // if the zone is active
outRead4 = digitalRead(out4); //check state of output 4
outReadLED4 = digitalRead(zone4); //check state of zone 4 indicator LED
Serial.println(" out4 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead4);
Serial.println("");
Serial.println(" Zone 4 LED: ");
Serial.print(outReadLED4);
Serial.println("");
Serial.println(" Sensor4 Value: ");
Serial.print(sensor4);
Serial.println("");
Serial.println(" Reading4 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading4);
Serial.println("");
}
// ZONE 5 DETAILS
if (zone5Active) { // if the zone is active
outRead5 = digitalRead(out5); //check state of output 5
outReadLED5 = digitalRead(zone3); //check state of zone 5 indicator LED
Serial.println(" out5 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead5);
Serial.println("");
Serial.println(" Zone 5 LED: ");
Serial.print(outReadLED5);
Serial.println("");
Serial.println(" Sensor5 Value: ");
Serial.print(sensor5);
Serial.println("");
Serial.println(" Reading5 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading5);
Serial.println("");
}
// ZONE 6 DETAILS
if (zone6Active) { // if the zone is active
outRead6 = digitalRead(out6); //check state of output 6
outReadLED6 = digitalRead(zone6); //check state of zone 4 indicator LED
Serial.println(" out6 output value (1 is HIGH or 5V and 0 is low or 0V): ");
Serial.print(outRead6);
Serial.println("");
Serial.println(" Zone 6 LED: ");
Serial.print(outReadLED6);
Serial.println("");
Serial.println(" Sensor6 Value: ");
Serial.print(sensor6);
Serial.println("");
Serial.println(" Reading6 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
Serial.print(reading6);
Serial.println("");
}
}
}
}
void loop() {
// put your main code here, to run repeatedly:
zone1Control();
zone2Control();
zone3Control();
zone4Control();
zone5Control();
zone6Control();
serialDebug();
}