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

    Analog to Digital Converter with ADC0808
    Zero crossing detector
    Audio Fader
    Based on 51 single-chip design and production of infrared remote control car
    High voltage generator circuit
    20dB antenna amplifier circuit diagram electronic project
    Servoelectric Guitar Project
    Overvoltage protection circuit diagram