Monday, May 4, 2015

Smart Parking -

My final project is to demonstrate Smart Parking using Internet of Things. I have used Django framework - Python web framework which follows model-view-controller (MVC) architectural pattern. Using Django made my work easy as I  just need to concentrate on my application code. I have used RESTful API to collect data from sensors and to get data from user. I'm using sqlite3 which is default one in Django frame work  and basic HTML to create web page. 

The total project is majorly divided in to three systems, Controller program that monitors the sensor data and update those details in to data base, Views program that monitors the request from the front end and renders the information that it fetched from database to webpage , and frontend HTML page that  displays the details.

Sensor and Wiring : 

 I have used HC-SR04 sensor to measure the distance as I found it affordable and is having good range detection 4 to 400 cm. But I found it working good if the object is place some where between 4 to 250 cm. It actually works well if you place the object with in 30 degrees of angle.

Let us see how to wire it. 

VCC - Connected to 5V as sensor needs 5V power
Trig - Connect this to GPIO output 
Echo - Connect this to GPIO input 
GND - Connected to ground

The output signal form sensor will be 5V, but the Raspberry Pi can only handle 3.3v or less. So in order to protect GPIO pins we need resistors to get down voltage to 3.3V or less. I have used two resistors 180 and 330 k ohm which are connected in parallel. 


Vout =   Vin * R2/(R2+R1)
Vout = Vin * 180 /(180 + 330)
Vout = 5V * 0.352941176
Vout = 1.8V 



Wiring 

Controller :

Controller generates the trigger which will be reflected back when it hits some obstacle. We will measure time that sound took to get back to echo and calculate distance using distance formula.

Distance = Speed * Time

Speed of Sound = 340m/s

Controller checks the distance of object every 5 seconds and updates those details in Database. I have designed this in such a way that if the distance of object is greater than 50, then update the Parking status as "empty" otherwise update it as "occupied". Controller will update database only when it senses a change in parking state.  


Smart parking Dash board shows Empty count and Occupied count and will allow you to reserve a parking lot for you if parking is available.  Default time vale to book would be 1 hour and you can change it. In case if parking is already occupied, it shows you expected parking available timestamp.
Every Booking is Request Post, which will validates the data and sum up the number of hours entered to current time stamp and store it as next parking available timestamp, which is then showed on webpage. 

I would like to enhance this project adding features like dynamic pricing - combining the earlier parking patterns and current need and available parking slots, Informing towing company - Adding more sensors to make complete system and handling them. I can use same sensors combining with Pi-camera and buzzer  for parking assist in car. This would display the distance of car behind you and alerts you. 

Monday, March 30, 2015

Starting Final Project - 

Smart Parking :

0.1 Introduction:

Purpose:

                The purpose of this document is to present a detailed explanation of Smart Parking Detection. This will describe us  purpose and features of the system, the interface of the system, what the system will do, the constraints under which it must operate and how the system will react to external stimuli. This document is intended for both the stakeholders and developers of  system.

1.0 Purpose & Requirements Specification

1.1 Purpose of Project:

                “ Decade of the Urbanization “ – World’s growing love affair with cities shows robust growth of urban population which is at rate of 1.8% per every year in this decade. With estimation of 70% of world’s population live in cities by 2050, managing urban areas has become one of the most important development challenges of the 21st century. As a result, countries will face numerous challenges in meeting the needs of their growing urban populations, including for transportation, infrastructure, housing, energy and employment, as well as for basic services such as education and health care. One of such problem is traffic congestion and parking in cities. According to a survey about 30% of traffic congestion in cities during peak times is because of drivers searching parking areas. To address this problem this project proposes a  well planned parking system that would save time, fuel  and helps us to reshape our cities and put them in path of “Smart Cities”. This smart parking system allows us to check the parking availability remotely using a web application.

