People Counter Using Ultrasonic Sensors and Arduino

by STEAM-DIY in Circuits > Arduino

53 Views, 0 Favorites, 0 Comments

People Counter Using Ultrasonic Sensors and Arduino

t725.png

The idea behind this project is to build a basic people-counting system. Using two HC-SR04 ultrasonic sensors, the system tracks when people enter or exit a room. This information is displayed on an LCD, which also encourages more visits if no one is inside. It can be used for various practical applications like managing room capacity in a small office or monitoring foot traffic in an exhibition.

The project is built using Arduino, making it a great entry-level electronics project. Whether you are new to Arduino or an experienced user, this project provides a hands-on learning experience with sensors, coding, and basic electronics.

Supplies

1x Arduino Uno

2x HC-SR04 Ultrasonic Sensors

1x 16x2 LCD Display

1x Potentiometer (10k Ohms) for contrast adjustment

1x Breadboard

Jumper wires

1x USB cable to connect Arduino to a computer

1x Power supply (if necessary)

Step 1: Set Up the Components

Begin by assembling your components. The Arduino will act as the brain of the system, and the ultrasonic sensors will detect the movement of people entering or leaving. The LCD screen will display the count and a message, such as "People In: X" and "Please Visit!" when the room is empty.

Wiring the Components:

  1. Connect the ultrasonic sensors to the Arduino as follows:
  2. VCC to 5V
  3. GND to GND
  4. Trigger Pin to Arduino pin 9 (for sensor 1) and pin 10 (for sensor 2)
  5. Echo Pin to Arduino pin 11 (for sensor 1) and pin 12 (for sensor 2)
  6. Wire the LCD display to the Arduino using the I2C interface or direct wiring method:
  7. VCC to 5V
  8. GND to GND
  9. SCL to pin A5 (I2C pin)
  10. SDA to pin A4 (I2C pin)
  11. Add a potentiometer to control the contrast of the LCD display.
  12. Use a breadboard and jumper wires to complete the circuit.


Step 2: Upload the Code

Now, you’ll need to upload the code to the Arduino. You can use the following sketch as a starting point: #include <LiquidCrystal.h>


const int trigPin1 = 9;

const int echoPin1 = 11;

const int trigPin2 = 10;

const int echoPin2 = 12;

int peopleCount = 0;


LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


void setup() {

pinMode(trigPin1, OUTPUT);

pinMode(echoPin1, INPUT);

pinMode(trigPin2, OUTPUT);

pinMode(echoPin2, INPUT);

lcd.begin(16, 2);

lcd.print("People In: ");

lcd.print(peopleCount);

lcd.setCursor(0, 1);

lcd.print("Please Visit!");

}


void loop() {

long duration1, duration2;

// Reading from sensor 1 (entrance)

digitalWrite(trigPin1, LOW);

delayMicroseconds(2);

digitalWrite(trigPin1, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin1, LOW);

duration1 = pulseIn(echoPin1, HIGH);

int distance1 = duration1 * 0.034 / 2;

// Reading from sensor 2 (exit)

digitalWrite(trigPin2, LOW);

delayMicroseconds(2);

digitalWrite(trigPin2, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin2, LOW);

duration2 = pulseIn(echoPin2, HIGH);

int distance2 = duration2 * 0.034 / 2;


// Logic for counting people based on distance thresholds

if (distance1 < 20) { // Someone enters

peopleCount++;

updateLCD();

}

if (distance2 < 20) { // Someone exits

peopleCount--;

updateLCD();

}

delay(1000); // Delay to prevent multiple readings for one person

}


void updateLCD() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("People In: ");

lcd.print(peopleCount);

if (peopleCount == 0) {

lcd.setCursor(0, 1);

lcd.print("Please Visit!");

}

}


Step 3: Test Your Project

Once your code is uploaded, place your sensors near a doorway to detect people entering and exiting. The LCD should update the count accordingly. Adjust the distance thresholds if necessary to make the system more accurate.

Conclusion


This Arduino people counter project is a fun way to explore the world of sensors and real-time displays. You can modify the code to add more features like notifications or alarms. With a few simple components, you now have a functional counter that can be applied in various real-life situations. Be sure to experiment with different sensor placements and LCD messages to personalize your project.