#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD object with I2C address
Servo myservo1; // Servo motor object
int IR1 = 2; // IR sensor input pin for car entry
int IR2 = 4; // IR sensor input pin for car exit
int Slot = 4; // Total number of parking slots
int flag1 = 0; // Flag for IR1 detection
int flag2 = 0; // Flag for IR2 detection
void setup() {
Serial.begin(9600);
Serial.println("Initializing LCD...");
lcd.init();
lcd.begin(16, 2);
lcd.backlight();
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
myservo1.attach(6);
myservo1.write(100);
lcd.setCursor(0, 0);
lcd.print(" ARDUINO ");
lcd.setCursor(0, 1);
lcd.print(" PARKING SYSTEM ");
delay(2000);
lcd.clear();
}
void loop() {
// Check for car entry using IR1
if (digitalRead(IR1) == LOW && flag1 == 0) {
if (Slot > 0) {
flag1 = 1;
if (flag2 == 0) {
myservo1.write(0);
Slot = Slot - 1;
}
} else {
lcd.setCursor(0, 0);
lcd.print(" SORRY ");
lcd.setCursor(0, 1);
lcd.print(" Parking Full ");
delay(1000);
lcd.clear();
}
}
// Check for car exit using IR2
if (digitalRead(IR2) == LOW && flag2 == 0) {
flag2 = 1;
if (flag1 == 0) {
myservo1.write(0);
Slot = Slot + 1;
}
}
// Close the gate (servo motor) after car entry and exit
if (flag1 == 1 && flag2 == 1) {
delay(1000); // Adjust the delay time
myservo1.write(100);
flag1 = 0, flag2 = 0;
}
// Update LCD display
lcd.setCursor(0, 0);
lcd.print(" WELCOME! ");
lcd.setCursor(0, 1);
lcd.print("Slot Left: ");
lcd.print(Slot);
}
This is my arduino IDE code Please help me.
My 16*2 lcd display with i2c interface showing is showing 16 dot but not displaying any msg?
Is it error in my code?
4 posts - 4 participants