smart parking lot with IR sensors

Hello everyone i really need help in my project 'smart parking lot'
i used an arduino uno ,10 IR proximity sensors,LCD 16.02 i2c 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 to the servo and then it doesnt close untill it passes the bar 'there is an other IR sensor after the barre and the exit sensors will work with the same way . the LCd must print the number of places available and down till it is full so it prints 'full'
so if any one have done it before or can help pls cuz i'm going to show it this week

pfc_parking_smart.ino (1.96 KB)

this is the codes i used

#include <Servo.h>// includes the servo moteur library
Servo myservo;
int y=0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // includes the LiquidCrystal Library
LiquidCrystal_I2C lcd(0x27, 2, 1 , 0, 4, 5, 6, 7, 3, POSITIVE); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
const int place[]={13,12,11,10,9,8};
byte val[6];
const int in =7;
const int out =6;
int count=0;
int valin=0;
int valout=0;
int pos=51;
int cnt;

void setup() {

Serial.begin(9600);
for (int i=0;i<5;i++)
{pinMode(place*,INPUT);}*
pinMode(in,INPUT);
pinMode(out,INPUT);
myservo.attach(5);
lcd.begin(16 , 2);
lcd.setCursor(0, 0);
lcd.print("systeme allumer");
myservo.write(0);
for (pos=51 ; pos>=0; pos--){

  • myservo.write(pos);*
  • delay(30);*
    }
    delay(1000);
    for (pos=0; pos<=51; pos++){
  • myservo.write(pos);*
  • delay(30);*
    }
    lcd.clear();
    lcd.setCursor(0, 0);
    count=0;
    }
    void loop() {

lcd.setCursor(0, 0);
lcd.print("P-L:");
lcd.setCursor(0, 1);
for(y=0;y<5;y++)
{

  • val[y]=digitalRead(place[y]);*

  • if(val[y]==1)*

  • {*

  • lcd.print(y+1);*

  • }*

  • }*

  • lcd.print(" ");*

  • valin=digitalRead(in);*

  • valout=digitalRead(out);*

  • if(count>=6)*

  • {*

  • count=6;myservo.write(0);delay(1000);myservo.detach();*

  • lcd.setCursor(5, 1);*

  • lcd.print(" FULL");*

  • }*
    if(valout==LOW)
    {

  • for(pos=51 ; pos>=0; pos--)*

  • {myservo.write(pos);delay(30);*
    }
    while(valout==LOW) {

  • valout=digitalRead(out);*

}
count++;
if(count<7){}
delay(1000);
for(pos =0; pos<=51; pos++)
{myservo.write(pos);delay(30);
}
}
if (valin==LOW)
{

  • myservo.attach(5);*
  • for(pos=51 ; pos>=0; pos--){myservo.write(pos);delay(30);}*
  • while(valin==LOW)*
  • {*
  • valin=digitalRead(in);}*
    count--;
    if(count<=0){count=0;}
    delay(1000);
    for(pos=0; pos<=51; pos++) {myservo.write(pos);delay(30);}
    }
    lcd.setCursor(10, 1);
    lcd.print(" cnt:");
    lcd.print(count);
    if(count>=6){
    lcd.setCursor(5, 1);
    lcd.print(" FULL " );}
    }

When a car aproach, the entry sensor is supposed to lift the barrier which is attached to the servo and then it doesnt close untill it passes the bar

I seriously doubt that the entry sensor is going to lift anything.

It is a pronoun. In that sentence, you used it twice. The pronoun can not possibly refer to the same noun in both cases. So, try that sentence again, without a single it in it.

int valin=0;
int valout=0;
int pos=51;
int cnt;





void setup() {

Serial.begin(9600);
for (int i=0;i<5;i++)
{pinMode(place,INPUT);}

The ONLY excuse for putting the { on the same line as the statement that it follows that holds any water is that it saves real estate. You look really silly

jamming the code together

and then putting in all the useless

blank lines.

Do the IR sensors pull the pins HIGH or LOW at all times?

myservo.write(0);
for (pos=51 ; pos>=0; pos--){
  myservo.write(pos);
  delay(30);
}

Slam the servo to position 0, then slam it to position 51, and then gently move it to position 0. Why the code does this seriously needs comments to explain.

As does moving the servo back to position 51. Magic numbers suck. A const byte or #define with reasonable name, to explain the meaning of position 51 would be much better.

  if(count>=6)
  {
    count=6;myservo.write(0);delay(1000);myservo.detach();

The 7th car drives in, so you detach the servo so the barrier can't be opened again to let the car, or any other car, leave. Again, some comments as to WHY are clearly in order.

if(count<7){}

If the number of cars (why can't you use a name that reflect what you are counting?) is less than 7, do nothing. If not, do nothing. This code seems completely useless. A comment explaining why this useless code is here is definitely in order.

The code you improperly posted is poorly indented and is not complete, so that is not the code you are running.

The code you ARE running does something, but you failed to describe what that is, or how what it actually does differs from what you want it to do.