Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to interface PIR modules with PIC microcontrollers

In this project a Passive Infrared (PIR) sensor is used to detect human movement and trigger an alarm. A typical PIR sensor comes pre-packaged with all the logic required to, detect IR radiation from living being and raise alarm. Similar PIR modules have just three pins, two for power supply (up to 12volt) and third for output. So, all that is required to do is to connect it to the power supply and connect the out pin to a microcontroller pin to detect any changes (detect high or low).
pir.jpg


I have seen many projects in the net where the PIR output pins are directly connected to microcontroller pins. But such arrangement did not work in my case.

I have purchased the PIR module from a shop of Chandni Market, Kolkata (Biggest electronics component market in eastern part of India). The market is notorious for parallel gray market sale. Some of the shops sell components without any papers even cash memo at a very low price. My PIR module costs INR Rs. 350/- without any papers. There was no manufacturer name written anywhere.

At first I had my PIR module’s output connected directly to a pin of pic16F84A microcontroller and did not get proper result. My microcontroller was sensing only high output from the PIR module on all conditions. So I checked the output of the PIR module and found that when connected to a 5 volt supply, the output pin voltage was about 2.66 volts and after detecting a movement the output pin voltage was about 3.44 volts! According to the datasheet of pic16F84A, input low voltage should be 0.2VDD. So I have used a BC547B with the PIR output as a switch to provide proper logic levels to the microcontroller.
[Comments from the reader are appreciated if they have faced a similar situation.]

I have used a pic16F84A microcontroller with 4MHz crystal and MikroC Pro Compiler.
To know more on how PIR module works see: How to use Pyroelectric ("Passive") Infrared Sensors (PIR)

Testing your PIR
It is a good idea to go through a simple test to verify that it works the way you expect. This test is also good for range testing. Simply connect the + pin of the PIR to the positive rail of a good power supply (3.5VDC to 6V) and connect ground to the - pin on your PIR. Then connect an LED (commonly available 2mA current and about 2 volt forward voltage drop) and a 220Ω resistor to the out pin as shown.
pirtest.png


Wait for 1 minute. Now when the PIR detects motion, the output pin will go "high" to 3.4V and light up the LED! [Check the voltage]. After that, stand still. After a few seconds the output line will drop to 2.66 volt. You can check this low voltage when the PIR module is facing opposite side. Otherwise a slight movement will make the output go up again.
Range is about 16f


Codes:-

//Alarm using PIR module.
//PIC16F84A microcontroller using 4MHz Crystal
// A buzzer is used as a sound producer
sbit pir_in at RA0_bit; //PIR module's output pin
sbit led_ind at RA1_bit; //An LED used as indicator
sbit buz_out at RB4_bit; //Buzzer output

sbit pir_in_Direction at TRISA0_bit;
sbit led_ind_Direction at TRISA1_bit;
sbit buz_out_Direction at TRISB4_bit;
void init_delay(); //initial delay routine's forword declaration

int i; //declare for using with for loops both in main and
//in the delay routine
void main() {

pir_in_Direction=1; //as input
led_ind_Direction=0; //as output
buz_out_Direction=0; //as output

led_ind=0; //initially off
buz_out=0; //initially off

init_delay(); //1 min delay to activate the PIR module
while(1){

while(pir_in==0){
buz_out=1;
for( i=0;i<15;i++){ //Buzzer sounds for 15 seconds
led_ind=0;
Delay_ms(500);
led_ind=1;
Delay_ms(500);
}
buz_out=0;
led_ind=0;
}

}
}
void init_delay(){

for(i=0;i<30;i++)
{
led_ind=1;
Delay_ms(500);
led_ind=0;
Delay_ms(500);
}
led_ind=0;
}
//////////////////////////////////////////////////////////////////////
Circuit diagram:-
pir_ckt.png



Finished Project
pir_com.jpg

Comments

is that source code is working??
I face the same problem too.. my AT89S52 always detect a motion from PIR evem my sensor already put inside the box.. here is my code
Code:
void main()
{
TMOD=0x01;
EA=0;
TH0=29300/256;TL0=29300%256;   //19456(4c00)
ET0=1;
//EX0=1;
//IT0=1;
//PX0=1;
TF0=0;
EA=1;
//TR0=1;

count=0;			//initial count value

out=0;
pir1=1;
pir2=1;
lampsig=1;

 lcd_cmd(0x38);
 delay(2); 
 lcd_cmd(0x01);  // Clear Screen
 lcd_cmd(0x84);
 lcd_cmd(0x1c);
 lcd("WELCOME");
 delay(20000);

	delay(1);
	lcd_cmd(0x01);
	lcd_cmd(0x80);
	//lcd_cmd(0x1c);
	lcd("Enter time interval(second):");
while(count<4)
{					
		delay(50);
		keypad();
		time=(digit[0]+(digit[1]*10)+(digit[2]*100));
		count++;		
		delay(1);
}

lcd_cmd(0x01);
	lcd_cmd(0x82);
	lcd("DEVICE READY");
	delay(50000);
lcd_cmd(0x01);
	lcd_cmd(0x82);
	lcd("TIME DISPLAY");
while(1)
{	


	if(pir1||pir2==1)
	{ 
	TR0=1;
	out=1;
	}

	lcd_cmd(0xc6);
	lcd_data_int(time);
			

while((lampsig==0) && (pir1||pir2==1))
{
time=(digit[0]+(digit[1]*10)+(digit[2]*100));
}
						 
if(time==0)
	{
	out=0;
	TR0=0;
	}		
}	
}

thank you
 

Part and Inventory Search

Blog entry information

Author
papunblg
Read time
3 min read
Views
1,392
Comments
2
Last update

More entries in Uncategorized

More entries from papunblg

Share this entry

Back
Top