ARM based Bidirectional Visitor Counter and Automatic Room Light Controller using PIR sensors

,


Introduction
Most of the regions in the world are undergoing a wave of terrorism. Ongoing circumstances has made one's life completely uncertain. Both developing and developed countries are facing terrorists attacks on social places, not sparing even hotels, schools and care centers. Aftermath of such incidents is large number of causalities. Human deaths and injuries are estimated by trial and error method [1]. Visitor detection check is also vital for no-go and restricted areas. Moreover, in limited sitting places such as cinemas, conference and meeting rooms, it is necessary to keep track of total number of visitors. This requires a system capable of keeping count of and check on total number of visitors in a zone or a building.
Bidirectional Visitor Counter (BVC) is a system used to count the visitors entering and leaving a room. The word bidirectional signifies the count of both types i.e. entering and leaving. When a person enters the room the count is incremented and when a person leaves the room that count is decremented. Bidirectional counters are designed accordance with the real time demands. The design becomes tedious for single door systems where all the visitors are going in and coming out through a single channel.
The energy sources are going scarce. In developing countries the energy consumption rate is higher than the production rate. Therefore it is the need of time to save the energy as much as possible. In these countries majority of the electric appliances are manually operated. Most of the times, the electric lights and fans are left running even in the fully evacuated rooms. It demands a shift towards an automated system in order to save energy. This paper describes the development and real time implementation of a bidirectional visitor counter and Automatic Room Light Controller (ARLC). Room light controller works on top of the information gathered through BVC. As soon as the net accumulated counter value falls to zero, the lights of the room and the fans will be turned off to save electricity. The room is automatically re-energized when the count is incremented.
Contrasting to previously developed systems on conventional microcontrollers like PIC and Atmel and limited ranged Infra-Red sensors (IR Sensors), we have used state of the art technology. Though the work can be done by conventional microcontrollers, but with increasing computer technology, it is difficult to program most of those microcontrollers. Moreover, with advanced field of study, researchers and the students are interested in state of art microcontrollers rather than conventional ones. So, our system may be regarded as shift of a developed system from conventional to state of the art technology.

Literature Review
Before the advancement of information systems, counting of visitors passing through a location used to been done manually. The room appliances are still mostly controlled manually in most parts of the world that often leads to power wastage in case of personal negligence. With the innovation in technology, many electronic systems such as bidirectional visitors' counters and automatic appliance controllers have been developed to keep check of the visitors visiting a hall and controlling the lights of that room [2][3][4][5][6][7][8].
The heart of these counters is a microcontroller that counts the visitors up and down using output from a IR sensor. These sensors consist of an IR transmitter/receiver (TX/RX) pair. The design of BVCs can be quite simple for two door systems. Where one door is dedicated for entering and the other for leaving. One sensor monitors for the visitors entering and the other one monitors the visitors leaving the room. This is the scenario for which many projects have been developed [2], [5], [8]. But the design becomes more challenging for single door systems where all the visitors are entering and leaving through the single channel. The conventional systems employ IR Transmitter receiver pair, each installed on opposing sides of the door [3]. In such systems, the sensor height, sensor alignment and power supply availability to both the devices offer many installation hurdles. The system can still fail to detect a kid if the installing height of sensors is a larger than the kids' height. Similarly, some visitors may also pass through channel without being detected if the height of the sensors is too low. Moreover, most of the existing systems are based on unreliable IR sensors with their limited range and poor detection with transparent or bright colored materials [11].
In comparison to the older systems, we have used practically applicable PIR sensors rather than ordinary IR sensors. Typical IR sensors used by earlier developers, have much limited range [11]. They can be used to successfully develop a model of sensing range of a few centimeters to inches. However, for practical application on several feet wide doors, PIR sensors are the best choice that we have used in our design. Moreover, a number of conventional microcontrollers were programmed through serial/parallel ports on PC which have been vanished from most of the present laptops and PCs used by a university student. It echoes to shift older technology on the state of the art

Proposed System
The proposed system is designed using ARM cortex based microcontroller, a seven segment display and two PIR sensors. One of the sensors is installed just outside and the other one just inside the door. Microcontroller determines whether a visitor is coming in or going out by reading the output sequence of the two sensors. We will call the outside sensor Sensor-A and the inside sensor as Sensor-B throughout this paper. The output of the microcontroller derives a relay circuit that turns on the lights of the room when the counter is incremented from 0. All the lights and fans remain turn on until the count is again decremented to its initial value of zero. The flow of our proposed algorithm is shown in Figure 1.

Materials
Prior to moving to the working methodology of our system, the used materials are discussed briefly here. Following components has been used in our proposed system:

Power Supply
To provide power to all the components of proposed system, we developed a power supply unit. The first part of this unit is a transformer that steps down 220 V AC mains to 12 V AC. These low voltages are then rectified through a full-wave rectifier. The rectified output is then filtered through filter capacitors and regulated to 5 V DC using a 7805 linear regulator. This supply unit powers all the components including microcontroller, sensors, seven segment driver circuit and the relay module.

