• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

motion sense interrupt not triggering

Q&A Forum › motion sense interrupt not triggering
0 Vote Up Vote Down
RICHARD HODGES asked 3 years ago
7 Answers
0 Vote Up Vote Down
RICHARD HODGES answered 3 years ago

Lets try again.  Based on your tutorial ESP8266 interrupts and timers I am using interrupts to act on PIR sensor going on and off.  I have two interrupt handlers, one triggered on RISING and the other on FALLING edge of the same pin.
So I have. code

attachInterrupt(digitalPinToInterrupt(14), detectsMovement, RISING);     and

attachInterrupt(digitalPinToInterrupt(14), noMovement, FALLING);

 
my problem is the RISING isr does not trigger while the FALLING isr works fine I have verified the voltage change on pin 14 going from a few mv to 3.3 volts but the isr is not called.
the called functions semply set a boolean flag and return.
So at this point I am looking for clues.   Thanks
Rick

 
 

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
Does it detect the RISING change when using just one interrupt handler?
 
Have you tried using a wire instead of the PIR motion sensor to check if it is not related with the sensor? If you have an oscilloscope, you can check the PIR motion sensor behavior in a better detaill and check if something is wrong, or if you need to adjust the sensor delay.
 
Regards,
Sara

0 Vote Up Vote Down
Steve Mercer answered 3 years ago

I’m fairly sure you can’t do that. For each pin you can have either RISING, FALLING or CHANGE. In your code, whatever attachInterrupt is last will be attached to the pin. I believe you need to change it to one attachInterrupt for that pin and use the CHANGE mode.
Another option is to use an attachInterrupt on a different pin and then tie the two pins together.

0 Vote Up Vote Down
RICHARD HODGES answered 3 years ago

Thank you.  If my approach is not permitted I guess I will try The double pin approach and tie the PIR output to Two input pins that are wired together. I really don’t want to use the CHANGE mode and have to do tests in the ISR to determine up or down.  
Rick

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Thanks for the suggestion, Steve.
Richard, then let us know if you were able to solve the problem.
Regards,
Sara

0 Vote Up Vote Down
RICHARD HODGES answered 3 years ago

Hi Sara;   I have verified that Steve is right.  My approach is not permitted.  I tested this by reversing the order in my code, placing the rising condition last.  This compiled and ran correctly and as predicted, ignored the first ISR.  I now have the code working my using the two pin approach.  Thanks again to you and Steve.
Rick

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

That’s great!
I’m glad everything is working as expected.
I’ll mark this issue as resolved.
If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.