Bharath Ram
Published © GPL3+

Smart Car Parking

A website that shows the Empty car parkings available of a particular store or shopping mall.

IntermediateShowcase (no instructions)3,980
Smart Car Parking

Things used in this project

Hardware components

Proximity Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

LinkitONE Car parking Schematics

Code

Smart Car Parking.ino

Arduino
LinkitONE code
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>

#define WIFI_AP "D-Link"
#define WIFI_PASSWORD "Your Password here"
#define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.
#define SITE_URL "api.thingspeak.com"
String api = "Write APIKEY here";
LWiFiClient c;

void setup()
{
  
  Serial.begin(9600);
  Serial.println("hello");
  delay(3000);
  LWiFi.begin();

  // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    Serial.println(".");
    delay(1000);
  }
  Serial.println("WiFi Connected");
  
  // keep retrying until connected to website
  
}


void loop()
{
  // Make sure we are connected, and dump the response content to Serial
  if(c.available())
  {
   char v=c.read(); 
   Serial.print(v);
  }
    
  Serial.println("connecting to Thingspeak");
  delay(3000);
  int val=analogRead(A0);
  if(val>=360)
  {
    val=1;
  }
  else
  val=0;
  
  String count= String(val);
  
  Update("field1="+count);
  
  delay(5000);
}

void Update(String data)
{
  if(c.connect(SITE_URL,80))
  {
    c.print("POST /update HTTP/1.1\n");
c.print("Host: api.thingspeak.com\n");
c.print("Connection: close\n");
c.print("X-THINGSPEAKAPIKEY: "+api+"\n");
c.print("Content-Type: application/x-www-form-urlencoded\n");
c.print("Content-Length: ");
c.print(data.length());
c.print("\n\n");
c.print(data);
  
  if (c.connected())
{
Serial.println("Uploaded to ThingSpeak...");
Serial.println();
}
else
{
  Serial.println("failed to connect");
}
  }
}

Thingspeak Javascript for Table plugin

JavaScript
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>

  // set your channel id here
  var channel_id = 70127;
  // set your channel's read api key here if necessary
  var api_key = 'Read API KEY here';
   

  // global variables
  var chart, charts, data;

  // load the google gauge visualization
 
   google.setOnLoadCallback(drawTable);
  
   function displayTable(p) {
        var data = new google.visualization.DataTable();
        data.addColumn('number', 'Total number of car parking');
        data.addColumn('number', 'Number of car parkings filled');
        data.addColumn('number', 'empty car parkings');
        data.addRows([
          [3,   p , 3-p  ]
          
        
        ]);

        var table = new google.visualization.Table(document.getElementById('table_div'));

        table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
      }
  
  function drawTable()
  
    {
      
      var p;
       $.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {

      // get the data point
      p = data.field1;

      // if there is a data point display it
      if (p) {
        p = Math.round(p);
       displayTable(p);
      }

    });
     
       
      

   
    }
  

     
</script>

Credits

Bharath Ram

Bharath Ram

6 projects • 22 followers

Comments