1. Blog>
  2. Bidirectional Visitor Counter using Arduino and SD Card Module

Bidirectional Visitor Counter using Arduino and SD Card Module

by: Jan 05,2021 6022 Views 0 Comments Posted in Activities

Visitor Counter arduino SD card LDR LCD

Overview:

In this project we are going to construct a bidirectional visitor counter circuit using Arduino which registers the number of people who made entry and exit at schools, library, offices, commercial buildings etc. in a given period of time, set by an operator and automatically stores the data in a SD at the instant of closing with date and time. 

The circuit detects people with the help of LDR and laser setup at entry and exit points. When a person passes through an entry / exit point the laser gets interrupted and the microcontroller registers a count. The circuit also sport automatic recovery feature where in case of power failure the counts are recovered from EEPROM memory. 

There are four push buttons provided in this circuit where an operator can set the staring and closing time and apart from this there are 4 LED indicators and a buzzer which helps in conforming a count has been registered when a person passes through an entry / exit point. 

Circuit diagram:

Circuit description:

LDR and Laser setup:

The proposed project utilizes laser beam and LDR to detect the passage of a person. The LDR is mounted inside a black hollow tube with minimum of 5 cm in length and less than or equal to 1.5 cm in diameter. The tube will prevent ambient light sources hitting the LDR. 

A laser module should be placed opposite to LDR with proper alignment as shown below:

We need to make two such setups, one at the entry point and another one at exit point. People must come inside a room / building through the entry point and must exit though the exit point.

The LDR is connected to a “logic NOT gate” IC 7404 with a pull-up resistor 10K. The IC 7404 is here to output a proper digital signal to Arduino by receiving a noisy LDR input. 

Pin diagram of IC 7404:

During idle state the laser beam hits the LDR and pin 1 will turn logic LOW in case of LDR IN and pin 3 in case of LDR OUT. The output of NOT gates will be turned HIGH which is complement to the input signal. 

When a person blocks the laser beam momentarily the LDR’s resistance will rises and pins 1 & 3 are no longer fully connected to GND (logic LOW) and since a pull-up resistor is connect at input pins 1 and 3 of IC 7404, it will be pulled to logic HIGH and the output of NOT gates (pins 2 & 4) will turn LOW.  

The Arduino pins 2 and 3 are configured as interrupts, an interrupt is generated when the voltage level turns from high to low and a count is incremented internally in the microcontroller.  

……and that’s how Arduino detects a passage of a person at entry and exit points.

SD card module:

The collected data during closing time is stored to a SD card, but interfacing Arduino to a SD card is not that straight forward until you use a SD card module using which you can easily interface a SD to any variant of Arduino.

A SD card module is illustrated in the above image. The SD card must be inserted in its socket in the correct direction and the pins that connect to Arduino are labeled at the backside. 

The module can be supplied with 5V, however the SD card operates only at 3.3V, fortunately the module comes with an on-board 3.3V regulator to supply 3.3V to the SD card. The module also comes with a level shifter IC which takes 5V signal from Arduino or any other microcontroller and converts it to 3.3V signal which is compatible with the SD card; otherwise 5V will kill it. 

The SD card utilizes SPI protocol to communicate with Arduino and generates a text file containing data of entry and exit count with date and time. An operator has to insert the SD card to his/her computer to read the data. The logged data is illustrated in the below image:

In the above image we can see the date, time, number of people who came in and out and the remaining number of people who did not exit during closing time. 

The time 00:00:00 is the starting hour and 23:59:59 is the closing hour which I have set and only when the clock hits closing time a new data will be logged to this text file.

Real Time Clock (RTC):

RTC clock module is responsible for tracking the time accurately. The clock modules we can use are DS3231 and DS1307, our recommendation is DS3231 since it can track time accurately when compare to DS1307. 

DS3231 RTC has a temperature compensated crystal which is built-in to the IC, whereas DS1307 has an external crystal which is susceptible external temperature and physical force by a huge margin, because of this DS3231 is far more accurate when it comes to tracking time.

DS3231 / DS1307 utilizes I2C protocol to communicate with Arduino, it can track time and date up to year 2100 with leap year compensation and it comes with a 3V coin cell which keep the RTC running even when you disconnect the main power supply to the circuit and it can run on the coin cell for more than 2 years.

How to set time to RTC DS3231 / DS1307:

1) In the program code please uncomment the following section:

2) Press upload after you enter the correct day, time and date in the first three lines respectively.

3) Once you upload the code, you will see date and time on the display. Now disconnect the power for 10 seconds and reconnect it, you should see correct date and time are displayed and running.

4) Now uncomment the code again and press upload for normal operation.

I2C display adapter:

This project utilizes an I2C LCD adapter module which is connected to a 16 x 2 LCD display. The I2C LCD module helps the project to prototype it quickly by reducing the number of wires that connects from LCD to four; otherwise we have to connect a bunch wires from Arduino to LCD.

It utilizes I2C protocol hence its name and can be soldered on the back of the LCD or can be connected on a breadboard as illustrated in the above image. It shares the same I2C bus as RTC does. Use the on-board trim potentiometer to adjust the contrast of the display. 

Buttons, LED and buzzer:

  • Buttons:

There are 4 push buttons provided to set start time and end time. The machine will operate only for the time period between you have set.

  • LED and Buzzer:

There are 4 LEDs provided in the circuit, two (red and green) for entry point and the other two are for exit point. When the green LED lights up, the entry / exit points are active and people may pass through one at a time. 

When a person passes though, the green LED turns OFF and red LED glows momentarily and beeps, indicating that a count has been registered and until the red LED turns OFF and green LED turns back ON, no one should pass through the point. 

Please note that entry and exit points are counted independently so people can come in and go out simultaneously, but one at a time at each point.

Prototype of the circuit:

After you prototype the circuit in a breadboard, the main construction can be done using a well-designed PCB and use Arduino pro mini for the main construction. 

Program code: Visitor-Counter

How to operate this machine correctly:

1) With the completed hardware setup, including properly aligned lasers with LDR, turn on the circuit. The first step should be setting the correct time and date to RTC which is already explained in this article.

2) The next step is to set start and end time using the push buttons. The machine will register the count of people between the start and end time only. 

3) To set start time press the menu button and press enter. Now the LCD will ask you to set (starting) hours and use INC and DEC buttons to select an hour (0 to 23) and press enter. Now the LCD will ask you to set minutes (0 to 59), use INC and DEC buttons to select a minute and press enter, the LCD will say start time is saved.

4) Now you need to set closing hours / ending hours. Press the menu and press INC button and press enter to move inside closing / end hour setting. Set hour and minute similar to point no. 3.

5) Example: 

  • Let’s see few examples. To set one hour counting period say between 9:00 and 10:00 hours. You can get the starting hour to 9:00 and ending hour to 9:59. The ending time 9:59 also includes the full 59th minute (so, do not set the end time to 10:00, otherwise the machine will count till 10:00:59 hours). The machine will automatically log data to SD card at 9:59:59 hours.
  • To run the machine 24 hours and if that is your requirement, please set the start time to 00:00 and end time to 23:59 and the machine will count number of people all the time. The count data will be saved to SD card at 23:59:59 hours.
  • Invalid time: If you set a start hour that is greater than your end hour, then the machine will not get activated at all. Example: setting start time to 9:00 hours and end time to 5:00 hours is an invalid time.

6) When the machine is not counting i.e. when the current time is before start time or after end time, the LCD will display the following:

7) If the machine is counting that is, when the current time is between start and end time, the LCD will display count details:


Note: The content and the pictures in this article are contributed by the author. The opinions expressed by contributors are their own and not those of PCBWay. If there is any infringement of content or pictures, please contact our editor (zoey@pcbway.com) for deleting.


Written by Blogthor.

Join us
Wanna be a dedicated PCBWay writer? We definately look forward to having you with us.
  • Comments(0)
You can only upload 1 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000
    Back to top