1.2 Behavior :

                Smart parking Detector is mobile application which helps people to locate available parking spots in the location that user planning to travel and can reserve a parking spot. This parking system can be installed in all parking demand places in the city such as Shopping malls, Airports, hotels etc.  User needs to install this application on his mobile by downloading it.  User can get availability of parking or propose next parking available time.

1.3 System Management Requirement:

                This system provides remote monitoring  and control function. Administrator will be appointed based of the size of institution, who monitors sensors, payment issues, timing issues (towing vehicle in case of delay in moving out). He also monitors the accuracy of system and update information accordingly.



1.4 Data Analysis Requirement:

                 System will maintain a repository to provide information to support decision making in determining pricing and planning. System will also calculate the time of next available parking slot and should report it to user.

1.5 Application Deployment Requirement:


                Smart parking detectors can be installed in any place in 10 minutes. To install Smart Parking System in any institution will happen in incremental manner instead of blocking all the parking and installing(depends on the size of institution) which may take few hours of shutdown of that particular block.  Internet connection is mandatory for these devices which can be provided with Wifi or Ethernet. These devices fetches and update the information from/in to a database, which is located on a web-server. User should be connected with internet to get the updates on available parking slots.

2.0 Process Specification:

2.1  USE case diagrams:


2.2 Sensor level diagram :



Sensor keeps on checking for a vehicle presence in the parking slot( uses distance sensor) .  If it finds any change in its state it will update those details in Database. If parking slot is empty it will update the total availability count adding one to it. When parking slot at particular sensor is occupied, it will update the availability count by subtracting one from it. When parking is full, it will check expire time-stamp(estimated time to vacate)  in database and determines availability of next parking slot send those details to user.

If distance calculated by sensor is more than 50 cm, parking is available, if its less than that parking slot is occupied.


2.3 Process Diagram:



Rectangle – state 
Diamond – Decision
Circle – Start/Stop

3.0 Domain Model Specification:





4.0 Information Model Specification:



  5.0 Service Specification Model



6.0 IOT level Specification Model


Smart parking belongs to IOT Level-1 specification because it uses a single level node/sensor for collecting data and store it in local database. It also uses local analysis , Rest services.






Monday, March 16, 2015

Fire Detection using Raspberry Pi

 Here in we are going to see how simple it is to come up with your own Fire detecting device using flame sensor and Raspberry pi . We  can use a buzzer or turn on water sprinklers or even  send an automatic email to fire department.  I'm going to use an LED which blinks on fire detection.

Requirements :


  1.        Raspberry Pi
  2.        Flame detector
  3.        LED 
  4.        330 Ohm resistor


Flame Sensor Interface:


  •  VCC :-  3.3V-5V voltage
  •  GND :- GND
  •  DO :- board digital output interface (0 and 1)
  •  AO :- board analog output interface


Circuit/ Connection Images:



Connection Steps:

1) Connect Ground on sensor to ground on Raspberry Pi.
2) Supply + 3.3V to power( + symbol on sensor).
3)  Connect Digital out pin of sensor to GPIO input using a resistor (256 O).
4) Connect GPIO out to LED .

Demo:




Code :

I'm using GPIO 18 as output which is connected to LED and GPIO pin 25 as Input from Flame Sensor


from time import sleep
import RPi.GPIO as GPIO

#GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

LedOut = 18
Flamein = 25

#Switch Pin
GPIO.setup(Flamein, GPIO.IN)

#Switch Led
GPIO.setup(LedOut, GPIO.OUT)
count = 0

while True:
    try:
        if (GPIO.input(25) == True):
            print 'fire in your house'
            GPIO.output(LedOut, 1)
            sleep(0.1)
            GPIO.output(LedOut, 0)
            sleep(0.1)
            GPIO.output(LedOut, 1)
         
        else:
            print 'you are safe'
            GPIO.output(LedOut, 0)
         
    except KeyboardInterrupt:
        exit()
GPIO.cleanup()









