Limited Time Your first expert consultation is free! Book now Book now

Back to MakerSpaceArduino Projects

Smart Parking Garage with Arduino

Heba 17

1. Overview

A small four-space parking garage model with an Arduino UNO. Two servo gates control entry and exit, two buttons count cars in and out, and an I2C 16x2 LCD shows how many spaces are free. It is a suggested, reproducible design, not a tested garage or a real traffic-control system.

2. How It Works

The controller starts with four free spaces and reads both buttons with software debounce, without a blocking delay. A stable press on D7 reduces the count and briefly opens the entry servo if a space is free. A press on D8 raises the count and opens the exit servo if a car is inside. The entry gate stays shut when the garage is full, and the exit gate stays shut when it is empty. The LCD shows Available and Occupied, and each servo closes again after an adjustable time.

3. Components Required

Click here to open the components table

4. Circuit Diagram

Make the connections according to the diagram: Arduino UNO D6 to the entry servo signal, D3 to the exit servo signal, A4 and A5 to the LCD SDA and SCL, D7 and D8 to two buttons that go to GND, and the regulated 5V supply to the V+ wires of both servos. Join the servo supply negative to Arduino GND, and never pass servo current through the board 5V.

Click here to open the wiring diagram

Diagram colors: orange = servo signal, purple/pink = buttons D7/D8, yellow = SDA, green = SCL, red = 5V, black = GND. Fritzing parts are licensed CC BY-SA.

5. Wiring Table

Read each row from the From pin to the To pin, then check power, ground and signals together before you power up. All grounds (LCD, both buttons, 5V supply, both servos) join the Arduino GND.

Click here to open the wiring table

6. Connection Steps

Wire the project in this order, with the power off. The table has the same steps with a check for each.

  1. Join the common GND first: Arduino, LCD, both buttons, 5V supply, both servos.
  2. Connect the external regulated 5V to V+ of both servos. Never take servo power from the Arduino 5V.
  3. Servo signals: D6 = entry gate, D3 = exit gate.
  4. LCD: A4 = SDA, A5 = SCL, Arduino 5V = VCC, GND = GND.
  5. Buttons: D7 = entry, D8 = exit, the other terminal of each goes to GND.
  6. Install Wire, Servo and LiquidCrystal_I2C, select Arduino UNO and the port, confirm the LCD address (0x27 or 0x3F), upload.
  7. Close both arms, then test each gate without a car model before adding any load.

Click here to open the connection steps table

7. Source Code

Upload this code to the Arduino UNO (file name smart_parking_garage.ino). It needs the Wire, Servo and LiquidCrystal_I2C libraries. The LCD address may be 0x27 or 0x3F; change it after checking your module, because the code does not detect it automatically.

#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
const byte ENTRY_SERVO_PIN = 6;
const byte EXIT_SERVO_PIN = 3;
const byte ENTRY_BUTTON_PIN = 7;
const byte EXIT_BUTTON_PIN = 8;
const byte TOTAL_SPACES = 4;
const byte CLOSED_ANGLE = 0;
const byte OPEN_ANGLE = 90;
const unsigned long DEBOUNCE_MS = 45;
const unsigned long GATE_OPEN_MS = 1200;
// Change 0x27 to 0x3F only after confirming the installed LCD.
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo entryServo;
Servo exitServo;
byte availableSpaces = TOTAL_SPACES;
unsigned long entryCloseAt = 0;
unsigned long exitCloseAt = 0;
bool lcdDirty = true;
struct ButtonState {
byte pin;
bool lastReading;
bool stableState;
unsigned long changedAt;
};
ButtonState entryButton = {ENTRY_BUTTON_PIN, HIGH, HIGH, 0};
ButtonState exitButton = {EXIT_BUTTON_PIN, HIGH, HIGH, 0};
bool pressedEvent(ButtonState &b) {
bool reading = digitalRead(b.pin);
if (reading != b.lastReading) { b.lastReading = reading; b.changedAt = millis(); }
if ((millis() - b.changedAt) >= DEBOUNCE_MS && reading != b.stableState) {
b.stableState = reading;
return b.stableState == LOW;
}
return false;
}
void openEntryGate() { entryServo.write(OPEN_ANGLE); entryCloseAt = millis() + GATE_OPEN_MS; }
void openExitGate() { exitServo.write(OPEN_ANGLE); exitCloseAt = millis() + GATE_OPEN_MS; }
void updateGates() {
unsigned long now = millis();
if (entryCloseAt != 0 && (long)(now - entryCloseAt) >= 0) { entryServo.write(CLOSED_ANGLE); entryCloseAt = 0; }
if (exitCloseAt != 0 && (long)(now - exitCloseAt) >= 0) { exitServo.write(CLOSED_ANGLE); exitCloseAt = 0; }
}
void updateDisplay() {
if (!lcdDirty) return;
lcd.clear();
lcd.setCursor(0, 0); lcd.print("Available: "); lcd.print(availableSpaces);
lcd.setCursor(0, 1); lcd.print("Occupied: "); lcd.print(TOTAL_SPACES - availableSpaces);
lcdDirty = false;
}
void setup() {
pinMode(ENTRY_BUTTON_PIN, INPUT_PULLUP);
pinMode(EXIT_BUTTON_PIN, INPUT_PULLUP);
entryServo.attach(ENTRY_SERVO_PIN);
exitServo.attach(EXIT_SERVO_PIN);
entryServo.write(CLOSED_ANGLE); exitServo.write(CLOSED_ANGLE);
lcd.init(); lcd.backlight();
updateDisplay();
}
void loop() {
if (pressedEvent(entryButton) && availableSpaces > 0) { availableSpaces--; openEntryGate(); lcdDirty = true; }
if (pressedEvent(exitButton) && availableSpaces < TOTAL_SPACES) { availableSpaces++; openExitGate(); lcdDirty = true; }
updateGates();
updateDisplay();
}

Still to verify: the sketch compiles with your library version, the LCD address, arm movement, the servo current margin, and a stable count under repeated presses.

8. Testing & Troubleshooting

  • Startup: power on without pressing anything; 4 spaces show and both gates stay closed.
  • One car in: press D7 once; the count becomes 3 and the entry gate opens once.
  • One car out: press D8 after an entry; the count returns to 4 and the exit gate opens.
  • Full garage: press D7 four times; at zero spaces the entry gate stays shut.
  • Empty garage: with 4 free, D8 does nothing.
  • Button bounce: one quick press must register once only.
  • Servo brownout: if the board restarts or the LCD glitches, keep the servos off the board 5V and increase the supply margin.
  • LCD blank: check the address, SDA/SCL, VCC, GND and the display contrast.

9. Improvements

  • Add a light sensor per space after checking voltage and logic levels.
  • Store the count in EEPROM with power-loss handling, after testing memory wear and start-up behavior.
  • Add adjustable motion timers and a clearer status display without blocking the main loop.
  • Add a mechanical stop switch to the model, for use while adjusting the angles.

10. Safety

The code, pinout, servo current margin and physical timing are not verified until the build is made and measured. This is a low-voltage 5V DC model only. Do not use motors or exposed wires near children without supervision.

Share
H
About the authorHeba
Share a useful question or note and the project team can reply in the discussion.

Comments & discussion (0)