IoT Based Smart Parking System Using NodeMCU ESP8266
IoT Based Smart Parking System Using NodeMCU ESP8266
IoT Based Smart Parking System Using NodeMCU ESP8266
ESP8266
Now days finding parking in busy areas is very hard and there is no system to get the details of
parking availability online. Imagine if you can get the parking slot availability information on
your phone and you don’t have roaming around to check the availability. This problem can be
solved by the IoT based smart parking system. Using the IoT based parking system you can
easily access the parking slot availability over the internet. This system can completely
automate the car parking system. From your entry to the payment and exit all can be done
automatically.
So here we are building an IOT based Car Parking System using NodeMCU, five IR sensors,
and two servo motors. Two IR sensors are used at entry and exit gate to detect the car while
three IR sensors are used to detect the parking slot availability. Servo motors are used to open
and close the gates according to the sensor value. Here we are using the Adafruit IO platform to
show publish the data on cloud which can be monitored from anywhere in the world.
Components Required
Hardware
NodeMCU ESP8266
IR Sensor (5)
Servo Motor (2)
Online Services
Adafruit IO
Circuit Diagram
The circuit diagram for this IoT based smart parking system project is given below.
In this Smart Parking System using IOT, we are using five IR Sensors and two servo motors. IR
sensors and Servo motors are connected to the NodeMCU. NodeMCU controls the complete
process and sends the parking availability and parking time information to Adafruit IO so that it
can be monitored from anywhere in the world using this platform. Two IR sensors are used at
entry and exit gate so that it can detect the cars at entry and exit gate and automatically open
and close the gate. We previously used Adafruit IO cloud in many IoT projects, follow the link to
learn more.
Two servo motors are used as entry and exit gate, so whenever the IR sensor detects a car, the
servo motor automatically rotates from 45° to 140°, and after a delay, it will return to its initial
position. Another three IR sensors are used to detect if the parking slot is available or occupied
and send the data to NodeMCU. Adafruit IO dashboard also has two buttons to manually
operate the entry and exit gate.
This is how this complete setup for Smart Parking System using IOT will look:
1. To use Adafruit IO, first, you have to create an account on Adafruit IO. To do this,
go to
2. the Adafruit IO website and click on ‘Get started for Free’ on the top right of the
screen.
2. After finishing the account creation process, log in to your account and click on ‘AIO Key’ on
the top right corner to get your account username and AIO key.
When you click on ‘AIO Key,’ a window will pop up with your Adafruit IO AIO Key and username.
Copy this key and username, it will be needed later in the code.
3. Now, after this, you need to create a feed. To create a feed, click on ‘Feed.’ Then click on
‘Actions,’ and then on ‘Create a New Feed’ as shown in the image below.
4. After this, a new window will open to enter the Name and Description of the feed. The writing
description is optional.
5. Click on ‘Create,’ after this; you will be redirected to your newly created feed.
For this project, we created a total of nine feeds for exit gate, entry gate, slot 1 entry & exit,
slot 2 entry & exit, and slot 3 entry & exit.
After creating feeds, now create an Adafruit IO dashboard to show all of these feeds on a single
page. To create a dashboard, click on the Dashboard option and then click on the ‘Action,’ and
after this, click on ‘Create a New Dashboard.’
In the next window, enter the name for your dashboard and click on ‘Create.’
6. As the dashboard is created now, we will add our feeds to the dashboard. To add a feed,
click on the ‘+’ in the top right corner.
First, we will add two RESET buttons blocks for Entry and Exit gate and then seven TEXT blocks
for parking details.
In this final step, give your block a title and customize it accordingly. Change the press value
from ‘1’ to ‘ON’. So whenever the button is pressed it will send the ‘ON’ string to NodeMCU, and
NodeMCU will perform the further task. If you don’t want to change the press value here than
you can change the condition in the program.
After this, follow the same procedure to create another block for the exit gate.
To create the rest of the blocks follow the same procedure, but instead of creating a RESET
block, create a TEXT block so that you can show the parking details.
After creating all the blocks, my dashboard looks like below. You can edit the dashboard by
clicking on the settings buttons
In Boards Manager window, Type esp in the search box, esp8266 will be listed there below. Now
select the latest version of the board and click on install.
First, include all the required libraries. ESP8266 Wi-Fi and Servo.h libraries are already installed
in the IDE. You can download the NTP client and Adafruit MQTT libraries from the below links:
NTPClient.h
Adafruit_MQTT.h
#include <ESP8266WiFi.h>
#include <Servo.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <NTPClient.h>;
#include <WiFiUdp.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
Then include the Wi-Fi and Adafruit IO credentials that you copied from the Adafruit IO server.
These will include the MQTT server, Port No, User Name and AIO Key
Set up the feed you're publishing to. Here Agriculture Data is the feed name.
…………………………………………..
…………………………………………..
Connect the Entry and Exit Servo Motor to the D4, D5 Pins of the NodeMCU, and select the out
pins of IR sensor as INPUT.
myservo.attach(D4);
myservos.attach(D5);
pinMode(carExited, INPUT);
pinMode(carEnter, INPUT);
pinMode(slot1, INPUT);
pinMode(slot2, INPUT);
pinMode(slot3, INPUT);
Inside the void loop, timeClient.update() function is used to update the date and time whenever
we request to NTP servers. After getting the data, we store the hour, minute and second in
three different integers.
timeClient.update();
hh = timeClient.getHours();
mm = timeClient.getMinutes();
ss = timeClient.getSeconds();
Digitally read the entry and exit IR sensor pins and check if these pins are high. If pins are high,
then move the servo motor to open the entry and exit gate. Then increase the count for entry
gate and decrease the count for exit gate and publish the data to the Adafruit IO dashboard.
myservos.write(OPEN_ANGLE);
delay(3000);
myservos.write(CLOSE_ANGLE);
myservo.write(OPEN_ANGLE);
delay(3000);
myservo.write(CLOSE_ANGLE);
if (! CarsParked.publish(count)) {}
Check the slot 1 IR sensor. If it is ‘1’ and Boolean function is false, then get the entry time from
the NTP server and save it in EntryTimeSlot1 variable. Publish the variable data to the Adafruit
IO feed.
s1_occupied = true;
If the IR sensor pin change to zero and Boolean function is true then publish the exit time to
Adafruit IO feed.
s1_occupied = false;
if (! ExitSlot1.publish((char*) ExitTimeSlot1.c_str())){}
s2_occupied = true;
if (! EntrySlot2.publish((char*) EntryTimeSlot2.c_str())){}
s2_occupied = false;
if (! ExitSlot2.publish((char*) ExitTimeSlot2.c_str())){}
s3_occupied = true;
if (! EntrySlot3.publish((char*) EntryTimeSlot3.c_str())){}
s3_occupied = false;
if (! ExitSlot3.publish((char*) ExitTimeSlot3.c_str())){ }
Here we are directly checking for a specific word in our subscribed feed, and if the word
matches with our specified word, i.e., ‘ON,’ it will rotate the servo motor to open the gate.
if (subscription == &EntryGate)
Serial.println((char*) EntryGate.lastread);
myservos.write(OPEN_ANGLE);
delay(3000);
myservos.write(CLOSE_ANGLE);
}
This is how the parking details are published on the Adafruit IO dashboard. It will show the
entry time and exit time for every slot. This dashboard also has two buttons to manually open
the entry and exit gate.
So this is how a Smart Parking System using IoT can be built. You can add more sensors to
increase the parking slots and can also add a payment system to automatically pay the parking
fee. Comment below if you have any doubts regarding this project.