people counter in a room with single door

I want to make a people counter of my room , which can count how many peoples are present in the room. In this case want to use two “HC-SR04” ultra sonic sensor .

i tried a tutorial on youtube link- Automatic lighting control using Arduino - YouTube
The source code of that tutorial is -

#include <NewPing.h>

int us1Pin = 13;
int us2Pin = 2;
int relayPin = 12;

#define MAX_DISTANCE 150



class USSensor {
public:
  USSensor(int trigPin, int echoPin, String aName) {
    trig = trigPin;
    echo = echoPin;
    sonar = new NewPing(trigPin, echoPin, MAX_DISTANCE);
    isActivated = false;
    name = aName;
    time = 0;
  }
  
  void update() {
    updateSensor();
    if (value < 100) {
      setActive(true);
    } else {
      if (millis() - time > 500) {
        setActive(false);
      } 
    }
  }
  
  void reset() {
    setActive(false);
    time = 0;
  }
  
  void setActive(boolean state) {
    if (!isActivated && state) {
      time = millis();
    }
    if (isActivated != state) {
      isActivated = state;
      Serial.print(name + ": ");
      Serial.println(state);
    }
  }
  
  boolean wasActive() {
    return (time != 0) && !isActivated;
  }
  
  int lastActive() {
    return millis() - time;
  }
  
private:
  int trig;
  int echo;
  int led;
  String name;
  boolean isActivated;
  unsigned long time;
  float value;
  NewPing *sonar;
  
  void updateSensor() {
    
    delay(25);
    unsigned int uS = sonar->ping();
    value = uS / US_ROUNDTRIP_CM;
    
//    delay(5);
//    pinMode(trig, OUTPUT);
//    digitalWrite(trig, LOW);
//    delayMicroseconds(50);
//    digitalWrite(trig, HIGH);
//    delayMicroseconds(200);
//    digitalWrite(trig, LOW);
//    pinMode(echo, INPUT);
//    int pulseLen = pulseIn(echo, HIGH);
//    float currentValue = pulseLen / 29.387 /2; // [voloshyn] convert into cm
//    if (value == 0.0f) value = currentValue;
//    else value = (value + currentValue) / 2;
//    value = pulseLen / 29.387 /2; // [voloshyn] convert into cm
  }
};

int peopleInRoom = 0;
USSensor *A;
USSensor *B;

void setup() {
  Serial.begin(9600);
  A = new USSensor(us1Pin, us1Pin, "A");
  B = new USSensor(us2Pin, us2Pin, "B");
  pinMode(relayPin, OUTPUT);
}

void loop() {
  
    A->update();
    B->update();
    
    if (A->wasActive() && B->wasActive()) {
      int a_time = A->lastActive();
      int b_time = B->lastActive();
      if (a_time < 5000 && b_time < 5000) {
        if (a_time > b_time) {
          peopleInRoom++;
        } else {
          peopleInRoom--;
        }
        Serial.print("People in room: ");
        Serial.println(peopleInRoom);
      }
      A->reset();
      B->reset();
    }

    if (peopleInRoom < 0) { // [voloshyn] in case when someone was already in the room when system was activated
      peopleInRoom = 0;
    }
    
    if (peopleInRoom > 0) {
      digitalWrite(relayPin, HIGH);
    } else {
      digitalWrite(relayPin, LOW);
    }
}

the problem is that , i can’t understand in which pins i attach two sensors ??

int us1Pin = 13;
int us2Pin = 2;

which pins will be the ECHO pin and which pin will be the TRIG pin for two sensor ??

please help me

which pins will be the ECHO pin and which pin will be the TRIG pin for two sensor ?

Whichever pins you attach the sensor to.

I have two sensors so i have 2 ECHO pins and 2 TRIG pins , but in the code only two variables are declared :( :(

int us1Pin = 13;
int us2Pin = 2;

i need four variables for two sensors , but in the code there is only two variable . What i'm saying if you just look this video https://www.youtube.com/watch?v=udaxZ0VGkO4

and if possible please help me with the circuit diagram

but in the code only two variables are declared

The answer to which seems to me to be "declare two more constants"

Hi,

Say you have to have double of everything (two trigger, two echo, etcetera).

Regards

The code only supports one sensor , but you have two. If you are going to use two sensors your code needs to read both ECHO pins, but not at the same time.

hi saddam2k9 ... you fix the code ? are you using? Try to do this, forcing the trigger...

int us1Pin = 13; int us2Pin = 2; int ust1Pin = 11; int ust2Pin = 10; int relayPin = 12; . . .

void setup() { Serial.begin(9600); A = new USSensor(ust1Pin, us1Pin, "A"); B = new USSensor(ust2Pin, us2Pin, "B"); pinMode(relayPin, OUTPUT);