IOT Car Counter

Hey everyone, I hope you are doing well. A partner and I have been working on the development of a car counter which uploads data to a webpage that will represent the amount of cars in a parking lot. Unfortunately, we both have minimal coding experience and have been learning as we go along.
Our project utilizes an ultrasonic distance sensor (UDS), an LED, and an Arduino Yun.
So far, this is the code that we have:

const int echoPin = 7; //Assigns receiver of UDS output to Arduino
const int triggerPin = 4; //Assigns trigger to Arduino
const int ledRPin = 13; //Assigns LED to Arduino
const float minRange = 14.0;  //Assigns minimum range for UDS to be considering goodRead as "off"
const float maxRange = 240.0; //Assigns maximum range for UDS to be considering goodRead as "off"

float travelTime; //stores the time between when a pulse was sent by the trigger pin and received by the echo pin in units of ms
float distance; //stores distance to object in units of cm

int goodRead;

void setup() {
  Serial.begin(9600); //baud rate at which serial data is collected
  pinMode(triggerPin, OUTPUT);
  pinMode(ledRPin, OUTPUT);
}

void loop() {
  pinMode(echoPin, OUTPUT);
  delay(10);
  digitalWrite(echoPin, 0);
  delay(10);
  pinMode(echoPin, INPUT); //resets echo in case of getting "stuck"

  digitalWrite(triggerPin, 0);
  delayMicroseconds(2);
  digitalWrite(triggerPin, 1);
  delayMicroseconds(10);
  digitalWrite(triggerPin, 0);

  travelTime = pulseIn(echoPin, 1, 13000);
  distance = (travelTime/29.0)/2.0; //distance based on the time it took for the sound to rebound back into echo

  if(distance > minRange && distance < maxRange){goodRead = 0;
  digitalWrite(ledRPin, 1);
  }
  else{goodRead = 1;
  digitalWrite(ledRPin, 0);} //allows LED to cut on only when distance parameters are met
  
delay(5);

}

We have been working on development of the code for counting the cars that pass through the entrance and exit - it should not be a problem for now. What we currently need to know is

  • How to get the current number of cars counted to show up on a webpage (vs. the maximum number alloted in the parking lot).
  • If it is possible to embed a Google Maps widget and get a pin to show up on the Arduino's location when the maximum number of parking spaces has not been reached by the car count.

We have no specific interval at which the cars must be counted, only that they be counted for every time an object passing by the UDS meets the distance parameters. As for server usage, I personally have considered Node.js and Thingspeak, but in the scope of things there's no telling which will be more practical to use given the requirements (and knowledge limitations) of this project. Neither of us have any networking experience whatsoever, so a lot of help in this area would be appreciated.

Thank you for your time!

Where are you counting anything? All I see you doing is turning an LED on or off if the distance is in range, or not.

I do not see how you think you can determine if a car is arriving or a car is leaving or a car is driving past or a cat wandered by, using one ultrasonic sensor.

The values, 14 and 240, are in what unit of measure? The value in distance is in what unit of measure?

What we currently need to know is how to get the current number of cars counted to show up on a webpage (vs. the maximum number alloted in the parking lot).

Well, the first step is to explain how you (think you) know which way a car is going, based on a single distance value. The second step is to use that knowledge to (magically) increment or decrement the count of cars in the lot. The data would "show up on a web page" when the Arduino, wearing an Ethernet shield, acting as server, received a GET request from a web browser, and responded with HTML data containing, among other things, the count of the cars in the lot.

If it is possible to embed a Google Maps widget and get a pin to show up on the Arduino's location when the maximum number of parking spaces has not been reached by the car count.

Yes, it is possible to include, in the HTML that the Arduino sends, data that enables the browser to display a google maps widget. The scale of such a map is not going to be fine enough to pin-point a single parking space that is not in use, even if your system knew how many cars are in the lot. Knowing that there are fewer cars in the lot than spaces is NOT the same as knowing where there is a space to park, or that one (or more) of the cars is not taking more than one space to park in. You will have a hard time, for instance, determining that the vehicle entering is towing a trailer, and is, therefore, going to need to use two spaces.

The distance parameters and values are in centimeters. As for the counting code, my partner and I received some from our instructor that currently needs refining. I will happily provide the code including the count once it has been cleared up, however my partner and I are under a time constraint which is why I'm asking for information that we will need in the future rather than what ties in with what we have now.

Using one UDS we can set up two separate distance parameters. This can simulate a parking lot entrance and exit in the case that both are separated simply by a curb. For example, the entrance may be detected from 10 centimeters to 180 centimeters, while the exit may be detected from 210 to 340 centimeters. Past 340 centimeters, I don't see the UDS functioning without interference. Maybe to 450, but I doubt it can maintain accuracy at that point.

Using these ranges, and setting up one as an entrance and reverse engineering the next to be an exit (while assuming, of course, that these are one-way passages), we can know how many cars have passed in and out of a parking lot. Granted, it isn't the most accurate method, but the project is more about proving it can be done. Of course better variations involving other Arduinos and ultrasonic distance sensors could be used, I just don't think there's an adequate amount of time or experience for us to utilize another.

We understand there's no way we can receive a pinpoint of where available parking spaces are. We're wanting to know how many are left, given the knowledge of how many were available to begin with. Using this data, we want to keep the pin from showing up on the map when the lot is full; when it's not full, the pin will show up.

Using these ranges, and setting up one as an entrance and reverse engineering the next to be an exit (while assuming, of course, that these are one-way passages), we can know how many cars have passed in and out of a parking lot.

Unless one leaves at the same time another is entering.

Granted, it isn't the most accurate method, but the project is more about proving it can be done.

If the approach, using just one ultrasonic sensor, were really viable, don't you suppose that it would be in widespread use already?

I just don't think there's an adequate amount of time or experience for us to utilize another.

Just out of curiosity, how much time are you given for the project, and how much of that time remains?

Using this data, we want to keep the pin from showing up on the map when the lot is full; when it's not full, the pin will show up.

OK. So, the idea is to have to google widget on the page all the time, and only show a pin if there is space available. I think that is possible, but I don't see the value that the map provides, then. A text banner supplies just as much information, without the need to consult a legend to see what the presence, or absence, of a pin means.

PaulS:
Unless one leaves at the same time another is entering.

That's right.

PaulS:
If the approach, using just one ultrasonic sensor, were really viable, don't you suppose that it would be in widespread use already?

Of course. My partner and I are going to create a second code to reverse engineer the process so that it's implied a second device could be used to subtract the count. :wink:

PaulS:
OK. So, the idea is to have a Google widget on the page all the time, and only show a pin if there is space available. I think that is possible, but I don't see the value that the map provides, then. A text banner supplies just as much information, without the need to consult a legend to see what the presence, or absence, of a pin means.

That sounds like an easier way to handle things, but the idea behind the map is that it can provide a visual representation that's more appealing. Is it possible to change the HTML within the embed code in order to place the pin on a location? I would be more than fine with having appear above the map when the lot is full, rather than the pin being taken away. Thanks!