Automatic parking lot

They are the same on any of the AVR arduino boards. If you get into ESP32 chips, double is twice the size as float.

I am actually trying to use time to calculate the cost
as mentioned

okay and since I am dealing with small values now so it is better to use float

why not stick to seconds? your cost is per second or is it not?

yeah that is right, sorry just realized it now, so basically remove 1000.0f/60 and keep 1000 right?

yes, then you can make s unsigned long as well

done now I all that is left is how to tackle the keypad

had to do it like this since it wasn't showing the '*'

It certainly looks like it.
A rush of kids trying to get their holiday homework done before school restarts…

At least it’s not “I really need this by tomorrow!”

haha certainly
just trying to finish it as fast as possible so I can have time to write a report and Big O Notation. after that I have several practical and theoretical assessments this 2 weeks so I am packed with assignments.
that is why I am asking here for two-point that I didn't understand.

can anyone guide me on how tackle this, the only thing I have thought so far is like this

void loop() {
  char key = myKeypad.getKey();
  if (key != NO_KEY)
  {
    if (isdigit(key))
    {
      //Serial.print(key);
      value = value * 10 + key - '0';
    }
    else if (key == 'A') {
      /*
        Serial.println ();
        Serial.print("Integer value = ");
        Serial.println (value);
        Serial.println("Enter 3 digits followed by #");
      */
      if (value == '#1*' ) { // work in progress

      }
      if () {
        a = millis();
        while (true)
        {
          c = millis();
          s = ((c - a) / 1000);
        }
      }
      value = 0;
      count = 0;
    }
  }
  else if (key = 'D') {
    lcd.clear();
    lcd.setCursor(0, 0);
    value = 0;
  }
}
}

or should I go a different route?

The single quotes denote a character constant.
You appear to have squeezed-in three characters.

yeah, I know about this error, still trying to figure out how to implement (n#)
and (#n
). so far what I could think of is to treat ('#') as the start then put the number = ('n') then end it with ('*

')
don't know if this is the right way to implement this. because I feel that if the ('1') timer is running then how will I activate time ('2') one when the second car comes in. and it goes till ('5')

You implement it as an array of entry times. When a car enters the lot, you record the current time at the given car index (0..4) not (1..5). Then, when a car exits, you calculate the duration as current time - entry time

so something like this, if the available slot is 5, one car enters and the available slot becomes 4. so let assume that

If (slot==4){ parking time array will p[0]= s, where 's' is from millis()}

right?

If your slot variable goes from 1..5, then just use that minus 1 as the index of where to store the entry time

int slot = 5;
unsigned long entryTime[5];
unsigned long duration;
int idx;
...
// you detect a car
idx = slot - 1;
entryTime[idx] = millis();
slot = slot - 1;
...
// a car exits - assume last in, first out?
idx = slot;
duration = millis() - entryTime[idx];
slot = slot + 1;
// do all your calculations to turn duration, in milliseconds into seconds/minutes/hours, etc
// and multiply by the $ rate

it actually goes opposite from 5...1 so do I have to replace it with the plus 1?
available slot 5:
available slot 4:
....
available slot 1:
when car enters the parking lot

edit: the cars are not in order

If the cars are in reverse order, draw out the mapping

Slot  Idx
5      0       // first car
4      1
3      2
2      3
1      4       // last car

and then figure out the mathematical relationship

Idx = 5 - Slot

I think I'll give up on this project for now and change it to an easier approach, I'll come back to it once I submit my projects and assessment.
since PIR doesn't work in it and the keypad code became more mess than it is supposed to be.

I apologize for wasting everybody's time and thank you for the help.
hopefully, next time when I work on it I'll be enjoying it without being under pressure.

Apparently, I can't give up on the keypad, so I was able to buy 2 IR sensors was able to implement it in my circuit, but the keypad issue still persists, I really need help since my submission is on the 5th and still not done, so is this correct or did I messed up more than it was supposed to be?

// C++ code
//
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>

Servo myservo;
int pos;
int led = 3;
int count = 0;
int ir1 = A4;
int ir2 = A5;
int value = 0;
int slot = 5;      //Enter Total number of parking Slots
unsigned long entryTime[5];
unsigned long duration;
int idx;
int flag1 = 0;
int flag2 = 0;
int pf; //duration * 0.29
int num;

const int rs = 13, e = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, e, d4, d5, d6, d7);

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'},
};
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0, A1, A2, A3}; //connect to the column pinouts of the keypad

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  pinMode(led, OUTPUT);
  pinMode(ir1, INPUT);
  pinMode(ir2, INPUT);
  lcd.begin(16, 2);
  myservo.attach(2);
  myservo.write(90);
  lcd.setCursor (0, 0);
  lcd.print("PARKING SYSTEM");
  lcd.setCursor (0, 1);
  lcd.print("PROJECT");
  delay (2000);
  lcd.clear();
  Serial.begin(9600);
  Serial.println("");
}
/*
  void sec() { // review
  c = millis();
  s = ((c - a) / 1000);
  }
*/
void loop() {
  char key = myKeypad.getKey();

  if (digitalRead (ir1) == LOW && flag1 == 0) { //pir sensor // keypad also entered
    if (slot > 0) {
      flag1 = 1;
      if (flag2 == 0) {
        myservo.write(0);
        idx = slot - 1;
        entryTime[idx] = millis();
        slot = slot - 1;
        digitalWrite(led, HIGH);
        delay(1000);
        digitalWrite(led, LOW);
      }
    } else {
      lcd.setCursor (0, 0);
      lcd.print("Sorry");
      lcd.setCursor (0, 1);
      lcd.print("Parking Full");
      delay (3000);
      lcd.clear();
    }
  }

  if (digitalRead (ir2) == LOW && flag2 == 0) { //cmd == "paid" &&
    flag2 = 1;
    if (flag1 == 0) {
      myservo.write(0);
      idx = slot;
      duration = millis() - entryTime[idx];
      slot = slot + 1;
    }
  }
  if (key != NO_KEY) {
    if (isdigit(key)) {
      num=key - '0';
    }
    else if (key == '#') {
      count++;
      if(num == 1){
        Serial.print(duration);
      }
    }
  }
  if (flag1 == 1 && flag2 == 1) {
    delay (1000);
    myservo.write(90);
    flag1 = 0, flag2 = 0;
  }
  lcd.setCursor (0, 0);
  lcd.print("Available");
  lcd.setCursor (0, 1);
  lcd.print("Slot: ");
  lcd.print(slot);
}

It is very hard to tell when you use variables like ir1 ir2 flag1 and flag2. How is anyone supposed to know what they mean?

MAYBE ir1 == Entry IR sensor? and ir2 == Exit IR sensor? I really can't even guess what flag1 and flag2 are supposed to represent.