Thursday, 2 October 2014

Program to interface PIR sensor with atmega 32


About PIR Sensor:

Pyroelectric Infrared Radiation Sensor (motion sensor) module basically detects human motion (within 6 meters range). You can open the white cap(Fresnel Lens) and see the sensors within. 

There are various modules available. I have used the one with 3 pins(1-VCC, 2-OUT, 3-GND).


How does it work?

I have tried to add enough comments which can help you understand the working. PIR sensors take 1-2 minutes to settle down. During this time it captures the infrared radiation of the room, and after that if someone comes in front of the sensor, the radiation picture changes, due to human temperature. 

The output pin goes low when it detects motion.

Nevertheless, you can refer the pdf for exact description.

Program :


#include"avr io.h"

#include"util delay.h"

#include"compat deprecated.h"

void main()

{

 DDRA = 0x00;                     //PORT A as input

 DDRC = 0x0F;                    // LED at PORT C as input

 while(1)

 {

  if(bit_is_set(PINA,0))        //no motion detected

  {  

   sbi(PORTC,0);

   sbi(PORTC,1);

   cbi(PORTC,2);

   cbi(PORTC,3);

  }

  else if(bit_is_clear(PINA,0))   // motion detected.

  {

   cbi(PORTC,0);

   sbi(PORTC,1);

   sbi(PORTC,2);

   sbi(PORTC,3);

  }

   

 }

}


You can find all the files on Github too.

If you come across any doubts or have queries, feel free to comment


Would you like to know "How to make a bump avoidance circuit using aluminum foil" ?







1 comment:

  1. Is bit_is_clear included in compat/depreceated.h?

    ReplyDelete

Powered by Blogger.