Monday, February 9, 2015

Smart City - Smart Parking

                             “ Decade of the Urbanization “ – World’s growing love affair with cities shows robust growth of urban population which is at rate of 1.8% per every year in this decade. With estimation of 70% of world’s population live in cities by 2050, managing urban areas has become one of the most important development challenges of the 21st century. As a result, countries will face numerous challenges in meeting the needs of their growing urban populations, including for transportation, infrastructure, housing, energy and employment, as well as for basic services such as education and health care. One of such problem is traffic congestion and parking in cities. According to a survey about 30% of traffic congestion's in cities during peak times is because of drivers searching parking areas. To address this problem this project proposes a  well planned parking system that would save time, fuel  and helps us to reshape our cities and put them in path of “Smart Cities”. This smart parking system allows us to check the parking availability remotely using a web application.

Devices : Location sensors and Distance sensors to identify the location spots




     


Setting up Raspberry Pi device -

Installing Raspbian OS:

Things required:

  • Raspberry Pi device
  • HDMI monitor 
  • USB Keyboard and Mouse
  • 8GB Sd card with NOOBS installed ( else download it from http://www.raspberrypi.org/downloads/ , extract it and copy it to SD card)
OS Installation:

           Connect your R-Pi devvice to HDMI tv using cable and supply power to the device. you will be displayed with list of OS that are available and that ready to install. Change your country and keyboard layout before you install Raspbian. Now select Raspbian as OS type and click on Install button which is on your top left. Once the installation has taken place it will prompt you to change few settings. Change your password and locality and click finish. Please change default start upp screen (option 2) so that need not provide startx command every time you login to your PI. Now your OS installation is done.

Connecting to WIFI:

Things Required:

  • Wifi dongle

Go to Preferences in Start and select WIFI configuration. Then click on scan button which brings list you  wifi connections that available. Double click on your wifi network and provide passcode in PSK and press connect.

Installing VNC server:

  Make sure  you are connected to network through Wifi or ethernet.

Log in to your Pi and install the Tight VNC Package, before installing make sure you get updates.

Follow below commands:

To update packages:

     Command : $ sudo apt-get updates 

To install VNC server :
   
   Command :  $ sudo apt-get install tightvncserver

Start VNC server using below command:
   Command : tightvncserver :1

Which will prompt you set a password and optional view only password. 

Now Install Tight VNC on your desktop from the link below:

http://www.tightvnc.com/download.php

Now after installation use your R-PI IP address followed by :: and then by your port number. To get IP address type ifconfig in your xterminal.  

So it should look like below. 

<Your Pi IP> ::590* or Your hostname::590*
 e.g.: 192.168.1.129::5901
* here tells you display number. So you should give display number as your port number.

Now try to connect from your client machine providing above mentioned details, which will ask you to provide password. Now you should be able to see your desktop.  


To run VNC server at start-up( boot ) ;

This is to run VNC server during boot process itself, so that we can connect to R-PI device with our laptop itself using VNC client.  

Below link would be help full to run VNC server during boot itself.

http://elinux.org/RPi_VNC_Server
















Monday, February 2, 2015

Internet of Things:

Imagine everything in the world connected with Internet and assume every object communicates with /reads other objects and reacts to them on its own . For say, your car communicates with cars those are already at location that you wish to travel and get availability of parking slots, Your refrigerators checks out of stock items and communicate to you, A sensor that saves lives by instant reporting about your health, Window shades on your house automatically comes down when sun sets and devices looking after you and come up with a plan that suits you for that days schedule. I would say it would be an automated world and this is Internet of things.  

With estimated 30 billion devices will be connected by internet by the year 2020, there is lot scope for this subject across all domains such as Agriculture,  Smart cities, logistics, Industries  and Health etc.

I'm here posting all my work and projects to complete my course "CSC9010 - Internet of Things" at Villanova University under guidance of Professor Paul Schragger.