Arduino UNO-Based Smart Parking System with IR Sensors and Servo Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is a parking system that uses an Arduino UNO microcontroller to control a 16x2 I2C LCD display, two IR sensors, and a servo motor. The system detects the presence of vehicles using the IR sensors and displays the number of available parking slots on the LCD. The servo motor acts as a gate, opening and closing based on the availability of parking slots.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
16x2 I2C LCD
- Description: A 16x2 character LCD display with I2C interface.
- Pins: GND, VCC, SDA, SCL
IR Sensor (x2)
- Description: Infrared sensor for detecting objects.
- Pins: out, gnd, vcc
Servo
- Description: A servo motor for controlling the gate.
- Pins: gnd, vcc, pulse
Wiring Details
Arduino UNO
- 5V: Connected to VCC of 16x2 I2C LCD, VCC of both IR sensors, and VCC of Servo.
- GND: Connected to GND of 16x2 I2C LCD, GND of both IR sensors, and GND of Servo.
- A4: Connected to SDA of 16x2 I2C LCD.
- A5: Connected to SCL of 16x2 I2C LCD.
- D4: Connected to pulse of Servo.
- D3: Connected to out of IR sensor 1.
- D2: Connected to out of IR sensor 2.
16x2 I2C LCD
- VCC: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- SDA: Connected to A4 of Arduino UNO.
- SCL: Connected to A5 of Arduino UNO.
IR Sensor 1
- vcc: Connected to 5V of Arduino UNO.
- gnd: Connected to GND of Arduino UNO.
- out: Connected to D3 of Arduino UNO.
IR Sensor 2
- vcc: Connected to 5V of Arduino UNO.
- gnd: Connected to GND of Arduino UNO.
- out: Connected to D2 of Arduino UNO.
Servo
- vcc: Connected to 5V of Arduino UNO.
- gnd: Connected to GND of Arduino UNO.
- pulse: Connected to D4 of Arduino UNO.
Code Documentation
// Created by Simple Circuits
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Servo myservo;
int IR1 = 2;
int IR2 = 3;
int Slot = 4; // Total number of parking Slots
int flag1 = 0;
int flag2 = 0;
void setup() {
Serial.begin(9600);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Open the backlight
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
myservo.attach(4);
myservo.write(100);
lcd.setCursor(0, 0);
lcd.print(" ARDUINO ");
lcd.setCursor(0, 1);
lcd.print(" PARKING SYSTEM ");
delay(2000);
lcd.clear();
}
void loop() {
if (digitalRead(IR1) == LOW && flag1 == 0) {
if (Slot > 0) {
flag1 = 1;
if (flag2 == 0) {
myservo.write(0);
Slot = Slot - 1;
}
} else {
lcd.setCursor(0, 0);
lcd.print(" SORRY :( ");
lcd.setCursor(0, 1);
lcd.print(" Parking Full ");
delay(3000);
lcd.clear();
}
}
if (digitalRead(IR2) == LOW && flag2 == 0) {
flag2 = 1;
if (flag1 == 0) {
myservo.write(0);
Slot = Slot + 1;
}
}
if (flag1 == 1 && flag2 == 1) {
delay(1000);
myservo.write(100);
flag1 = 0;
flag2 = 0;
}
lcd.setCursor(0, 0);
lcd.print(" WELCOME! ");
lcd.setCursor(0, 1);
lcd.print("Slot Left: ");
lcd.print(Slot);
}
This code initializes the LCD and servo motor, sets up the IR sensors as inputs, and controls the servo motor based on the sensor readings. The LCD displays the number of available parking slots.