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.

[PIC] PIR Sensor Interfacing with PIC16F877A Microcontroller

Status
Not open for further replies.

nakiiib

Newbie level 2
Joined
Nov 30, 2017
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
26
Hi. I am using this code below to use in my PIC trainer kit where PIC16F877A is used but output buzzer always turns on even if I dont give a signal or even connect the PIR sensor to that port. Can someone tell me what's wrong with this code?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
sbit pir_in at RB7_bit; //PIR module's output pin
sbit led_ind at RD0_bit; //An LED used as indicator
sbit buz_out at RC1_bit; //Buzzer output
 
sbit pir_in_Direction at TRISB7_bit;
sbit led_ind_Direction at TRISD0_bit;
sbit buz_out_Direction at TRISC1_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
pir_in=0;
init_delay(); //1 min delay to activate the PIR module
while(1)
{
if(pir_in==1){
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);
}
}
else
{
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;
}

 
Last edited:

When you say the buzzer turns on, are you meaning the uC's output or the device itself sounding ?
Depending on the external connections, the logic could be inverted, i.e a zero at RC1 making it beep.
 

The buzzer turns on meaning the uC's output. But since I want to turn on the buzzer only when a signal from sensor is obtained but it is still turning on the buzzer even if no signal is obtained or even sensor is connected at all.
 

Hi. I am using this code below to use in my PIC trainer kit where PIC16F877A is used but output buzzer always turns on even if I dont give a signal or even connect the PIR sensor to that port. Can someone tell me what's wrong with this code?

if your PIR sensor gives a level 1 , or if you disconnect the sensor from RC1 pin, it is the same way ..
Open input is a Level 1 ..
try to short RC1 input to Ground 0V , to check if your buzer stop.
 

Your code is very simple and does not seem to have any mistake that impede it from doing what is supposed to do. However, it was not clear if you did all the preliminary checks, such as if the reset is working, if the clock frequency is adequate, if the external circuit (not shown) is correctly polarized, if the input is being properly read, etc ... So, start with a button and a blinking LED and go ahead step by step.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top