Advertisement
hms11

ZoneCommandRev1

Sep 21st, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.84 KB | None | 0 0
  1. // ------------------------- ZONE COMMAND ---------------------
  2. // ---------------------6 ZONE CONTROL BOARD-------------------
  3.  
  4. // -------------------DESIGNED AND PROGRAMMED BY:--------------
  5. // ----------------------------COREY EARL-----------------------
  6. // -------------------REVISION 1 (SEPT 20TH, 2020)--------------
  7. // --------------All Zones Appear to Function And Debug---------
  8. // ------------------------More Testing Needed------------------
  9.  
  10.  
  11. // print debug messages or not to serial
  12. const bool serialDisplay = true;
  13.  
  14.  
  15. /// ---------------SETTINGS-----------------
  16.  
  17. // Which zones are active. If a zone is active set as true, if a zone is deactived or not needed set to false.
  18. const bool zone1Active = true;
  19. const bool zone2Active = true;
  20. const bool zone3Active = true;
  21. const bool zone4Active = true;
  22. const bool zone5Active = true;
  23. const bool zone6Active = true;
  24.  
  25. // If the relay goes active when driven low set this to true, if the relays go active when drive high set to false
  26. const bool relayLow = true;
  27.  
  28. // Sensor trigger points to trigger each zones output on. High or low "on" decided by relayLow setting
  29.  
  30. // Zone 1 setpoints
  31. int trigger1On = 100;
  32. int trigger1Off = 400;
  33.  
  34. // Zone 2 setpoints
  35. int trigger2On = 100;
  36. int trigger2Off = 400;
  37.  
  38. // Zone 3 setpoints
  39. int trigger3On = 100;
  40. int trigger3Off = 400;
  41.  
  42. // Zone 4 setpoints
  43. int trigger4On = 100;
  44. int trigger4Off = 400;
  45.  
  46. // Zone 5 setpoints
  47. int trigger5On = 100;
  48. int trigger5Off = 400;
  49.  
  50. // Zone 6 setpoints
  51. int trigger6On = 100;
  52. int trigger6Off = 400;
  53.  
  54. //// -------------------CODE----------------------
  55.  
  56. // ---Pin Assignments--
  57.  
  58. // Set Pin Assignments for Zone Status LED's
  59. const int zone1 = 8;
  60. const int zone2 = 9;
  61. const int zone3 = 10;
  62. const int zone4 = 11;
  63. const int zone5 = 12;
  64. const int zone6 = 13;
  65.  
  66.  
  67. // Set pin assignments for OUT pins
  68. const int out1 = 2;
  69. const int out2 = 3;
  70. const int out3 = 4;
  71. const int out4 = 5;
  72. const int out5 = 6;
  73. const int out6 = 7;
  74.  
  75. // Set pin asignments for sensor inputs and read delays (done with millis, not delay)
  76. const byte sens1 = A0;
  77. const byte sens2 = A1;
  78. const byte sens3 = A2;
  79. const byte sens4 = A3;
  80. const byte sens5 = A4;
  81. const byte sens6 = A5;
  82.  
  83. // --Variables--
  84.  
  85. // Delay Variables
  86. unsigned long sensorReadDelay = 500; // delay between sensor readings in millis
  87. unsigned long lastSensorReadTime = 0; //the last time a sensor was read
  88. unsigned long serialDelay = 3000; // delay between printing to serial monitor in millis
  89. unsigned long lastSerialPrintTime = 0; // the last time the serial monitor was printed too
  90.  
  91.  
  92. // Analog sensor reading values sensors 1-6
  93. int sensor1;
  94. int sensor2;
  95. int sensor3;
  96. int sensor4;
  97. int sensor5;
  98. int sensor6;
  99.  
  100. // Sensor pins 1-6 states ("1" = Low, "2" = Neutral, "3" = High)
  101. int reading1;
  102. int reading2;
  103. int reading3;
  104. int reading4;
  105. int reading5;
  106. int reading6;
  107.  
  108. // Output pin values outputs 1-6
  109. int outRead1;
  110. int outRead2;
  111. int outRead3;
  112. int outRead4;
  113. int outRead5;
  114. int outRead6;
  115.  
  116. // Output LED pin values outputs 1-6
  117. int outReadLED1;
  118. int outReadLED2;
  119. int outReadLED3;
  120. int outReadLED4;
  121. int outReadLED5;
  122. int outReadLED6;
  123.  
  124.  
  125.  
  126. void setup() {
  127.  
  128. // start the serial monitor and display welcome message
  129. Serial.begin(9600);
  130. Serial.println( " Processes Started ");
  131. Serial.println(" --ZONE COMMAND VERSION 1-- ");
  132. Serial.println(" --6 ZONE CONTROL BOARD-- ");
  133. Serial.println(" -- ");
  134.  
  135. // set LED indicator pins to output.
  136. pinMode(zone1, OUTPUT);
  137. pinMode(zone2, OUTPUT);
  138. pinMode(zone3, OUTPUT);
  139. pinMode(zone4, OUTPUT);
  140. pinMode(zone5, OUTPUT);
  141. pinMode(zone6, OUTPUT);
  142. // set OUT pins to output
  143. pinMode(out1, OUTPUT);
  144. pinMode(out2, OUTPUT);
  145. pinMode(out3, OUTPUT);
  146. pinMode(out4, OUTPUT);
  147. pinMode(out5, OUTPUT);
  148. pinMode(out6, OUTPUT);
  149. // set sensor pins to input
  150. pinMode(sens1, INPUT);
  151. pinMode(sens2, INPUT);
  152. pinMode(sens3, INPUT);
  153. pinMode(sens4, INPUT);
  154. pinMode(sens5, INPUT);
  155. pinMode(sens6, INPUT);
  156. }
  157.  
  158. // Read Zone 1 sensor and control output if zone is active
  159. void zone1Control() {
  160. if (zone1Active) { //if the zone is active
  161. sensor1 = analogRead(sens1);
  162. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  163. lastSensorReadTime = millis();
  164.  
  165. // Set the sensor reading levels for the output trigger for sensor1
  166. if (sensor1 <= trigger1On) {
  167. reading1 = 1; // Reading is below trigger, turn on relay
  168. }
  169. else if (sensor1 >= trigger1On && sensor1 <= trigger1Off) {
  170. reading1 = 2; // Reading is in between triggers, maintain relay state
  171. }
  172. else if (sensor1 >= trigger1Off) {
  173. reading1 = 3; // Reading is above trigger, turn off relay
  174. }
  175. }
  176.  
  177. if (relayLow) { //if the relays are activated by being driven low
  178. if (reading1 == 1) { // if the output needs to be turned on
  179. digitalWrite(out1, LOW);
  180. digitalWrite(zone1, HIGH); //Turn Zone Indicator LED On
  181. }
  182. else if (reading1 == 3) { //if the output needs to be turned off
  183. digitalWrite(out1, HIGH);
  184. digitalWrite(zone1, LOW); //Turn Zone Indicator LED Off
  185. }
  186. }
  187. else if (!relayLow) { //if the relays are actived by being driven high
  188. if (reading1 == 1) { // if the output needs to be turned on
  189. digitalWrite(out1, HIGH);
  190. digitalWrite(zone1, HIGH); //Turn Zone Indicator LED On
  191. }
  192. else if (reading1 == 3) { //if the output needs to be turned off
  193. digitalWrite(out1, LOW);
  194. digitalWrite(zone1, LOW); //Turn Zone Indicator LED Off
  195. }
  196. }
  197. }
  198. }
  199.  
  200. // Read Zone 2 sensor and control output if zone is active
  201. void zone2Control() {
  202. if (zone2Active) { //if the zone is active
  203. sensor2 = analogRead(sens2);
  204. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  205. lastSensorReadTime = millis();
  206.  
  207. // Set the sensor reading levels for the output trigger for sensor1
  208. if (sensor2 <= trigger2On) {
  209. reading2 = 1; // Reading is below trigger, turn on relay
  210. }
  211. else if (sensor2 >= trigger2On && sensor2 <= trigger2Off) {
  212. reading2 = 2; // Reading is in between triggers, maintain relay state
  213. }
  214. else if (sensor2 >= trigger2Off) {
  215. reading2 = 3; // Reading is above trigger, turn off relay
  216. }
  217. }
  218.  
  219. if (relayLow) { //if the relays are activated by being driven low
  220. if (reading2 == 1) { // if the output needs to be turned on
  221. digitalWrite(out2, LOW);
  222. digitalWrite(zone2, HIGH); //Turn Zone Indicator LED On
  223. }
  224. else if (reading2 == 3) { //if the output needs to be turned off
  225. digitalWrite(out2, HIGH);
  226. digitalWrite(zone2, LOW); //Turn Zone Indicator LED Off
  227. }
  228. }
  229. else if (!relayLow) { //if the relays are actived by being driven high
  230. if (reading2 == 1) { // if the output needs to be turned on
  231. digitalWrite(out2, HIGH);
  232. digitalWrite(zone2, HIGH);//Turn Zone Indicator LED On
  233. }
  234. else if (reading2 == 3) { //if the output needs to be turned off
  235. digitalWrite(out2, LOW);
  236. digitalWrite(zone2, LOW); //Turn Zone Indicator LED Off
  237. }
  238. }
  239. }
  240. }
  241.  
  242. // Read Zone 3 sensor and control output if zone is active
  243. void zone3Control() {
  244. if (zone3Active) { //if the zone is active
  245. sensor3 = analogRead(sens3);
  246. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  247. lastSensorReadTime = millis();
  248.  
  249. // Set the sensor reading levels for the output trigger for sensor1
  250. if (sensor3 <= trigger3On) {
  251. reading3 = 1; // Reading is below trigger, turn on relay
  252. }
  253. else if (sensor3 >= trigger3On && sensor3 <= trigger3Off) {
  254. reading3 = 2; // Reading is in between triggers, maintain relay state
  255. }
  256. else if (sensor3 >= trigger3Off) {
  257. reading3 = 3; // Reading is above trigger, turn off relay
  258. }
  259. }
  260.  
  261. if (relayLow) { //if the relays are activated by being driven low
  262. if (reading3 == 1) { // if the output needs to be turned on
  263. digitalWrite(out3, LOW);
  264. digitalWrite(zone3, HIGH); //Turn Zone Indicator LED On
  265. }
  266. else if (reading3 == 3) { //if the output needs to be turned off
  267. digitalWrite(out3, HIGH);
  268. digitalWrite(zone3, LOW); //Turn Zone Indicator LED Off
  269. }
  270. }
  271. else if (!relayLow) { //if the relays are actived by being driven high
  272. if (reading3 == 1) { // if the output needs to be turned on
  273. digitalWrite(out3, HIGH);
  274. digitalWrite(zone3, HIGH);//Turn Zone Indicator LED On
  275. }
  276. else if (reading3 == 3) { //if the output needs to be turned off
  277. digitalWrite(out3, LOW);
  278. digitalWrite(zone3, LOW); //Turn Zone Indicator LED Off
  279. }
  280. }
  281. }
  282. }
  283.  
  284. // Read Zone 4 sensor and control output if zone is active
  285. void zone4Control() {
  286. if (zone4Active) { //if the zone is active
  287. sensor4 = analogRead(sens4);
  288. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  289. lastSensorReadTime = millis();
  290.  
  291. // Set the sensor reading levels for the output trigger for sensor1
  292. if (sensor4 <= trigger4On) {
  293. reading4 = 1; // Reading is below trigger, turn on relay
  294. }
  295. else if (sensor4 >= trigger4On && sensor4 <= trigger4Off) {
  296. reading4 = 2; // Reading is in between triggers, maintain relay state
  297. }
  298. else if (sensor4 >= trigger4Off) {
  299. reading4 = 3; // Reading is above trigger, turn off relay
  300. }
  301. }
  302.  
  303. if (relayLow) { //if the relays are activated by being driven low
  304. if (reading4 == 1) { // if the output needs to be turned on
  305. digitalWrite(out4, LOW);
  306. digitalWrite(zone4, HIGH); //Turn Zone Indicator LED On
  307. }
  308. else if (reading4 == 3) { //if the output needs to be turned off
  309. digitalWrite(out4, HIGH);
  310. digitalWrite(zone4, LOW); //Turn Zone Indicator LED Off
  311. }
  312. }
  313. else if (!relayLow) { //if the relays are actived by being driven high
  314. if (reading4 == 1) { // if the output needs to be turned on
  315. digitalWrite(out4, HIGH);
  316. digitalWrite(zone4, HIGH);//Turn Zone Indicator LED On
  317. }
  318. else if (reading4 == 3) { //if the output needs to be turned off
  319. digitalWrite(out4, LOW);
  320. digitalWrite(zone4, LOW); //Turn Zone Indicator LED Off
  321. }
  322. }
  323. }
  324. }
  325.  
  326. // Read Zone 5 sensor and control output if zone is active
  327. void zone5Control() {
  328. if (zone5Active) { //if the zone is active
  329. sensor5 = analogRead(sens5);
  330. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  331. lastSensorReadTime = millis();
  332.  
  333. // Set the sensor reading levels for the output trigger for sensor1
  334. if (sensor5 <= trigger5On) {
  335. reading5 = 1; // Reading is below trigger, turn on relay
  336. }
  337. else if (sensor5 >= trigger5On && sensor5 <= trigger5Off) {
  338. reading5 = 2; // Reading is in between triggers, maintain relay state
  339. }
  340. else if (sensor5 >= trigger5Off) {
  341. reading5 = 3; // Reading is above trigger, turn off relay
  342. }
  343. }
  344.  
  345. if (relayLow) { //if the relays are activated by being driven low
  346. if (reading5 == 1) { // if the output needs to be turned on
  347. digitalWrite(out5, LOW);
  348. digitalWrite(zone5, HIGH); //Turn Zone Indicator LED On
  349. }
  350. else if (reading5 == 3) { //if the output needs to be turned off
  351. digitalWrite(out5, HIGH);
  352. digitalWrite(zone5, LOW); //Turn Zone Indicator LED Off
  353. }
  354. }
  355. else if (!relayLow) { //if the relays are actived by being driven high
  356. if (reading5 == 1) { // if the output needs to be turned on
  357. digitalWrite(out5, HIGH);
  358. digitalWrite(zone5, HIGH);//Turn Zone Indicator LED On
  359. }
  360. else if (reading5 == 3) { //if the output needs to be turned off
  361. digitalWrite(out5, LOW);
  362. digitalWrite(zone5, LOW); //Turn Zone Indicator LED Off
  363. }
  364. }
  365. }
  366. }
  367.  
  368. // Read Zone 6 sensor and control output if zone is active
  369. void zone6Control() {
  370. if (zone6Active) { //if the zone is active
  371. sensor6 = analogRead(sens6);
  372. if ((unsigned long)(millis() - lastSensorReadTime) >= sensorReadDelay) {
  373. lastSensorReadTime = millis();
  374.  
  375. // Set the sensor reading levels for the output trigger for sensor1
  376. if (sensor6 <= trigger6On) {
  377. reading6 = 1; // Reading is below trigger, turn on relay
  378. }
  379. else if (sensor6 >= trigger6On && sensor6 <= trigger6Off) {
  380. reading6 = 2; // Reading is in between triggers, maintain relay state
  381. }
  382. else if (sensor6 >= trigger6Off) {
  383. reading6 = 3; // Reading is above trigger, turn off relay
  384. }
  385. }
  386.  
  387. if (relayLow) { //if the relays are activated by being driven low
  388. if (reading6 == 1) { // if the output needs to be turned on
  389. digitalWrite(out6, LOW);
  390. digitalWrite(zone6, HIGH); //Turn Zone Indicator LED On
  391. }
  392. else if (reading6 == 3) { //if the output needs to be turned off
  393. digitalWrite(out6, HIGH);
  394. digitalWrite(zone6, LOW); //Turn Zone Indicator LED Off
  395. }
  396. }
  397. else if (!relayLow) { //if the relays are actived by being driven high
  398. if (reading6 == 1) { // if the output needs to be turned on
  399. digitalWrite(out6, HIGH);
  400. digitalWrite(zone6, HIGH);//Turn Zone Indicator LED On
  401. }
  402. else if (reading6 == 3) { //if the output needs to be turned off
  403. digitalWrite(out6, LOW);
  404. digitalWrite(zone6, LOW); //Turn Zone Indicator LED Off
  405. }
  406. }
  407. }
  408. }
  409.  
  410. // Display Serial debugging messages to serial monitor if serialDisplay set to true
  411. void serialDebug() {
  412. if (serialDisplay) { // if debug mode is turned on
  413. if ((unsigned long)(millis() - lastSerialPrintTime) >= serialDelay) {
  414. lastSerialPrintTime = millis();
  415. if (relayLow) { // if the Relays are activated by a low signal
  416. Serial.println(" Relays are set to be activated by a LOW (0V) signal ");
  417. }
  418. else if (!relayLow) { // if the Relays are activated by a high signal
  419. Serial.println(" Relays are set to be activated by a HIGH (5V) signal ");
  420. }
  421. Serial.println(" ZONE STATUS ");
  422. Serial.println(" -- ");
  423. // ZONE 1 DETAILS
  424. if (zone1Active) { // if the zone is active
  425. outRead1 = digitalRead(out1); //check state of output 1
  426. outReadLED1 = digitalRead(zone1); //check state of zone 1 indicator LED
  427. Serial.println(" out1 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  428. Serial.print(outRead1);
  429. Serial.println("");
  430. Serial.println(" Zone 1 LED: ");
  431. Serial.print(outReadLED1);
  432. Serial.println("");
  433. Serial.println(" Sensor1 Value: ");
  434. Serial.print(sensor1);
  435. Serial.println("");
  436. Serial.println(" Reading1 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  437. Serial.print(reading1);
  438. Serial.println("");
  439. }
  440. // ZONE 2 DETAILS
  441. if (zone2Active) { // if the zone is active
  442. outRead2 = digitalRead(out2); //check state of output 2
  443. outReadLED2 = digitalRead(zone2); //check state of zone 2 indicator LED
  444. Serial.println(" out2 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  445. Serial.print(outRead2);
  446. Serial.println("");
  447. Serial.println(" Zone 2 LED: ");
  448. Serial.print(outReadLED2);
  449. Serial.println("");
  450. Serial.println(" Sensor2 Value: ");
  451. Serial.print(sensor2);
  452. Serial.println("");
  453. Serial.println(" Reading2 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  454. Serial.print(reading2);
  455. Serial.println("");
  456. }
  457. // ZONE 3 DETAILS
  458. if (zone3Active) { // if the zone is active
  459. outRead3 = digitalRead(out3); //check state of output 3
  460. outReadLED3 = digitalRead(zone3); //check state of zone 3 indicator LED
  461. Serial.println(" out3 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  462. Serial.print(outRead3);
  463. Serial.println("");
  464. Serial.println(" Zone 3 LED: ");
  465. Serial.print(outReadLED3);
  466. Serial.println("");
  467. Serial.println(" Sensor3 Value: ");
  468. Serial.print(sensor3);
  469. Serial.println("");
  470. Serial.println(" Reading3 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  471. Serial.print(reading3);
  472. Serial.println("");
  473. }
  474. // ZONE 4 DETAILS
  475. if (zone4Active) { // if the zone is active
  476. outRead4 = digitalRead(out4); //check state of output 4
  477. outReadLED4 = digitalRead(zone4); //check state of zone 4 indicator LED
  478. Serial.println(" out4 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  479. Serial.print(outRead4);
  480. Serial.println("");
  481. Serial.println(" Zone 4 LED: ");
  482. Serial.print(outReadLED4);
  483. Serial.println("");
  484. Serial.println(" Sensor4 Value: ");
  485. Serial.print(sensor4);
  486. Serial.println("");
  487. Serial.println(" Reading4 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  488. Serial.print(reading4);
  489. Serial.println("");
  490. }
  491. // ZONE 5 DETAILS
  492. if (zone5Active) { // if the zone is active
  493. outRead5 = digitalRead(out5); //check state of output 5
  494. outReadLED5 = digitalRead(zone3); //check state of zone 5 indicator LED
  495. Serial.println(" out5 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  496. Serial.print(outRead5);
  497. Serial.println("");
  498. Serial.println(" Zone 5 LED: ");
  499. Serial.print(outReadLED5);
  500. Serial.println("");
  501. Serial.println(" Sensor5 Value: ");
  502. Serial.print(sensor5);
  503. Serial.println("");
  504. Serial.println(" Reading5 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  505. Serial.print(reading5);
  506. Serial.println("");
  507. }
  508. // ZONE 6 DETAILS
  509. if (zone6Active) { // if the zone is active
  510. outRead6 = digitalRead(out6); //check state of output 6
  511. outReadLED6 = digitalRead(zone6); //check state of zone 4 indicator LED
  512. Serial.println(" out6 output value (1 is HIGH or 5V and 0 is low or 0V): ");
  513. Serial.print(outRead6);
  514. Serial.println("");
  515. Serial.println(" Zone 6 LED: ");
  516. Serial.print(outReadLED6);
  517. Serial.println("");
  518. Serial.println(" Sensor6 Value: ");
  519. Serial.print(sensor6);
  520. Serial.println("");
  521. Serial.println(" Reading6 Value ('1' = LOW, '2' = NEUTRAL, '3' = HIGH: ");
  522. Serial.print(reading6);
  523. Serial.println("");
  524. }
  525. }
  526. }
  527. }
  528. void loop() {
  529. // put your main code here, to run repeatedly:
  530. zone1Control();
  531. zone2Control();
  532. zone3Control();
  533. zone4Control();
  534. zone5Control();
  535. zone6Control();
  536. serialDebug();
  537. }
  538.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement