ESP8266/IoT B.Tech/Diploma Beginner

IoT Bidirectional Visitor Counter using ESPP8266 & MQTT

IoT IR Based Bidirectional Visitor Counter using NodeMCU ESP8266 & MQTT Cloud Ubidots. Count number of visitor using IR Sensor & NodeMCU Code

  • Suitable forB.Tech/Diploma ESP8266/IoT students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview: IoT Visitor Counter
In this project, we will make
IoT IR Based Bidirectional Visitor Counter
using
NodeMCU ESPP8266
&
Ubidots MQTT
. You can use this project for monitoring the total number of incoming, outgoing, and current visitors online from any part of the world using
Ubidots Dashboard
. To count the incoming and outcoming visitors, it is better to use an
Infrared
or
IR Sensor
. The Visitors data uploads automatically to Ubidots cloud using the NodeMCU ESP8266 WiFi Module.
You can use this
NodeMCU Bidirectional Visitor counter
in the hall, Shopping mall, office, functions in the entrance gate to count the total number of visitors. The device counts the total number of people entering through the gate & also counts the total number of people leaving through the different gates. And finally, it calculates the
total
number of current people by subtracting the outgoing visitor from the incoming visitor. When even a single person is found inside the room, the light turns
on
automatically. When no people are present in the room, the light turns
off
automatically.
In one of my previous projects, I made the
Visitor Counter Project using Arduino
. But this time we will send the data to the cloud instead of watching it on
OLED Screen
. We can make this IoT Visitor Counter using
ESP8266 Wifi Module
, a pair of
IR Sensor
OLED Display
, and a
Relay Module
. Apart from these main components we also need some passive
electronic components
& PCB Board. The project is simply easy and even a beginner can make it without any difficulty.
Bill of Materials
The list of
components
that you need for making IoT Bidirectional Visitor Counter are as follows. You can purchase all the components online from Amazon.
S.N.
Components Name
Quantity
Purchase Links

NodeMCU ESP8266 Board

Amazon
AliExpress

IR Sensor Module

Amazon
AliExpress

0.96" I2C OLED Display

Amazon
AliExpress

1 Channel Relay Module

Amazon
AliExpress

5V Power Supply

Amazon
AliExpress
IR Sensor as Visitor Detector
The main element of this IoT project is the
IR Sensor
which works as a
Obstacle Detector
. Whenever the IR sensor detects an interrupt it counts the person and adds it to the previous value.
IR Sensor module
has the great adaptive capability of the
ambient light
. It has an infrared transmitter and a receiver. The
infrared emitting
tube emits a certain
frequency
which when encounters an obstacle reflect back to the signal. The
reflected signal
is then received by the receiver tube. The other components in the circuit are
Opamp, Variable Resistor
&
output LED
The Sensor consists of the following electronics components.
1. IR LED Transmitter
IR LED
emits light, in the range of Infrared frequency with a wavelength of
700nm – 1mm
. IR LEDs have a light-emitting angle of approx.
20-60 degrees
and has a range up to
5-10cm
2. Photodiode Receiver
Photodiode
acts as the
IR receiver
as its conducts when light falls on it. Photodiode looks like a LED, with a
black color
coating on its outer side.
3. LM358 Opamp
LM358
is an
Operational Amplifier (Op-Amp)
used as a
voltage comparator
in the IR sensor. The comparator circuit compares the
threshold voltage
set using the preset and the photodiode’s series resistor voltage. When the Photodiode’s series resistor voltage drop is greater than the threshold voltage, the Op-Amp output is
high
or vice-versa.
When the Op-Amp output is high the LED at the output terminal turns ON. This indicates an object detection.
4. Variable Resistor
The
variable resistor
here is preset. It is used to
calibrate
the distance range at which the object should be detected.
IoT Bidirectional Visitor Counter Circuit or Schematic
The Circuit for NodeMCU ESP8266 Bidirectional Visitor Counter is very simple. Here is a circuit diagram for the project. You can design the schematic using a
Fritzing
Software.
Connect the I2C Pins (SDA & SCL) of 0.96″ OLED Display with NodeMCU D2 & D1 Pins. Connect the output pin of the pair of IR Sensors to D5 & D6 of NodeMCU. One of the IR Sensors will act as the incoming visitor counter and the other as the outgoing visitor counter. Similarly, connect a 5V Relay Module to the D4 Pin of NodeMCU. Both the IR Sensors and Relay Module works at 5V VCC. You can supply 5V from
Amica NodeMCU Vin
pin or
Lolin NodeMCU VU
Pin.
Schematic & PCB Designing
You can assemble and try this circuit on breadboard. But if you don’t want to assemble the circuit on
breadboard
, then you can check this schematic and build a custom PCB. I prefer
EasyEDA
, an online
Schematic
&
PCB Designing Tool
for drawing the Schematic.
After designing the ESP8266 Bidirectional Visitor Counter Schematic, you can convert the schematic to PCB. The PCB looks something like this shown in the image below.
PCB Ordering & Assembly
The Gerber File for IoT IR Based Bidirectional Visitor Counter with Light Control PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File:
IoT IR Based Visitor Counter PCB
You can use this Gerber file to order high quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
After a week, I got the PCB. The PCB quality is superb and has a very high Finish.
I then assembled all the components on the PCB. The PCB board along with the mounted component makes the final hardware perfect. Now we need to test the device along with the code.
Setting Up Ubidots
We need to setup the
Ubidots dashboard
in order to recieve the Visitor Counter data from ESP8266 MQTT. In order to set up Ubidots, visit
https://ubidots.com/
& create a
New Account
using your email address.
After
into Ubidots Dashboard, we need an
API Key
. To get the API key, click on the top right of the dashboard on the profile option. You will see an option called
“API Credentials”
. Click on the option.
Now when you click on
Default Token
and copy the
API Token
. You need an API Token in the code part to receive the data.
Source Code/Program
The
for esp8266 Bidirectional Visitor Counter with Automatic Light Control System is given below. The code requires
SSD1306 & GFX OLED library
for compilation and
Ubidots Library
. First download the following libraries and add it to the Arduino IDE.
1. Download SSD1306 Library:
https://github.com/adafruit/Adafruit_SSD1306
2. Download Adafruit GFX Library:
https://github.com/adafruit/Adafruit-GFX-Library
3. Download Ubidots MQTT Library:
https://github.com/ubidots/ubidots-mqtt-esp
From this code part, change the
Wifi SSID, Password
&
Ubidots Token
. Use the same
API Token
. Some of the networks don’t work with
MQTT Protocol
because of the Security issue. You can try another network if the device fails to connect to the M
QTT Server

#define TOKEN "*********************************" // Your Ubidots TOKEN
#define WIFINAME "************" //Your SSID
#define WIFIPASS "*************" // Your Wifi Pass
You can now copy the
code
and
upload
it to the NodeMCU ESP8266 Board.

#include "UbidotsESPMQTT.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafrui

Technologies used

ESP8266ArduinoMQTTWiFiBLESSD1306OLEDRelayI2CSPIArduino IDE

Hardware components

  • ESP8266
  • Arduino
  • SSD1306
  • OLED
  • Relay
  • LM35
  • IR Sensor

Software & tools

  • Arduino IDE
  • MQTT
  • EasyEDA
  • Fritzing

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.