- This topic has 0 replies, 1 voice, and was last updated 11 years, 9 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › Passive Infrared Sensor connected to 8051
HI,
In my project, I am using a PIR sensor to control the lights. When I connect the sensor output to the ULN Driver (which is in turn connected to LEDs though relays), I was able to get proper working of the circuit. But when I use AT89C51 microcontroller to control the system i.e the PIR to the input of the microcontroller (say P2) and ULN driver connected to an output port (say P0), I was not able to get a proper response. The LEDs would glow continuously when the reset switch on the microcontroller board was kept pressed. The followinf is the code used. Please help me.
#include <reg51.h>
sbit pir_in=P2^6; //PIR module's output pin
sbit ULN_in1= P0^6; //ULN input pin 1 LED1
sbit ULN_in4= P0^4; //ULN input pin 4 LED3
int i,j,k; //looping variables
void init_delay (int a); //to generate initial delay for the PIR to stabilise
void main()
{
pir_in=1; //as input to microcontroller
ULN_in1=0; //as output
ULN_in4=0; //as output
init_delay(120); // 1 minute delay to activate the PIR module
while(1) //to continuously monitor PIR output
{
while(pir_in==1)
{
ULN_in1=1; //because the ULN output is the inverse of the ULN input
ULN_in4=1;
}
ULN_in1=0;
ULN_in4=0;
}
}
void init_delay (int a)
{
for(k=a;k>0;k–)
for(i=0; i<1000; i++)
for(j=0; j<1275; j++);
}