microcontroller PIR sensor triggered by itself when using timer works without timer


Posted on Feb 6, 2014

A PIR sensor is triggered by itself when using a timer to wait 2 seconds after the sensor is triggered. Without using the timer to wait the sensor works as expected. I have a PIR sensor connected to an ATMega328p. The PIR sensor has three pins; VCC, GND and AL. The AL pin uses open collector to show that motion is detected. What I have done is th


microcontroller PIR sensor triggered by itself when using timer works without timer
Click here to download the full size of the above Circuit.

at I connected the AL pin to PC0 pin on my ATMega and set up the pin as input with internal pull up resistor and a LED connected to PC5 to show when motion is detected: Everything works as expected, the LED lights up when I wave my hand infront of the sensor and it does not trigger without motion. The sensor sets the AL pin LOW for about 100 - 200 ms. The thing is that I don`t want to use the signal for 2 seconds after motion has been detected. So I implemented a timer and flag logic that ignores the signal during these 2 seconds. The problem is that now the LED lights up by itself after the timer has stop counting and start accepting motion signals volatile bool motion_detected; void setup_default_values() { DDRC |= (1 << PC5); DDRC |= (1 << PC4); DDRC |= (1 << PC3); DDRC &= ~(1 << PC0); PORTC |= (1 << PC0); TCCR1B |= (1 << CS12); // Timer 1B set up to use a prescaler of 256 TCNT1 = 0; // Timer value set to 0 motion_detected = false; } void check_sensor() { if (PINC & (1 << PC0) { PORTC &= ~(1 << PC5); }else{ PORTC |= (1 << PC5); if (!motion_detected) { PORTC |= (1 << PC3); _delay_ms(50); PORTC &= ~(1 << PC3); PORTC |= (1 << PC4); TCNT1 = 0; motion_detected = true; } } } #define F_CPU 1000000UL /* * Timer increments per second * * This value represents how many increments the timer will do to the TCNT1 register * per second. * * To produce this value you divide the clock frequency in hz with the prescaler amount. * For...




Leave Comment

characters left:

Related Circuits

  • New Circuits

    .

     


    Popular Circuits

    VHF 5/8wave vertical antennas
    Common Collector Colpitts Oscillator
    light dependent blinker using ldr and cd4093
    TLE6282 H-Bridge And Half Bridge Driver IC
    Sound Synchronized LED Video Tutorial
    A Half Bridge Buck Boost Converter with high side N-type MOSFET
    Board making technique
    Dual edge triggered circuit diagram
    Using a diode as a temperature sensor and 3 1 2 digits Thermometer
    Eliminate loops cold junction compensation amplification circuit ISO102 INA101
    Using PLL Phase Locked Loop IC frequency N 1 to 10 of the multiplier circuit
    Single-phase torque motor speed control circuit 2
    TA7366 67 five lights single drive circuit



    Top