Arduino Smart Parking System With IR Sensors OLED and Servo Gate

Published Nov 19, 2026
 3 hours to build
 Beginner

A mini smart parking system with an Arduino Uno: three IR sensors detect parked cars, an OLED shows free slots, and an SG90 servo gate closes automatically when the parking is full.

display image

Components Used

SG90 micro servo Motor
DFRobot Accessories 9g micro servo (1.6kg)
X 1
Arduino Uno R3
Main controller; reads the three IR sensors and drives the OLED and servo
X 1
IR obstacle sensor module
One per parking slot (digital output, LOW when a car is detected)
X 3
0.96 inch SSD1306 I2C OLED 128x64
Shows the status of each slot and the number of free spaces
X 1
MB102 breadboard power module
Separate regulated 5V supply for the servo
X 1
Breadboard and jumper wires
For building the circuit
X 1
Description

Finding an empty parking space can be frustrating. In this project I built a mini smart parking system with an Arduino Uno that monitors three parking slots and controls an automatic entrance gate.

Each slot has its own IR obstacle sensor. When a car parks, the sensor detects it and the Arduino updates the slot status on a 128×64 I2C OLED, showing which spaces are occupied and how many are free. An SG90 servo acts as the entrance gate: it stays open while at least one slot is free and closes when the parking is full.

This page covers how it works and the wiring. The complete Arduino code, a section-by-section code walkthrough, a troubleshooting table and FAQs are in the full tutorial on my website: Arduino Smart Parking System – full tutorial and code on Electronixity.

Demo video

How it works

The Arduino keeps checking the three IR sensors:

  1. Detecting a car: each IR module shines infrared light. When a car sits in front of it, light reflects back and the module's digital output changes (on most modules it goes LOW). The potentiometer sets the detection threshold.
  2. Checking the slots: sensor 1 watches slot 1, sensor 2 watches slot 2 and sensor 3 watches slot 3.
  3. Counting free spaces: free slots = 3 − occupied slots.
  4. Updating the OLED: the screen shows each slot as OCCUPIED or EMPTY plus the number of free spaces.
  5. Controlling the gate: if at least one slot is free, the servo opens the gate (90°). When all three are occupied, it closes (0°).

Gate logic: 0, 1 or 2 cars parked → gate open. 3 cars parked → gate closed. As soon as one car leaves, it opens again.

Circuit diagram and wiring

Disconnect the Arduino from USB before wiring.

IR sensors → Arduino Uno

  • Slot 1 OUT → D2, Slot 2 OUT → D3, Slot 3 OUT → D4
  • All VCC → 5V, all GND → GND

OLED → Arduino Uno

  • VCC → 5V (if your module supports it), GND → GND
  • SDA → A4, SCL → A5

SG90 servo

  • Signal (orange/yellow) → D9
  • Red → external regulated 5V supply
  • Brown/black → external supply GND and Arduino GND

Power tip: don't run the servo from the Uno's 5V pin. Use a separate regulated 5V supply (like an MB102 breadboard power module) and connect its ground to the Arduino GND. Don't connect the external supply's positive output to the Arduino 5V pin while the Uno is powered over USB.

Libraries

Install Adafruit SSD1306 and Adafruit GFX Library from the Arduino IDE Library Manager. The Servo library is normally included with the IDE. Reading the IR sensors needs no extra library.

Code

The complete sketch, with an explanation of how it reads the sensors, counts free slots, controls the gate and updates the OLED, is here:

👉 Get the complete Arduino Smart Parking code on Electronixity

The tutorial also shows the two settings you may need to change: the sensor logic (LOW vs HIGH when a car is detected) and the OLED I2C address (0x3C or 0x3D).

Testing

  1. After uploading, the OLED should show all three slots as EMPTY with FREE SLOTS: 3, and the gate should open.
  2. Place a toy car in front of sensor 1: SLOT 1 becomes OCCUPIED and FREE SLOTS drops to 2. The gate stays open.
  3. Repeat with slots 2 and 3. When all three are occupied, FREE SLOTS shows 0 and the servo closes the gate.
  4. Remove any one car. The free count goes back to 1 and the gate opens again.
  5. Open the Serial Monitor at 9600 baud to see each slot's status and the gate state.

If a sensor doesn't detect the car reliably, slowly turn its potentiometer while watching the module's indicator LED. Car colour and surface finish affect how much IR light reflects back.

Something not right? Blank OLED, a slot stuck on OCCUPIED, a servo that won't move or moves the wrong way, or an Arduino that resets are all covered in the troubleshooting table of the full tutorial on Electronixity.

This is a demonstration model, not a complete access-control system. A real parking gate needs separate entry/exit detection and gate safety logic.

Downloads

smart-parking-circuit-diagram Download
Comments
Ad