Hello, I have made a car parking system with arduino nano. It is not responding to any commands.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address (0x27) to match your LCD
Servo myservo1;
int ir_s1 = 17;
int ir_s2 = 16;
int Total = 6;
int Space;
int flag1 = 0;
int flag2 = 0;
int greenLed = 6; // Green LED connected to pin 6
int redLed = 7; // Red LED connected to pin 7
void setup() {
pinMode(ir_s1, INPUT);
pinMode(ir_s2, INPUT);
myservo1.attach(3);
myservo1.write(100);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Car Parking ");
lcd.setCursor(0, 1);
lcd.print(" System ");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" By ");
lcd.setCursor(0, 1);
lcd.print(" Samar Gosalia ");
delay(2000);
lcd.clear();
Space = Total;
}
void loop() {
if (digitalRead(ir_s1) == LOW && flag1 == 0) {
if (Space > 0) {
flag1 = 1;
if (flag2 == 0) {
myservo1.write(0);
Space = Space - 1;
}
}
else {
lcd.setCursor(0, 0);
lcd.print("Sorry No Space");
lcd.setCursor(0, 1);
lcd.print(" Available :( ");
digitalWrite(redLed, HIGH); // Turn on the red LED
digitalWrite(greenLed, LOW); // Turn off the green LED
delay(1000);
lcd.clear();
}
}
if (digitalRead(ir_s2) == LOW && flag2 == 0) {
flag2 = 1;
if (flag1 == 0) {
myservo1.write(0);
Space = Space + 1;
}
}
if (flag1 == 1 && flag2 == 1) {
delay(1000);
myservo1.write(100);
flag1 = 0;
flag2 = 0;
}
lcd.setCursor(0, 0);
lcd.print("Total Space: ");
lcd.print(Total);
lcd.setCursor(0, 1);
lcd.print("Space Left: ");
lcd.print(Space);
if (Space > 0) {
digitalWrite(greenLed, HIGH); // Turn on the green LED
digitalWrite(redLed, LOW); // Turn off the red LED
}
else {
digitalWrite(greenLed, LOW); // Turn off the green LED
digitalWrite(redLed, HIGH); // Turn on the red LED
}
}
Note: I am not using the LCD.