top of page
Writer's pictureRamesh G

Bluetooth Visitor Counter and automatic light control

Updated: Jun 21


Here to learn, we will make a Arduino and Bluetooth based Visitor Counter and an Automatic Light Control System using Infrared sensor. In this project, a pair of IR sensors can detect the visitor IN/OUT directions, and arduino send these data to android application using Bluetooth. Android screen displayed in Visitor Walk In count, Visitor Walk Out count and Visitor inside count using android application. This device also have a Bar chart and pie chart for comparison of Visitor In, Out and Inside count for visual and data analysis.

In addition to that Visitor counter control an automatic light control system for ON/OFF for the light. If people presence inside the building the light automatically ON and If no people are inside the building the light automatically OFF.


Components required

Arduino Nano - 1 no

Bluetooth module HC-05 - 1no

IR sensor module -2nos

1-Channel 5V Relay Module - 1no


Circuit diagram


What is an IR Sensor?

IR sensor is an electronic device, that emits the light in order to sense some object of the surroundings. An IR sensor can measure the heat of an object as well as detects the motion. Usually, in the infrared spectrum, all the objects radiate some form of thermal radiation. These types of radiations are invisible to our eyes, but infrared sensor can detect these radiations.

The emitter is simply an IR LED (Light Emitting Diode) and the detector is simply an IR photodiode . Photodiode is sensitive to IR light of the same wavelength which is emitted by the IR LED. When IR light falls on the photodiode, the resistances and the output voltages will change in proportion to the magnitude of the IR light received.


IR Sensor Working Principle

There are different types of infrared transmitters depending on their wavelengths, output power and response time. An IR sensor consists of an IR LED and an IR Photodiode, together they are called as PhotoCoupler or OptoCoupler.


IR Transmitter or IR LED

Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations called as IR LED’s. Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye.


IR Receiver or Photodiode

Infrared receivers or infrared sensors detect the radiation from an IR transmitter. IR receivers

come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from normal photo diodes as they detect only infrared radiation. Different types of IR receivers exist based on the wavelength, voltage, package, etc. When used in an infrared transmitter – receiver combination, the wavelength of the receiver should match with that of the transmitter.

The emitter is an IR LED and the detector is an IR photodiode. The IR photodiode is sensitive to the IR light emitted by an IR LED. The photo-diode’s resistance and output voltage change in proportion to the IR light received. This is the underlying working principle of the IR sensor.

When the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to the IR receiver. Based on the intensity of the reception by the IR receiver, the output of the sensor defines.


Bluetooth HC-05 Module

HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth.

It has 6 pins,

Key/EN- NC

VCC to Connect 5 V power

GND to power Ground

TXD to Arduino Nano Rx (D0)

RXD to Arduino Nano Tx (D1)

State- NC

HC-05 module Information

HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds.


This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator.


As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.

HC-05 Default Settings

Default Bluetooth Name: “HC-05”

Default Password: 1234 or 0000

Download Datasheet

Subscribe and Download code.

Arduino Code

#define DELAY_TIMEOUT 1500


int IR_Right_Pin = 8; // <<<---->>> ** IN DIRECTION ** SENSOR

int IR_Left_Pin = 9; // **<<<---->>> OUT DIRECTION ** SENSOR

#define Relay 2


//Remove Bluetooth RX, Tx wiring when program upload

int IR_Right_state = 0;

int IR_Left_state = 0;


int IR_Right_state_last = -1;

int IR_Left_state_last = -1;


int IN_counter = 0;

int OUT_counter = 0;

int Inside_counter = 0;


bool Walk_IN = false;

bool Walk_Out = false;

unsigned long tm;


void setup(void) {

Serial.begin(9600);

pinMode(IR_Right_Pin, INPUT);

pinMode( IR_Left_Pin , INPUT);

pinMode(Relay, OUTPUT);


}

void loop(void) {

IR_Right_state = digitalRead(IR_Right_Pin );

IR_Left_state = digitalRead( IR_Left_Pin );

checkWalkIn();

checkWalkOUT();

checkInside();

}


void checkWalkIn(){

if( IR_Right_state != IR_Right_state_last ){

IR_Right_state_last = IR_Right_state;

if( (Walk_IN == false) && ( IR_Right_state == LOW ) ){

Walk_IN = true;

tm = millis();

}

}


if( (millis() - tm) > DELAY_TIMEOUT ){

Walk_IN = false;

}



if( Walk_IN && (IR_Left_state == LOW) && (IR_Right_state == HIGH) ){

Walk_IN = false;

IN_counter++;

// Serial.print("in:");

// Serial.print(IN_counter);

}

}


void checkWalkOUT(){

if( IR_Left_state != IR_Left_state_last ){

IR_Left_state_last = IR_Left_state;

if( (Walk_Out == false) && ( IR_Left_state == LOW ) ){

Walk_Out = true;

tm = millis();

}

}


if( (millis() - tm) > DELAY_TIMEOUT ){

Walk_Out = false;

}

if( Walk_Out && (IR_Right_state == LOW) && (IR_Left_state == HIGH) ){

Walk_Out = false;

OUT_counter++;

// Serial.print("out:");

// Serial.print(OUT_counter);

}

}


void checkInside(){

Inside_counter = (IN_counter-OUT_counter);


if(Inside_counter<=0)

{

digitalWrite(Relay, LOW);

delay(200);

}

else

digitalWrite(Relay, HIGH);

Serial.print(IN_counter);

Serial.print("|");

Serial.print(OUT_counter);

Serial.print("|");

Serial.print(Inside_counter);

Serial.print("|");

Serial.print(digitalRead(Relay));

Serial.print("\n");

delay(700);

}


Serial monitor

After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on

Serial monitor.


Android application

First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234).

In this Mobile output Visitors In, Out,Inside head counts and Light control ON/OFF status displayed in screen. And also update chart button for Bar chart and Pie chart view and you can click to In,out,inside count data to add/remove in pie chart for desired output result.

Subscribe and Download code.

Android App Download


Recent Posts

See All

Comments


bottom of page