People commonly refer to an electronic system that counts the number of people entering a place as a people counter. Retail stores, museums, event venues, and other public spaces often use these systems to monitor traffic and track how many individuals enter or exit a location. These systems are valuable for managing crowd control, analyzing customer behavior, and optimizing operational efficiency.
Objective
At the end of this experiment, you will be able to implement a people counter system to enable you to monitor the number of people entering a place.
Components to use
Circuit diagram
Figure: Schematic diagram
Figure: Components used to make connection on the board
Arduino codes
Code knowledge
This code sets up a simple counter system using a push button and an LCD screen. When you press the button, the program increments the counter value and displays it on both the Serial Monitor and the LCD screen. Here’s a detailed, step-by-step explanation:
ezButton.h: Provides functions to manage button presses, including “debouncing,” which helps filter out false triggers due to noise.
button(6): Sets up a button on pin D6 of the Ardunino. The ezButton library simplifies handling button presses.
prev_count: Stores the last recorded button press count to detect changes in the button press count.
button.setDebounceTime(50):This sets the debounce time for the button to 50 milliseconds. Purpose: “Debouncing” handles the “bouncing” effect that happens when you press or release a mechanical button. Without debouncing, the Arduino might read multiple presses for a single button push. Setting a debounce time of 50 milliseconds ensures the button stays in a stable state for at least 50 milliseconds before the program counts it as a valid press. This prevents accidental multiple counts for a single press.
button.setCountMode(COUNT_FALLING); This line sets the button’s count mode to COUNT_FALLING.
COUNT_FALLING means the button counts only when it changes from a HIGH state to a LOW state–when you release it after pressing. This setting ensures the program counts each press once upon release, instead of multiple times while you hold the button down.
Step 4: Loop Function
button.loop(): This line must run every time through the loop to update the button state. It tracks any changes in button press status.
count = button.getCount() retrieves how many times the user has pressed the button.
if (prev_count != count): Checks if the current button press count differs from prev_count.
If the count increases (indicating a new button press)…
- Serial.println(count): Displays the updated count on the Serial Monitor.
- lcd.clear(): Clears the LCD screen to prepare for a new message.
- lcd.setCursor(0, 0): Moves the cursor to the start of the first row.
- lcd.print(“Count: “) and lcd.print(count): Displays “Count: ” followed by the updated count value.
prev_count = countupdatesprev_countto match the latest count, allowing the program to detect the next button press as a new change.
Results
The provided code uses an LCD and the ezButton library to count button presses and display the count both on the serial monitor and the LCD.
Expected Outputs
Serial Monitor Output:
The serial monitor displays a message each time you press and release the button:
1 2 3 …
LCD Output:
The LCD shows the current count:
Count: 1
After the next button press:
Count: 2
In summary:
- Visible Output: The LCD shows “Count: X”, where X is the updated button press count.
- Serial Monitor Output: Each button press updates the count and prints it to the monitor.
This program effectively tracks button presses and displays the count in real-time