Nipun Jyoti Pathak
Published

Bidirectional Visitor Counter System

This System measures the flow of people entering or leaving a room. Also gives information on how many people are inside the room.

IntermediateFull instructions provided1 hour645
Bidirectional Visitor Counter System

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
LED (generic)
LED (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE
Twilio API for WhatsApp
Twilio API for WhatsApp

Story

Read more

Schematics

Circuit Diagram of The System

Code

Arduino Code

Arduino
void(* resetFunc) (void) = 0; //declaring reset func at address 0
//defining the pins
#define trig2 5
#define echo2 6
#define trig1 7
#define echo1 8
#define entryLight 11
#define exitLight 9
#define GND 10

int  d1, d2, distance, i, j, p, q, a = 0;
long int duration;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(trig1, OUTPUT);
  pinMode(echo1, INPUT);
  pinMode(trig2, OUTPUT);
  pinMode(echo2, INPUT);
  pinMode(entryLight, OUTPUT);
  pinMode(exitLight, OUTPUT);
  pinMode(GND, OUTPUT);
}


void loop() {
  // put your main code here, to run repeatedly:
  a++;
  Ultrasonic(trig1, echo1);
  d1 = distance;

  Ultrasonic(trig2, echo2);
  d2 = distance;

  if(d1 <= 20)
  {
    digitalWrite(entryLight, HIGH);
    i++;
    if(i == 1)
    {
      p++;
    }
    else
    {
      p;
    }
  }
  else
  {
    i = 0;
    digitalWrite(entryLight, LOW);
  }
  if(d2 <= 20)//if distance is less than or equal to 20
  {
    digitalWrite(exitLight, HIGH);//
    digitalWrite(GND, LOW);
    j++;
    if(j == 1)
    {
      q++;
    }
    else
    {
      q;
    }
  }
  else
  {
    j = 0;
    digitalWrite(exitLight, LOW);
    digitalWrite(GND, LOW);
  }
  // Serial.println(p);
  // Serial.println(q);
  if((p - q) < 0)
  {
    resetFunc();    
  }
  if(a%200 == 0) //print after every 20 seconds
  {
    Serial.print("Persons Entered = ");
    Serial.print(p);
    Serial.print(", Persons Exit = ");
    Serial.print(q);
    Serial.print(", Total Persons in the Room = ");
    Serial.println(p - q);
  }
  delay(100);
}



void Ultrasonic(int trig, int echo)
{
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = 0.034 * duration/2;
}

Python Code

Python
from boltiot import Bolt, Sms #Import Sms and Bolt class from boltiot library
import json, time, datetime

SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'whatsapp:This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'whatsapp:This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'


bolt = Bolt(API_KEY, DEVICE_ID)
sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)
while True:
    data = json.loads(bolt.serialRead('10'))['value']
    print(data) 
    try:
        print("Sending message...")
        response = sms.send_sms(data)
        time.sleep(10)
    except Exception as e:
        print("Error occurred: Below are the details")
        print(e)
    time.sleep(10)

Credits

Nipun Jyoti Pathak

Nipun Jyoti Pathak

2 projects • 1 follower
I am pursuing B.Tech in Electrical Engineering. I am still learning about machine learning, neural networks, IoT and game development.

Comments