Advertisement
safwan092

Arduino_NANO_RFID_LCD_BUZZER_Smart_Shopping_Cart

May 13th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <SPI.h>
  3. #include <MFRC522.h>
  4. #include <LiquidCrystal_I2C.h>
  5. #include <Wire.h>
  6. #define SS_PIN 10
  7. #define RST_PIN 9
  8. #define buzzer 6
  9. MFRC522 mfrc522(SS_PIN, RST_PIN);
  10. LiquidCrystal_I2C lcd(0x27, 16, 2);
  11.  
  12. //char input[12];
  13. String input;
  14. int count = 0;
  15.  
  16. int a;
  17. int p1 = 0, p2 = 0, p3 = 0, p4 = 0;
  18. int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
  19.  
  20. double total = 0;
  21. int count_prod = 0;
  22.  
  23. void setup () {
  24. Serial.begin(9600);
  25. SPI.begin();
  26. mfrc522.PCD_Init();
  27. pinMode(A3, INPUT_PULLUP);
  28. pinMode(4, OUTPUT);
  29. pinMode(5, OUTPUT);
  30. pinMode(buzzer, OUTPUT);
  31. lcd.init();
  32. lcd.init();
  33. lcd.backlight();
  34. lcd.clear();
  35. lcd.setCursor(0, 0);
  36. lcd.print(" AUTOMATIC BILL");
  37. delay (2000);
  38. lcd.setCursor(0, 1);
  39. lcd.print(" SHOPPING CART ");
  40. delay (2000);
  41. lcd.clear();
  42. lcd.setCursor(0, 0);
  43. lcd.print("WELCOME TO");
  44. delay (2000);
  45. lcd.setCursor(3, 1);
  46. lcd.print("SUPER MARKET");
  47. delay (2000);
  48. lcd.clear();
  49. lcd.setCursor(0, 0);
  50. lcd.print("Plz Add iTem");
  51. }
  52.  
  53.  
  54.  
  55. void loop() {
  56. readRFID();
  57. int a = digitalRead(A3);
  58.  
  59. if (input == "29 36 CF B8" && (a == 1))
  60. {
  61.  
  62. lcd.setCursor(0, 0);
  63. lcd.print("Butter Added ");
  64. lcd.setCursor(0, 1);
  65. lcd.print("Price :- 10.00 ");
  66. p1++;
  67. digitalWrite(4, HIGH);
  68. digitalWrite(5, HIGH);
  69. delay(2000);
  70. total = total + 10.00;
  71. count_prod++;
  72. digitalWrite(4, LOW);
  73. digitalWrite(5, LOW);
  74. showTotal();
  75. input = "";
  76. }
  77. else if (input == "29 36 CF B8" && (a == 0))
  78. {
  79. if (p1 > 0)
  80. {
  81. lcd.clear();
  82. lcd.setCursor(0, 0);
  83. lcd.print("Butter Removed!!! ");
  84. digitalWrite(4, HIGH);
  85. digitalWrite(5, HIGH);
  86. delay(2000);
  87. p1--;
  88. total = total - 10.00;
  89. count_prod--;
  90. lcd.clear();
  91. digitalWrite(4, LOW);
  92. digitalWrite(5, LOW);
  93. showTotal();
  94. input = "";
  95. }
  96. else
  97. {
  98. lcd.clear();
  99. lcd.setCursor(0, 0);
  100. lcd.print("Not in cart!!! ");
  101. digitalWrite(4, HIGH);
  102. digitalWrite(5, HIGH);
  103. delay(2000);
  104. digitalWrite(4, LOW);
  105. digitalWrite(5, LOW);
  106. showTotal();
  107. input = "";
  108. }
  109. }
  110.  
  111.  
  112. if (input == "C6 91 09 2B" && (a == 1))
  113. {
  114. lcd.setCursor(0, 0);
  115. lcd.print("Milk Added ");
  116. lcd.setCursor(0, 1);
  117. lcd.print("Price :- 20.00 ");
  118. p2++;
  119. digitalWrite(4, HIGH);
  120. digitalWrite(5, HIGH);
  121. delay(2000);
  122. total = total + 20.00;
  123. count_prod++;
  124. digitalWrite(4, LOW);
  125. digitalWrite(5, LOW);
  126. showTotal();
  127. input = "";
  128. }
  129.  
  130. else if (input == "C6 91 09 2B" && (a == 0))
  131. {
  132. if (p2 > 0)
  133. {
  134. lcd.clear();
  135. lcd.setCursor(0, 0);
  136. lcd.print("Milk Removed!!! ");
  137. digitalWrite(4, HIGH);
  138. digitalWrite(5, HIGH);
  139. delay(2000);
  140. p2--;
  141. total = total - 20.00;
  142. count_prod--;
  143. lcd.clear();
  144. digitalWrite(4, LOW);
  145. digitalWrite(5, LOW);
  146. showTotal();
  147. input = "";
  148. }
  149. else
  150. {
  151. lcd.clear();
  152. lcd.setCursor(0, 0);
  153. lcd.print("Not in cart!!! ");
  154. digitalWrite(4, HIGH);
  155. digitalWrite(5, HIGH);
  156. delay(2000);
  157. digitalWrite(4, LOW);
  158. digitalWrite(5, LOW);
  159. showTotal();
  160. input = "";
  161. }
  162. }
  163.  
  164.  
  165. if (input == "03007C2DA0F2" && (a == 1))
  166. {
  167. lcd.setCursor(0, 0);
  168. lcd.print("Tea Added ");
  169. lcd.setCursor(0, 1);
  170. lcd.print("Price :- 25.00 ");
  171. p3++;
  172. digitalWrite(4, HIGH);
  173. digitalWrite(5, HIGH);
  174. delay(2000);
  175. total = total + 25.00;
  176. count_prod++;
  177. digitalWrite(4, LOW);
  178. digitalWrite(5, LOW);
  179. showTotal();
  180. input = "";
  181. }
  182.  
  183. else if (input == "03007C2DA0F2" && (a == 0))
  184. {
  185. if (p3 > 0)
  186. {
  187. lcd.clear();
  188. lcd.setCursor(0, 0);
  189. lcd.print("Tea Removed!!! ");
  190. digitalWrite(4, HIGH);
  191. digitalWrite(5, HIGH);
  192. delay(2000);
  193. p3--;
  194. total = total - 25.00;
  195. count_prod--;
  196. lcd.clear();
  197. digitalWrite(4, LOW);
  198. digitalWrite(5, LOW);
  199. showTotal();
  200. input = "";
  201. }
  202. else
  203. {
  204. lcd.clear();
  205. lcd.setCursor(0, 0);
  206. lcd.print("Not in cart!!! ");
  207. digitalWrite(4, HIGH);
  208. digitalWrite(5, HIGH);
  209. delay(2000);
  210. digitalWrite(4, LOW);
  211. digitalWrite(5, LOW);
  212. lcd.clear();
  213. input = "";
  214. }
  215. }
  216. }
  217.  
  218. void readRFID() {
  219. // Look for new cards
  220. if ( ! mfrc522.PICC_IsNewCardPresent())
  221. {
  222. return;
  223. }
  224.  
  225. // Select one of the cards
  226. if ( ! mfrc522.PICC_ReadCardSerial())
  227. {
  228. return;
  229. }
  230.  
  231. //Show UID on serial monitor
  232. Serial.println ("");
  233. Serial.println("UID tag :");
  234. String content = "";
  235. byte letter;
  236. for (byte i = 0; i < mfrc522.uid.size; i++)
  237. {
  238. content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  239. content.concat(String(mfrc522.uid.uidByte[i], HEX));
  240. content.toUpperCase();
  241. }
  242. input = content.substring(1);
  243. digitalWrite(buzzer,1);
  244. delay(500);
  245. digitalWrite(buzzer,0);
  246. Serial.println(input);
  247. lcd.setCursor(0, 1);
  248. lcd.print(input);
  249. }
  250.  
  251.  
  252. void showTotal() {
  253. lcd.clear();
  254. lcd.setCursor(0, 0);
  255. lcd.print("Total Price :-");
  256. lcd.setCursor(0, 1);
  257. lcd.print(total);
  258. }
  259.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement