Calculate parked time when two cars enter

Hello! I'm new to Arduino and RFID so please bear with me.

I'm planning to make a parking system where there is one point of entry and another point for exit. Each of these points will have an RFID sensor each(2 RFID sensors: One entry and one Exit). So I want each card scanned (simulates a car) to have its own timer to calculate time parked of each car.

So for example: a red car enters the parking lot then a blue car enters after some time before the red car exits. Then after some time the red car exits. So here I have to start timing the red car once it arrives and also start the timer once the blue car's arrival.

How am I able to distinguish the timers apart? Or how do I "connect" one timer to one RFID card? How would I prevent overlapping the timers?

Put the arrival times in different levels of an array. The level used for each depends on the ID of the card that you read. This will allow you to differentiate between the cars on exit and to retrieve the corresponding arrival time from the array

Thanks for the quick response. Would I be able to use the millis() function for each card to calculate the time?

Yes. Save the millis() value on entry then on exit the elapsed parking time in milliseconds is the current value of millis() minus the entry value of millis()

millis() is intended to be used for timing events.

Oh sweet! Thanks for the help

Yes, but you would be better off with an RTC and Epoch Time. The millis() value gets reset if you lose power so all the timing values would be worthless. With an RTC it is easy to calculate the number of seconds between the time the card checked in and the time the card checked out.

The card has an ID number. Record the time and ID number together.

Ignore the timers that don't match the card ID.

How do you propose to fit an RFID card to a car?

Would this be an active or passive card?
You can't just have the card in the car because the metal in the car would screen the signal.

What happens when a car enters that has no RFID card fitted?

Is this a real application or just an academic exercise?

Oh wow I was thinking about RTC. I'll have to look into it more.
Thanks for the suggestions.

I guess the driver would have to tap it or I'd have to find a way to attach the tag to the car(a toy car).
The RFID cards would be passive I guess.
It's an academic exercise so I'm not looking at all the different scenarios but thanks for the input.

tl;dr: arrays

If you have a known list of car(d)s that are allowed to park, then @UKHeliBob's suggestion to use an array will suffice.

The level used for each depends on the ID of the card that you read.

You'd need to make a permanent association between a card and its corresponding slot in the array.

If you are letting everyone park, then you'll have to go to a bit more trouble and store (in arrays) the car ID and also the time when it parked. And keep a count of how many cars are even in there.

When a car leaves, look it up (find it in the ID array) and calculate the time it dwelled. Those slots in the arrays become free.

If both arrays have as many elements as there are parking spaces, you can just run through the the ID array looking for the car that is leaving, and a new car can be placed (ID and time) into any free slot, which might be indicated by a special ID like zero, no car here yet (and associated time is without meaning in a free slot).

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.