Advertisement
safwan092

Untitled

Dec 2nd, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. #include "thingProperties.h"
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4.  
  5.  
  6. LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address and dimensions
  7. Servo gateEnterServo; // Servo for entering gate
  8. Servo gateExitServo; // Servo for exiting gate
  9.  
  10. const int gateEnterPin = 7; // Digital pin for entering gate
  11. const int gateExitPin = 8; // Digital pin for exiting gate
  12. const int irParkingPins[] = {2, 3, 4, 5, 6}; // Digital pins for IR sensors
  13. const int numParkingSensors = 5;
  14.  
  15. int carsNumber = 0;
  16. bool x, y = false;
  17.  
  18.  
  19. void setup() {
  20.  
  21. lcd.init(); // Initialize the LCD
  22. lcd.backlight();
  23. lcd.setCursor(3, 0);
  24. lcd.print("Parking System");
  25. lcd.setCursor(0, 1);
  26. lcd.print("P1:");
  27. lcd.setCursor(10, 1);
  28. lcd.print("P2:");
  29. lcd.setCursor(0, 2);
  30. lcd.print("P3:");
  31. lcd.setCursor(10, 2);
  32. lcd.print("P4:");
  33. lcd.setCursor(0, 3);
  34. lcd.print("P5:");
  35.  
  36. for (int i = 0; i < numParkingSensors; i++) {
  37. pinMode(irParkingPins[i], INPUT);
  38. }
  39.  
  40. pinMode(gateEnterPin, INPUT);
  41. pinMode(gateExitPin, INPUT);
  42.  
  43. gateEnterServo.attach(10); // Attach servo to pin 11
  44. gateExitServo.attach(11); // Attach servo to pin 12
  45.  
  46. // Initialize gates to closed positions
  47. gateEnterServo.write(90); // Adjust the angles as needed
  48. gateExitServo.write(0);
  49.  
  50. // Initialize serial and wait for port to open:
  51. Serial.begin(9600);
  52. // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  53. delay(1500);
  54.  
  55. // Defined in thingProperties.h
  56. initProperties();
  57.  
  58. // Connect to Arduino IoT Cloud
  59. ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  60.  
  61.  
  62. setDebugMessageLevel(2);
  63. ArduinoCloud.printDebugInfo();
  64. }
  65.  
  66. void loop() {
  67.  
  68. ArduinoCloud.update();
  69.  
  70. if (digitalRead(irParkingPins[0]) == 1 ) {
  71. lcd.setCursor(4, 1);
  72. lcd.print("EMPTY");
  73. p1=true;
  74.  
  75. }
  76. else {
  77. lcd.setCursor(4, 1);
  78. lcd.print("FILL ");
  79. p1=false;
  80.  
  81. }
  82.  
  83. if (digitalRead(irParkingPins[1]) == 1 ) {
  84. lcd.setCursor(13, 1);
  85. lcd.print("EMPTY");
  86. p2=true;
  87.  
  88. }
  89. else {
  90. lcd.setCursor(13, 1);
  91. lcd.print("FILL ");
  92. p2=false;
  93.  
  94. }
  95.  
  96. if (digitalRead(irParkingPins[2]) == 1 ) {
  97. lcd.setCursor(4, 2);
  98. lcd.print("EMPTY");
  99. p3=true;
  100.  
  101. }
  102. else {
  103. lcd.setCursor(4, 2);
  104. lcd.print("FILL ");
  105. p3=false;
  106.  
  107. }
  108.  
  109. if (digitalRead(irParkingPins[3]) == 1 ) {
  110. lcd.setCursor(13, 2);
  111. lcd.print("EMPTY");
  112. p4=true;
  113.  
  114.  
  115. }
  116. else {
  117. lcd.setCursor(13, 2);
  118. lcd.print("FILL ");
  119. p4=false;
  120.  
  121. }
  122.  
  123. if (digitalRead(irParkingPins[4]) == 1 ) {
  124. lcd.setCursor(4, 3);
  125. lcd.print("EMPTY");
  126. p5=true;
  127.  
  128.  
  129. }
  130. else {
  131. lcd.setCursor(4, 3);
  132. lcd.print("FILL ");
  133. p5=false;
  134.  
  135. }
  136.  
  137. if (digitalRead(gateEnterPin) == 0 && x == false && carsNumber < 5 ) {
  138. Serial.println("openGate");
  139. gateEnterServo.write(0);
  140. carsNumber++;
  141. x = true;
  142. }
  143. if (digitalRead(gateEnterPin) == 1 && x == true ) {
  144. x = false;
  145. gateEnterServo.write(90);
  146. }
  147.  
  148. if (digitalRead(gateExitPin) == 0 && y == false && carsNumber > 0) {
  149. Serial.println("closeGate");
  150. gateExitServo.write(90);
  151. carsNumber--;
  152. y = true;
  153. }
  154. if (digitalRead(gateExitPin) == 1 && y == true) {
  155. y = false;
  156. gateExitServo.write(0);
  157. }
  158.  
  159.  
  160.  
  161.  
  162. Serial.println(carsNumber);
  163.  
  164. if(carsNumber == 5){ lcd.setCursor(10, 3); lcd.print("FULL ");}
  165. else{
  166.  
  167. lcd.setCursor(10, 3);
  168. lcd.print("cars ");
  169. lcd.print(carsNumber);
  170. }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement