+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Newbie level 2
    Points: 20, Level: 1

    Join Date
    Nov 2017
    Posts
    2
    Helped
    0 / 0
    Points
    20
    Level
    1

    PIR Sensor Interfacing with PIC16F877A Microcontroller

    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 by nakiiib; 30th November 2017 at 11:10.

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 30,125, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,995
    Helped
    1138 / 1138
    Points
    30,125
    Level
    42
    Blog Entries
    9

    Re: PIR Sensor Interfacing with PIC16F877A Microcontroller

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  3. #3
    Newbie level 2
    Points: 20, Level: 1

    Join Date
    Nov 2017
    Posts
    2
    Helped
    0 / 0
    Points
    20
    Level
    1

    Re: PIR Sensor Interfacing with PIC16F877A Microcontroller

    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.



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 4
    Points: 8,293, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,328
    Helped
    270 / 270
    Points
    8,293
    Level
    21

    Re: PIR Sensor Interfacing with PIC16F877A Microcontroller

    Quote Originally Posted by nakiiib View Post
    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.



  5. #5
    Super Moderator
    Points: 30,125, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,995
    Helped
    1138 / 1138
    Points
    30,125
    Level
    42
    Blog Entries
    9

    Re: PIR Sensor Interfacing with PIC16F877A Microcontroller

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



--[[ ]]--