Monil Patel
Published © GPL3+

Smart Parking System

A system that can be used by users that allows them to view the available parking spaces through a website in huge parking lots.

IntermediateProtip1,575
Smart Parking System

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT

Story

Read more

Schematics

Schematics

Code

The website

HTML
<html>
	<head>
		<title>Parking System</title>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
		<script src="action.js"></script>
		<style>
			.c1{
				padding:50px;
				text-decoration:underline;
				font-size:25px;
				font-weight:bold;
				color:darkblue;
			}
			h1{
				padding:10px;
				color:lightblack;
			}
			table{
				left-margin-left:50px;
			}
			td{
				text-align:center;
				color:white;
			}
			body{
				background-image:url("pics/bg2.jpg");
				background-size: cover;
				background-repeat: no-repeat;
				background-attachment: fixed;
				width:100%;
		}
		
		div{
			margin-left:800px;
		}
		
		.c2{
			color:black;
			font-size:20px;
			font-weight:bold;
		}
		
		</style>
	</head>
	<body>
		<center>
			<h1>Parking Slots Booking</h1>
		</center>
		<div>
			<table>
					<tr>
						<td class="c1">Slots</td>
						<td class="c1">Status</td>
						<td class="c1">Book</td>
					</tr>
					<tr>
						<td class="c2">S1</td>
						<td id="a1" style="background-color:lightgreen;color:white">AVAILABLE</td>
						<td><input id="b1" type="button" value="Book Slot"></button></td>
					</tr>
					 
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
					
					<tr>
						<td class="c2">S2</td>
						<td id="a2" style="background-color:lightgreen;color:white">AVAILABLE</td>
						<td><input id="b2" type="button" value="Book Slot"></button></td>
					</tr>	
					
					
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
					
					<tr>
						<td class="c2">S3</td>
						<td id="a3" style="background-color:lightgreen;color:white">AVAILABLE</td>
						<td><input id="b3" type="button" value="Book Slot"></button></td>
					</tr>
			</table>
		</div>
	</body>
</html>

Ultrasonic Sensor code

Python
run this code in your raspberry pi
#Libraries
import RPi.GPIO as GPIO
import time

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

#set GPIO Pins
GPIO_TRIGGER1 = 18
GPIO_ECHO1 = 24
GPIO_TRIGGER2 = 21
GPIO_ECHO2 = 16
GPIO_TRIGGER3 = 26
GPIO_ECHO3 = 19


GPIO.setwarnings(False)
#set GPIO direction (IN / OUT)
GPIO.setup(GPIO_TRIGGER1, GPIO.OUT)
GPIO.setup(GPIO_ECHO1, GPIO.IN)
GPIO.setup(GPIO_TRIGGER2, GPIO.OUT)
GPIO.setup(GPIO_ECHO2, GPIO.IN)
GPIO.setup(GPIO_TRIGGER3, GPIO.OUT)
GPIO.setup(GPIO_ECHO3, GPIO.IN)

def distance(GPIO_TRIGGER,GPIO_ECHO):
    # set Trigger to HIGH
    GPIO.output(GPIO_TRIGGER, True)

    # set Trigger after 0.01ms to LOW
    time.sleep(0.00001)
    GPIO.output(GPIO_TRIGGER, False)

    StartTime = time.time()
    StopTime = time.time()

    # save StartTime
    while GPIO.input(GPIO_ECHO) == 0:
        StartTime = time.time()

    # save time of arrival
    while GPIO.input(GPIO_ECHO) == 1:
        StopTime = time.time()

    # time difference between start and arrival
    TimeElapsed = StopTime - StartTime
    # multiply with the sonic speed (34300 cm/s)
    # and divide by 2, because there and back
    distance = (TimeElapsed * 34300) / 2

    return distance





if __name__ == '__main__':
    try:
        while True:
            #dist = distance()
            dist1 = distance(GPIO_TRIGGER1,GPIO_ECHO1)
            
            state1 = 0
        
            #print ("Measured Distance = %.1f cm" % dist1)
            if dist1 < 5:
                print ("slot1 : In use")
            else :
                print ("slot1 : Empty")
                
            dist2 = distance(GPIO_TRIGGER2,GPIO_ECHO2)

            if dist2 < 5:
                print ("slot2 : In use")
            else :
                print ("slot2 : Empty")
            dist3 = distance(GPIO_TRIGGER3,GPIO_ECHO3)  
            if dist3 < 5:
                print ("slot3 : In use")
            else :
                print ("slot3 : Empty")


            print("--------------------------------------------------------------------------")
            time.sleep(1)
            
        # Reset by pressing CTRL + C
    except KeyboardInterrupt:
        print("Measurement stopped by User")
        GPIO.cleanup()

Credits

Monil Patel

Monil Patel

0 projects • 0 followers

Comments

Add projectSign up / Login