user82056: the project requires a automated parking lot, I have been able to connect and function the sensor and button for exit and enter, and the led(red lights when parking is full, green when there is spots). the maximum cars are 5. and the lcd prints the spots available and the spaces taken. the keypad is also connected. now what I need is to make a code that times each car that enters in the order that they enter in and for each car that leaves it has to enter its order of entering to calculate the price it has to pay with this equation: Parking Fee (fils) = time(sec) x 0.29fils
here is the code i have at the moment:
#include <Servo.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Servo myservo;

#define Servo 7
#define exit SDA
#define power 6 // extra
#define ground 10 // extra
#define capacity 5
#define R_led SCL
#define G_led 13
int val;
int n = 5;
int s = 0;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {A4, A3, A2, A1}; //Arduino Pins
byte colPins[COLS] = {8, 9, 10}; //Arduino Pins

void setup(){
  for(int i=0;i<4;i++){
    pinMode(rowPins[i],INPUT);  //set row pins as inputs
    pinMode(colPins[i],OUTPUT); //set column pins as outputs
  }
  Serial.begin(9600);
  myservo.attach(Servo);
  lcd.begin(16,2);
  pinMode(power,OUTPUT);
  pinMode(ground,OUTPUT);
  pinMode(exit,INPUT);
  pinMode(G_led,OUTPUT);
  pinMode(R_led,OUTPUT);
  digitalWrite(ground,LOW);
  digitalWrite(power,HIGH);
  myservo.write(0);
  digitalWrite(R_led,LOW);
  digitalWrite(G_led,LOW);  
}

void loop(){
  if (n>=1){
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("Spots left: ");
    lcd.print(n);
    lcd.setCursor(1,1);
    lcd.print("Cars inside: ");
    lcd.print(s);
    digitalWrite(G_led,HIGH);
    digitalWrite(R_led,LOW);
    delay(30);
    
  }
  else {
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("The parking is");
    lcd.setCursor(0,1);
    lcd.print("full!");
    digitalWrite(G_led,LOW);
    digitalWrite(R_led,HIGH);
    delay(30);    
  }
val = analogRead(A0);
// Serial.println(val); 
if (val>950)
{
  if (n!=0){
    n--;
    s++;
    myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
if (digitalRead(exit)==1)
{
  if (n!=capacity){
    n++;
    s--;
      myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
delay(20);
  int keyValue=0;
    digitalWrite(colPins[0],HIGH); //Set column1 as high
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){             //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
            //display either 1,4,7 or *
        Serial.println(keys[i][0]); //display key pressed
        delay(500);
      }
    }
    
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],HIGH); //Set column2 as high
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){              //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
        //display either 2,5,8,0
         Serial.println(keys[i][1]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],HIGH);//Set column3 as high
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either 3,6,9,#
         Serial.println(keys[i][2]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],HIGH);//Set column4 as high
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either A,B,C,D
         Serial.println(keys[i][3]); //display key pressed
        delay(500);
      }
    }
}


user42015: For measuring the time for each parking lot:
Declare an array of unsigned long with one element per parking lot (so 5 in this case) and initialize it with zeros:
#define N_PARKING_LOTS 5
unsigned long timestamps[N_PARKING_LOTS] = {0};

Then go to the place in your code where a new car arrives in its parking lot. You need the number of the used parking lot. Set the corresponding element in the array to millis() (for example here element 3, so the 4th parking lot):
timestamps[3] = millis();

When the corresponding car leaves you can get the time by calculating the difference and by that calculate the price:
unsigned long park_duration = millis() - timestamp[3];
float price = (park_duration/1000)*0.29;

How you know the parking lot depends on your actual process. It is difficult to understand what you want to say in your question. You could guide the arriving car to a parking spot chosen by you.
Btw: The code will get much easier for you when you actually use the Keypad library, instead of just including it. Then your current code will get way shorter.

