Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "thingProperties.h"
- #include <LiquidCrystal_I2C.h>
- #include <Servo.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD address and dimensions
- Servo gateEnterServo; // Servo for entering gate
- Servo gateExitServo; // Servo for exiting gate
- const int gateEnterPin = 7; // Digital pin for entering gate
- const int gateExitPin = 8; // Digital pin for exiting gate
- const int irParkingPins[] = {2, 3, 4, 5, 6}; // Digital pins for IR sensors
- const int numParkingSensors = 5;
- int carsNumber = 0;
- bool x, y = false;
- void setup() {
- lcd.init(); // Initialize the LCD
- lcd.backlight();
- lcd.setCursor(3, 0);
- lcd.print("Parking System");
- lcd.setCursor(0, 1);
- lcd.print("P1:");
- lcd.setCursor(10, 1);
- lcd.print("P2:");
- lcd.setCursor(0, 2);
- lcd.print("P3:");
- lcd.setCursor(10, 2);
- lcd.print("P4:");
- lcd.setCursor(0, 3);
- lcd.print("P5:");
- for (int i = 0; i < numParkingSensors; i++) {
- pinMode(irParkingPins[i], INPUT);
- }
- pinMode(gateEnterPin, INPUT);
- pinMode(gateExitPin, INPUT);
- gateEnterServo.attach(10); // Attach servo to pin 11
- gateExitServo.attach(11); // Attach servo to pin 12
- // Initialize gates to closed positions
- gateEnterServo.write(90); // Adjust the angles as needed
- gateExitServo.write(0);
- // Initialize serial and wait for port to open:
- Serial.begin(9600);
- // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
- delay(1500);
- // Defined in thingProperties.h
- initProperties();
- // Connect to Arduino IoT Cloud
- ArduinoCloud.begin(ArduinoIoTPreferredConnection);
- setDebugMessageLevel(2);
- ArduinoCloud.printDebugInfo();
- }
- void loop() {
- ArduinoCloud.update();
- if (digitalRead(irParkingPins[0]) == 1 ) {
- lcd.setCursor(4, 1);
- lcd.print("EMPTY");
- p1=true;
- }
- else {
- lcd.setCursor(4, 1);
- lcd.print("FILL ");
- p1=false;
- }
- if (digitalRead(irParkingPins[1]) == 1 ) {
- lcd.setCursor(13, 1);
- lcd.print("EMPTY");
- p2=true;
- }
- else {
- lcd.setCursor(13, 1);
- lcd.print("FILL ");
- p2=false;
- }
- if (digitalRead(irParkingPins[2]) == 1 ) {
- lcd.setCursor(4, 2);
- lcd.print("EMPTY");
- p3=true;
- }
- else {
- lcd.setCursor(4, 2);
- lcd.print("FILL ");
- p3=false;
- }
- if (digitalRead(irParkingPins[3]) == 1 ) {
- lcd.setCursor(13, 2);
- lcd.print("EMPTY");
- p4=true;
- }
- else {
- lcd.setCursor(13, 2);
- lcd.print("FILL ");
- p4=false;
- }
- if (digitalRead(irParkingPins[4]) == 1 ) {
- lcd.setCursor(4, 3);
- lcd.print("EMPTY");
- p5=true;
- }
- else {
- lcd.setCursor(4, 3);
- lcd.print("FILL ");
- p5=false;
- }
- if (digitalRead(gateEnterPin) == 0 && x == false && carsNumber < 5 ) {
- Serial.println("openGate");
- gateEnterServo.write(0);
- carsNumber++;
- x = true;
- }
- if (digitalRead(gateEnterPin) == 1 && x == true ) {
- x = false;
- gateEnterServo.write(90);
- }
- if (digitalRead(gateExitPin) == 0 && y == false && carsNumber > 0) {
- Serial.println("closeGate");
- gateExitServo.write(90);
- carsNumber--;
- y = true;
- }
- if (digitalRead(gateExitPin) == 1 && y == true) {
- y = false;
- gateExitServo.write(0);
- }
- Serial.println(carsNumber);
- if(carsNumber == 5){ lcd.setCursor(10, 3); lcd.print("FULL ");}
- else{
- lcd.setCursor(10, 3);
- lcd.print("cars ");
- lcd.print(carsNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement