This project demonstrates how you can use Arduino to count the number of cars that come in and out of a mall using two sensors, send the data to the cloud using Processing & PHP, and later view the number of available slots in the parking lot. You do not need an Ethernet or Wifi shield for this project!
How it worksThe sensors need to be placed in the entry and exit point of the parking lot for this to work as intended. Basically, you increment the count every time a car comes in and decrement when it goes out. The LED in the system simply indicates that the vehicle is properly counted as it lights on every time a car passes through the sensor.
ProcessingProcessing is an open source language/development tool for writing programs in other computers. Useful when you want those other computers to "talk" with an Arduino, for instance to display or save some data collected by the Arduino.
For this project, we used Processing to receive the data (count of cars) sent by Arduino via serial port. Download and install the Processing IDE to your computer. You can see in the attached Processing sketch a very simple and straight-forward lines of code. Here, we call the PHP file using the method loadStrings().
The PHP file post-message.php is the same file in the tutorial found here. We downloaded the entire zip file from the Github page and edited a few lines of code in the original file so that we can use it without having to login to our Samsung account. For this to work, you will need to follow the instructions here about changing the port of your WAMP or XAMP server and installing the CA certificate for ARTIK Cloud. Alternatively, you can use your remote or hosted server with installed SSL certificate.
Copy the files to a folder, say, acdemo so that it can be accessed using the URL http://localhost:8000/acdemo/post-message.php or https://www.yourwebsite.com/acdemo/post-message.php
There are only two files in the PHP SDK that you need to edit: ArtikCloudProxy.php and post-message.php. You can view your client & device ID here.
In the post-message.php file, you need to get your access token and device ID. The easiest way to get the token is by following the steps here. Note that the only data that we're sending to the cloud is the number of cars that enters and exits the mall. We created a device in the Artik Cloud and named it Car Counter with a field called count which holds this value.
Now that everything is setup, it's time to get it going! Follow the simple steps below:
Artik Cloud- 1. Login to your Artik Cloud account and go to Applications > New Application
- 2. Enter the necessary details for your application in the next screen.
- 3. Once you finish creating your application, if will be displayed in your dashboard. Click the application name and look for Show Client ID & Secret. You need these codes for the PHP files.
- 4. From the side menu, select your application and click Permissions. Add Car Counter from the list of device types and check Read & Write permissions.
- 1. Upload the sketch to your Arduino UNO. If this is your first time to use Arduino, follow these steps to understand how to do this procedure.
- 2. Run the Processing sketch in the Processing IDE. Make sure that your WAMP server is on at this point if you're using your local computer instead of a hosted server.
- 3. If you have successfully connected the parts for this system based on the connection diagram above, pass through the PIR sensor to see if it works.
- 4. Login to your Artik Cloud account to see if the data is being sent properly.
- 1. Open the link below to see if the data is being properly sent to Artik Cloud. If nothing goes wrong, this will display a Json file. If you don't see a Json file, you may not have installed the SSL certificate as described above. Try to go back and make sure to follow the directions properly.
http://localhost:8000/acdemo/post-message.php?count=10
Based on the above data of car count, you can create an app for a mall so that shoppers can view the number of available slots in the parking space before going to the mall. You can also add another light indicator that turns on when the parking is full or not.
Comments