Smart parking system with arduino and IR sensors

Hello everyone i really need help in my project 'smart parking lot'
i used an arduino une ,two IR proximity sensors,LCD and a mini servo motor so i have a problem withe the code i think . When a car aproach, the entry sensor is supposed to lift the barrier which is attached with the servo and so do the exit sensor but it doesn't work as it supposed and LCd must print the number of places available and down till it is full so it prints 'parking full'
I have tried some codes but without succes the same prob come everytime (the barrier goes up and down quiqly and the lcd doesn't count places knowing that the Sensor are working fine)
so if any one have done it before or can help pls cuz i'm going to show it this week

I bet the problem is in the code you tried, but didn't bother to include with your post. Did you start with just ONE device and learn how to program for it? Do you have a program that makes the servo work the way you want it to work? Do you have a program that makes the IR proximity sensor work the way you want it to work?

Once you get the individual parts figured out, then write a program to use your two sensors to do what you want. And when that runs ok, add the LCD code and get it to work. By then you will know where to place code to operate the servo.

DO NOT try to do it all at once!!!

Paul

1 Like

You must post your code, else we can't help you.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

#DH12043 here’s the code i’m using
#include <Servo.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);//connected to RS,EN,D4,D5,D6,D7 of LCD display respectively
Servo myservo; // create servo object to control a servo

#define ServoM 7 //Connected to the servo motor.
#define Exit 9 //Pin connected to the EXIT sensor.
#define In 8 //Pin connected to the IN sensor.
#define BarLow 90 //Low position of the barrier.
#define BarUp 177 //Up position of the barrier.
#define CAPACITY 7 //Capacity of the parking lot.

void setup(){
myservo.attach(ServoM); // attaches the servo.
lcd.begin(16,2);

pinMode(Exit, INPUT); // set ‚ÄúEXIT‚ÄĚ sensor pin to input
pinMode(In, INPUT); // set ‚ÄúIN‚ÄĚ sensor pin to input

myservo.write(BarLow); //Barrier in the low position
delay(1000);
}

int Available= 7; // Number of places available.

//================================================================
void loop(){

if (Available == 1){ //If only one place is available.
lcd.clear(); //Clear the LCD screen.
lcd.setCursor(1,0);
lcd.print(‚Äúdisponible‚ÄĚ);//Display the text"Space left for.
lcd.setCursor(0,1);
lcd.print(Available); //Display the no. of spaces left for cars.
lcd.print(" places");
delay(1000);
}else{
if (Available >= 1){
lcd.clear();
lcd.setCursor(1,0);
lcd.print(‚Äúdisponible‚ÄĚ);
lcd.setCursor(0,1);
lcd.print(Available);
lcd.print(" places");
delay(1000);

}else{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(‚ÄúD√©sol√©!‚ÄĚ);
lcd.setCursor(0,1);
lcd.print(‚ÄúPas d‚Äôespace!‚ÄĚ);
delay(1000);

}
}

if(digitalRead(In)) //If the IN sensor detects a car at the entrance.
{
if(Available != 0){ //Checking if there is place in parking lot(‚Äô!=‚Äô means ‚Äėnot equal to‚Äô).
Available‚Äď; //Deduct a place from the lot in the memory.
myservo.write(BarUp); //Lift the barrier up.

delay(3000);

myservo.write(BarLow);//Lower the barrier.

}
}
if(digitalRead(Exit)) //If the EXIT sensor detects a car the exit.=
{
if(Available != CAPACITY){
Available++;
myservo.write(BarUp);

delay(3000);

myservo.write(BarLow);

}
}
delay(20);
}

try this:

#include <Servo.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //connected to RS,EN,D4,D5,D6,D7 of LCD display respectively
Servo myservo;  // create servo object to control a servo

#define ServoM    7        //Connected to the servo motor.
#define Exit      9         //Pin connected to the EXIT sensor.
#define In        8         //Pin connected to the IN sensor.
#define BarLow    90      //Low position of the barrier.
#define BarUp     177        //Up position of the barrier.
#define CAPACITY  7         //Capacity of the parking lot.

int  Available = 7;                   // Number of places available.

//================================================================
void setup() {
  myservo.attach(ServoM);          // attaches the servo.
  lcd.begin(16, 2);
  pinMode(Exit, INPUT);           // set "EXIT" sensor pin to input
  pinMode(In, INPUT);             // set "IN" sensor pin to input
  myservo.write(BarLow);          //Barrier in the low position
  delay(1000);
}

//================================================================
void loop() {
  checkForCars();
  if (Available == 1) { //If only one place is available.
    lcd.clear();       //Clear the LCD screen.
    lcd.setCursor(1, 0);
    lcd.print("disponible");//Display the text"Space left for.
    lcd.setCursor(0, 1);
    lcd.print(Available);       //Display the no. of spaces left for cars.
    lcd.print(" places");
    delay(1000);
  }
  else if (Available > 1) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("disponible");
    lcd.setCursor(0, 1);
    lcd.print(Available);
    lcd.print(" places");
    delay(1000);
  }
  else if (Available == 0) {
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("Désolé!");
    lcd.setCursor(0, 1);
    lcd.print("Pas d'espace!");
    delay(1000);
  }
}
void checkForCars() {
  if (digitalRead(In)) {   //If the IN sensor detects a car at the entrance.
    if (Available != 0) {   //Checking if there is place in parking lot('!=' means 'not equal to').
      Available--;          //Deduct a place from the lot in the memory.
      myservo.write(BarUp); //Lift the barrier up.
      delay(3000);
      myservo.write(BarLow);//Lower the barrier.
    }
  }
  if (digitalRead(Exit))    //If the EXIT sensor detects a car the exit.=
  {
    if (Available != CAPACITY) {
      Available++;
      myservo.write(BarUp);
      delay(3000);
      myservo.write(BarLow);
    }
  }
}

I guess my only criticism is: your operation is completely asynchronous. Meaning a car cannot go out while one is coming in and one cannot go out while one is coming in.

Paul