safwan092

Untitled

Nov 12th, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. #define buzzer 3 // Connect buzzer to pin 3
  2. #define button 4 // Connect push button to pin 4
  3. #define relay 5 // Connect relay to pin 5
  4. #define reed_switch 2 // Connect reed switch to pin 2 (for interupt)
  5. #define status_LED 6
  6. bool button_history = false;
  7. bool latch = false;
  8. bool door_state = false;
  9. int milli;
  10. int seconds;
  11. int minutes;
  12. bool LED_state;
  13. void(* resetFunc) (void) = 0; // To reset Arduino via code
  14.  
  15. #include <Wire.h>
  16. #include <LiquidCrystal_I2C.h>
  17.  
  18. LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  19.  
  20. void setup() {
  21. lcd.noCursor();
  22. lcd.noBlink();
  23. Serial.begin(9600);
  24. lcd.init();
  25. lcd.backlight();
  26. BOOTUP();
  27. pinMode(buzzer, OUTPUT);
  28. pinMode(button, INPUT);
  29. pinMode(reed_switch, INPUT);
  30. pinMode(relay, OUTPUT);
  31. pinMode(status_LED, OUTPUT);
  32.  
  33. HOME();
  34. BUTTON_TRUE();
  35. }
  36.  
  37. void loop() {
  38. // scroll 13 positions (string length) to the left
  39. // to move it offscreen left:
  40.  
  41. SANITIZE();
  42.  
  43. }
  44.  
  45. void BOOTUP() {
  46. String BootupMSG_T = "-BrillBox-";
  47. String BootupMSG_B = "Version 1";
  48. lcd.setCursor(3, 0);
  49. lcd.print(BootupMSG_T);
  50.  
  51. lcd.setCursor(4, 1);
  52. lcd.print(BootupMSG_B);
  53.  
  54. delay(2000);
  55.  
  56. for (int positionCounter = 0; positionCounter < BootupMSG_T.length() + 3; positionCounter++) {
  57. // scroll one position left:
  58. lcd.scrollDisplayLeft();
  59. // wait a bit:
  60. delay(200);
  61. }
  62. lcd.clear();
  63. }
  64.  
  65. void HOME() {
  66. //Serial.println("entered into HOME()");
  67. bool button_state = digitalRead(button);
  68. //Serial.println(button_state);
  69. //Serial.println(button_history);
  70.  
  71. if (button_state == true) {
  72. button_history = true;
  73. return;
  74. }
  75.  
  76. while (button_history == false) {
  77. bool button_state = digitalRead(button);
  78.  
  79. if (button_state == true) {
  80. button_history = true;
  81. return;
  82. }
  83.  
  84. //Serial.println("In while loop");
  85. String HOME_T = "BrillBox:";
  86. String HOME_B = "Press To Start";
  87. lcd.setCursor(0, 0);
  88. lcd.print(HOME_T);
  89.  
  90. lcd.setCursor(1, 1);
  91. lcd.print(HOME_B);
  92. delay(500);
  93. lcd.clear();
  94. lcd.setCursor(0, 0);
  95. lcd.print(HOME_T);
  96. delay(600);
  97. }
  98. }
  99.  
  100. void BUTTON_TRUE() {
  101. lcd.clear();
  102. String BT_T = "Preparing to";
  103. String BT_B = "Sterilize ";
  104. lcd.setCursor(2, 0);
  105. lcd.print(BT_T);
  106.  
  107. lcd.setCursor(4, 1);
  108. lcd.print(BT_B);
  109. delay(1000);
  110. //check if door is closed (for safety reasons)
  111.  
  112. while (latch == false) {
  113. lcd.clear();
  114. latch = digitalRead(reed_switch);
  115. if (latch == true) {
  116. break;
  117. }
  118. Serial.println(latch);
  119. String LATCH_T = "Please Close";
  120. String LATCH_B = "Door";
  121.  
  122. lcd.setCursor(2, 0);
  123. lcd.print(LATCH_T);
  124.  
  125. lcd.setCursor(6, 1);
  126. lcd.print(LATCH_B);
  127. delay(500);
  128.  
  129. latch = digitalRead(reed_switch);
  130. if (latch == true) {
  131. break;
  132. }
  133.  
  134. lcd.clear();
  135. delay(500);
  136. }
  137.  
  138. }
  139.  
  140. void SANITIZE() {
  141.  
  142. digitalWrite(buzzer, LOW);
  143.  
  144.  
  145. door_state = digitalRead(reed_switch);
  146.  
  147. if (door_state == false) {
  148. digitalWrite(relay, LOW);
  149. LID_OPEN();
  150. }
  151.  
  152. //lcd.clear();
  153. String SANTIZIE_T = "Sterilizing: ";
  154. lcd.setCursor(2, 0);
  155. lcd.print(SANTIZIE_T);
  156. lcd.setCursor(5, 1);
  157. lcd.print(14 - minutes);
  158. lcd.print(":");
  159. if (seconds > 49) {
  160. lcd.print("0");
  161. lcd.print(59 - seconds);
  162. }
  163. if (seconds < 50) {
  164. lcd.print(59 - seconds);
  165. }
  166.  
  167.  
  168. digitalWrite(relay, HIGH);
  169. milli++;
  170. if (milli >= 10) {
  171. seconds++;
  172. if (LED_state == false) {
  173. digitalWrite(status_LED, HIGH);
  174. LED_state == true;
  175. }
  176. else {
  177. digitalWrite(status_LED, LOW);
  178. LED_state == false;
  179. }
  180. milli = 0;
  181.  
  182. }
  183. if (seconds >= 60) {
  184. lcd.clear();
  185. minutes ++;
  186. seconds = 0;
  187. }
  188. if (minutes >= 15) {
  189. minutes = 0;
  190. void DONE();
  191. }
  192. Serial.println(milli);
  193. Serial.println(seconds);
  194. Serial.println(minutes);
  195. delay(100);
  196.  
  197.  
  198. }
  199.  
  200. void DONE() {
  201. lcd.clear();
  202.  
  203. String DONE_T = "Sterilization";
  204. String DONE_B = "Complete";
  205. int counter;
  206.  
  207. while (latch == true) {
  208. latch = digitalRead(reed_switch);
  209.  
  210. lcd.setCursor(1, 0);
  211. lcd.print(DONE_T);
  212. lcd.setCursor(3, 1);
  213. lcd.print(DONE_B);
  214.  
  215. if (counter < 3) { // Beep buzzer 3 times after done (so it does not get annoying)
  216. digitalWrite(buzzer, HIGH);
  217. digitalWrite(status_LED, HIGH);
  218. counter++;
  219. }
  220.  
  221. delay(500);
  222.  
  223. lcd.clear();
  224. digitalWrite(buzzer, LOW);
  225. digitalWrite(status_LED, LOW);
  226. delay(500);
  227. }
  228. button_history = false;
  229. HOME();
  230. BUTTON_TRUE();
  231. }
  232.  
  233. void LID_OPEN() {
  234. Serial.println("In LID_OPEN");
  235.  
  236. latch = digitalRead(reed_switch);
  237.  
  238. if (latch == true) {
  239. return;
  240. }
  241.  
  242. //Screen 1:
  243. String LCD_OPEN_T1 = "-Warning-";
  244. //No LCD_OPEN_T1
  245. //Screen 2:
  246. String LCD_OPEN_T2 = "Sterilizing";
  247. String LCD_OPEN_B2 = "Stopped";
  248. //Screen 3:
  249. String LCD_OPEN_T3 = "Please Close";
  250. String LCD_OPEN_B3 = "Door";
  251.  
  252. while (latch == false) {
  253. delay(1000);
  254. lcd.clear();
  255. Serial.println("In LID_OPEN While LOOP");
  256. latch = digitalRead(reed_switch);
  257.  
  258. lcd.setCursor(3, 0);
  259. lcd.print(LCD_OPEN_T1);
  260. digitalWrite(buzzer, HIGH);
  261. digitalWrite(status_LED, HIGH);
  262.  
  263.  
  264. if (latch == true) {
  265. break;
  266. }
  267. latch = 1;//digitalRead(reed_switch);
  268. delay(500);
  269. digitalWrite(buzzer, LOW);
  270. digitalWrite(status_LED, LOW);
  271. lcd.clear();
  272. delay(500);
  273. lcd.setCursor(3, 0);
  274. lcd.print(LCD_OPEN_T1);
  275. latch = digitalRead(reed_switch);
  276.  
  277. if (latch == true) {
  278. break;
  279. }
  280. digitalWrite(buzzer, HIGH);
  281. digitalWrite(status_LED, HIGH);
  282. delay(500);
  283. digitalWrite(buzzer, LOW);
  284. digitalWrite(status_LED, LOW);
  285. lcd.clear();
  286. delay(500);
  287.  
  288. lcd.setCursor(3, 0);
  289. lcd.print(LCD_OPEN_T1);
  290. latch = digitalRead(reed_switch);
  291.  
  292. if (latch == true) {
  293. break;
  294. }
  295. digitalWrite(buzzer, HIGH);
  296. digitalWrite(status_LED, HIGH);
  297. delay(500);
  298.  
  299. digitalWrite(buzzer, LOW);
  300. digitalWrite(status_LED, LOW);
  301. lcd.clear();
  302. if (latch == true) {
  303. break;
  304. }
  305. delay(500);
  306.  
  307. lcd.setCursor(2, 0);
  308. lcd.print(LCD_OPEN_T2);
  309. lcd.setCursor(4, 1);
  310. lcd.print(LCD_OPEN_B2);
  311. latch = digitalRead(reed_switch);
  312.  
  313. if (latch == true) {
  314. break;
  315. }
  316. digitalWrite(buzzer, HIGH);
  317. digitalWrite(status_LED, HIGH);
  318. delay(1000);
  319. if (latch == true) {
  320. break;
  321. }
  322.  
  323. lcd.clear();
  324.  
  325. lcd.setCursor(2, 0);
  326. lcd.print(LCD_OPEN_T3);
  327.  
  328. lcd.setCursor(6, 1);
  329. lcd.print(LCD_OPEN_B3);
  330.  
  331. latch = digitalRead(reed_switch);
  332.  
  333. if (latch == true) {
  334. break;
  335. }
  336. digitalWrite(buzzer, LOW);
  337. digitalWrite(status_LED, LOW);
  338. delay(750);
  339. }
  340. return;
  341. }
Advertisement
Add Comment
Please, Sign In to add comment