Rucksikaa Raajkumar
Published © CC BY

Limit the crowd to prevent the spread of COVID-19

A cheap and effective method to limit the crowd in public places - such as shopping malls, supermarkets, etc - and public transport vehicles

BeginnerFull instructions provided2 hours8,695
Limit the crowd to prevent the spread of COVID-19

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
You will only be needing the power rail of this breadboard
×1
IR tracking sensor module
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Could be used instead of the IR tracking sensor module
×2
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Connections

Connections (2)

Arduino Uno microcontroller board

Code

Code

Arduino
You will be needing the Wire, Servo and LiquidCrystal_I2C libraries for this project. Wire and Servo libraries are inbuilt but the LiquidCrystal_I2C library should be downloaded. The link will be provided in the comments section below.
// LIMIT THE CROWD TO PREVENT THE SPREAD OF COVID-19
// ARDUINO PROJECTS BY R
// AUTHOR: RUCKSIKAA RAAJKUMAR
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
#define trig 4
#define echo 3
const int out_sensor=5;
int out_state;
Servo servo;
LiquidCrystal_I2C lcd(0x27,16,2);
int count; // Variable to store the number of people inside
int limit = 15; // The maximum occupancy 
long duration;
int distance;
void setup() { // put your setup code here, to run once:
  pinMode(out_sensor, INPUT); // Configure the pin of the IR tracking sensor as INPUT
  pinMode(trig, OUTPUT); // Configure the trig pin of the Ultrasonic sensor module as OUTPUT as it emits ultrasonic waves (pulse)
  pinMode(echo, INPUT); // Configure the echo pin of the echo pin as INPUT
  Serial.begin(9600);
  servo.attach(9); // Servo motor is connected to D9
  servo.write(0); // Set the initial position of servo motor as 0 degrees.
  lcd.begin();
}
void loop() { // put your main code here, to run repeatedly:
  if(count==limit){ // If maximum occupancy is reached
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("Max. occupancy");
    lcd.setCursor(5,1);
    lcd.print("reached");
  }else{ // If maximum occupancy is not reached
    lcd.clear();
    lcd.print("No. of people=");
    lcd.print(count);
  }
  digitalWrite(trig, LOW);
  delayMicroseconds(5);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH); // Calculate time taken (in microseconds) for the pulse emitted by the trigger pin to reach the echo pin.
  distance = (duration/2) * (331.3/10000); // Calculate the distance from the sensor to the obstacle in cm, using the speed of sound in air(m/s) and the time taken (stored in duration variable)
  Serial.println(distance);
  out_state=digitalRead(out_sensor); 
  Serial.println(count);
  if(out_state==LOW){ // If anyone hovers over the IR sensor
    count--; // Value stored in count variable will be decreased by one as the person is exiting the building or vehicle
    servo.write(90); 
    delay(5000); // Door will remain open for 5 seconds
    servo.write(0);
    if(count<0){
      count=0;
    }
  }
  if(distance<5){
    if(count>limit){ // If value stored in count variable is greater than maximum occupancy
      lcd.clear();
      lcd.print("You can't enter");
      lcd.setCursor(6,1);
      lcd.print("now");
      delay(2000);
    }else{
      count++; // Count will increase by one as a person is entering
      servo.write(90);
      delay(5000);
      servo.write(0);
    }
  } 
}

Credits

Rucksikaa Raajkumar

Rucksikaa Raajkumar

43 projects • 93 followers
Amateur Arduino Developer. Undergraduate. YouTuber (https://www.youtube.com/c/RucksikaaRaajkumar/videos) and Blogger (Arduino Projects by R)

Comments