Tiva C Launchpad
In the design we have used ARM Cortex-M (TM4C1233H6PM microcontroller) based Tiva C Launchpad (by Texas Instruments) shown in Figure 2. Details of the microcontroller are given in [10]. The board requires 5 V regulated power supply on VBUS and GND pins. The power is provided through regulated supply of 5 V. Six GPIO ports are available on the board with nomenclature Port A, Port B, Port C, Port D, Port E and Port F. We make use of selected pins from port A, B, E and F. Port A and B are used to provide power and data to 7-segment display respectively. Port E is used to integrate PIR sensors' interrupts and single relay module. The status indicator LEDs are connected to port F. The microcontroller drives and reads the PIR sensors, the 7-segment display and trigger the relay switch.

PIR Proximity Sensor
For visitor detection, we have used two Passive Infra-Red (PIR) proximity motion sensor HC-SR501 as shown in Figure 3. Operating voltage range of sensor is from 4.5 V to 20 V and the power is provided through the supply unit described in first section. Delay time and block time of the sensors are adjustable. The sensing range of HC-SR501 is about 120 degrees up to the distance of seven meters [9]. Though the linear range is useful for most practical scenarios, we found out experimentally that the angle is too wide for satisfactory operation of visitor counting in real world scenarios. The solution of this problem is also discussed in order to improve efficiency. PIR sensors sense an object by comparing the heat emitted by the moving object and the background. So, such sensors must be installed only for stationary backgrounds and heat invariant environments to avoid false switching. Ambient temperature conditions for HC-SR501 is exactly in accordance with room temperature conditions of most of the regions including Asia and some of the European countries.

Common Anode 7-Segment Display
To display the number of visitors inside a room, we have used a common anode 7-segment display. For this purpose, a driving circuit is designed using four NPN transistors. The driving circuit is powered from the same power supply.

Single Relay Module
This module controls the electric appliances. In common, the room appliances operate on 220 V. So, the single relay module turns on and off these appliances of the room in accordance with the output of bidirectional visitor counter. Single relay module is designed using 5 V DC-220 V AC relay (Figure 4). Relay is triggered by the signal asserted on GPIO pin of microcontroller. As soon as the count is incremented from zero, the relay module triggers and turns on the appliances. The relay moves back to its initial condition only when count falls to zero again.

Working
When a visitor enters a room, it is detected sequentially first by sensor A and then by sensor B. The microcontroller recognizes that sequence and increments the occupancy counter. It can be problematic if there is non-overlapping proximity area of sensors (shown in Figure 5 as a typical case). As soon as anyone of the sensors senses a motion, the corresponding signal is asserted. This signal remains high for a specific time interval after the sensor output goes low. This signal gets away with the problems created by non-overlapping proximity area.
The working of our proposed system is shown in Figure 6. The dotted line shows the door and the Signal-A and Signal-B are the corresponding signals asserted by Sensor A and Sensor B respectively. Same analogy is used for decrementing the occupancy count with only difference that the sensors sequence will be reversed as is shown in Figure 7.

Pseudo Code
The pseudo code of the algorithm is given in Algorithm. 1

Testing and Results
The real time testing was done on main entrance of Department of Electrical Engineering, UET Lahore. The testing under controlled conditions produced 100 % accuracy. The wrong triggers were avoided by allowing just one visitor to be in the range of the sensors at a time. However testing in real time conditions produced about 60 % efficiency the cause of which was diagnosed to be the wide sensing angle of PIR sensors.
In order to increase the efficiency in this scenario it was required to optimally reduce this wide angle. We added an extra view restricting geometry in front of the sensors as depicted in Figure 8 . Due to this addition, we were able to reduce the angle range from 120 degrees to only 40 degrees. Testing this new design in real time improved the accuracy to 96 %.The error of 4 % was found when two persons passed before the sensors exactly at the same time. It can be avoided by queueing on the entrances of highly recommended places. For second testing, a class room of the department was chosen. The whole system including BVC and ARLC was tested in this last phase. The system yielded 100 % efficiency by accurately counting the students entering and leaving the class room and turning on and off the lights accordingly.

Conclusion
Replacement of the outdated technology with latest one, have made us enable to develop a practically applicable BVC system that produced highly efficient results in practical scenarios. The system is an effective addition for security systems. It may be implemented at sensitive buildings and highly secret meeting rooms. Moreover, it relaxes the management burden in public recreation and limited seats places such as cinemas. In addition to visitor counter, automatic room light controller produces amazing efficiency to control the room appliances which is a desired product for energy deficient developing countries.

Future Work
The project can be expanded in various projections. For time being, we have controlled room lights in digital manner such that the lights are turned off automatically when no person is inside the room and turned on automatically when the count is incremented. We intend to control light intensity based on the number of people inside the room. It will be more power friendly in order to save energy. We will also embed with Internet of Things (IoT) technology and WLAN connectivity for observations on world wide web. Moreover, we have intended to develop an automated ticketing systems at cinemas and recreational places to reduce the further load of the management.