82056: <p>the project requires a automated parking lot, I have been able to connect and function the sensor and button for exit and enter, and the led(red lights when parking is full, green when there is spots). the maximum cars are 5. and the lcd prints the spots available and the spaces taken. the keypad is also connected. now what I need is to make a code that times each car that enters in the order that they enter in and for each car that leaves it has to enter its order of entering to calculate the price it has to pay with this equation: Parking Fee (fils) = time(sec) x 0.29fils
here is the code i have at the moment:</p>
<pre><code>#include &lt;Servo.h&gt;
#include &lt;LiquidCrystal.h&gt;
#include &lt;Keypad.h&gt;
LiquidCrystal lcd(12,11,5,4,3,2);
Servo myservo;

#define Servo 7
#define exit SDA
#define power 6 // extra
#define ground 10 // extra
#define capacity 5
#define R_led SCL
#define G_led 13
int val;
int n = 5;
int s = 0;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {A4, A3, A2, A1}; //Arduino Pins
byte colPins[COLS] = {8, 9, 10}; //Arduino Pins

void setup(){
  for(int i=0;i&lt;4;i++){
    pinMode(rowPins[i],INPUT);  //set row pins as inputs
    pinMode(colPins[i],OUTPUT); //set column pins as outputs
  }
  Serial.begin(9600);
  myservo.attach(Servo);
  lcd.begin(16,2);
  pinMode(power,OUTPUT);
  pinMode(ground,OUTPUT);
  pinMode(exit,INPUT);
  pinMode(G_led,OUTPUT);
  pinMode(R_led,OUTPUT);
  digitalWrite(ground,LOW);
  digitalWrite(power,HIGH);
  myservo.write(0);
  digitalWrite(R_led,LOW);
  digitalWrite(G_led,LOW);  
}

void loop(){
  if (n&gt;=1){
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print(&quot;Spots left: &quot;);
    lcd.print(n);
    lcd.setCursor(1,1);
    lcd.print(&quot;Cars inside: &quot;);
    lcd.print(s);
    digitalWrite(G_led,HIGH);
    digitalWrite(R_led,LOW);
    delay(30);
    
  }
  else {
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print(&quot;The parking is&quot;);
    lcd.setCursor(0,1);
    lcd.print(&quot;full!&quot;);
    digitalWrite(G_led,LOW);
    digitalWrite(R_led,HIGH);
    delay(30);    
  }
val = analogRead(A0);
// Serial.println(val); 
if (val&gt;950)
{
  if (n!=0){
    n--;
    s++;
    myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
if (digitalRead(exit)==1)
{
  if (n!=capacity){
    n++;
    s--;
      myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
delay(20);
  int keyValue=0;
    digitalWrite(colPins[0],HIGH); //Set column1 as high
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i&lt;4;i++){             //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
            //display either 1,4,7 or *
        Serial.println(keys[i][0]); //display key pressed
        delay(500);
      }
    }
    
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],HIGH); //Set column2 as high
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i&lt;4;i++){              //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
        //display either 2,5,8,0
         Serial.println(keys[i][1]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],HIGH);//Set column3 as high
    digitalWrite(colPins[3],LOW);
    for(int i=0;i&lt;4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either 3,6,9,#
         Serial.println(keys[i][2]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],HIGH);//Set column4 as high
    for(int i=0;i&lt;4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either A,B,C,D
         Serial.println(keys[i][3]); //display key pressed
        delay(500);
      }
    }
}
</code></pre>
 42015: <p>For measuring the time for each parking lot:</p>
<p>Declare an array of <code>unsigned long</code> with one element per parking lot (so 5 in this case) and initialize it with zeros:</p>
<pre><code>#define N_PARKING_LOTS 5
unsigned long timestamps[N_PARKING_LOTS] = {0};
</code></pre>
<p>Then go to the place in your code where a new car arrives in its parking lot. You need the number of the used parking lot. Set the corresponding element in the array to <code>millis()</code> (for example here element 3, so the 4th parking lot):</p>
<pre><code>timestamps[3] = millis();
</code></pre>
<p>When the corresponding car leaves you can get the time by calculating the difference and by that calculate the price:</p>
<pre><code>unsigned long park_duration = millis() - timestamp[3];
float price = (park_duration/1000)*0.29;
</code></pre>
<p>How you know the parking lot depends on your actual process. It is difficult to understand what you want to say in your question. You could guide the arriving car to a parking spot chosen by you.</p>
<p>Btw: The code will get much easier for you when you actually use the <code>Keypad</code> library, instead of just including it. Then your current code will get way shorter.</p>
