How do I use the interrupt


  • Mod

    I have a motion sensor that I want to go to sleep for a long time until, obviously, motions is sensed.
    I found the interrupt pin in the sample sketch and did some reading.
    I (sort of) understand now how it works from the software side.
    However, what I don't understand is how it works from the hardware side.

    Do I need to send the trigger signal to the interrupt pin as well?
    If so can I do that just like without resistor?


  • Contest Winner

    @marceltrapman

    @marceltrapman said:

    However, what I don't understand is how it works from the hardware side.

    Do I need to send the trigger signal to the interrupt pin as well?
    If so can I do that just like without resistor?

    you can send a 5V signal (uno, nano, proMini) to the pin, yes.

    You can detect a FALLING edge (detection that the pin is moving from 5V towards GND), RISING edge(see falling edge), either (CHANGE) or LOW detection of a signal.


  • Mod

    @BulldogLowell beware that the datasheet of the atmega states that only low level can be detected when in deep sleep mode. So beware when trying to detect edges & high level (I've seen them being detected sometimes though (I think 😉 )


  • Mod

    @BulldogLowell @Yveaux The only thing I want is see that the motion sensor detected a change.
    The change itself HIGH/LOW is reported by the motion sensor.
    Or do I miss something.

    Would I just hook up the signal from the sensor to the interrupt pin (when I am sure it is not beyond 5v) or do I have to do it differently.


  • Mod

    @marceltrapman what I mean is that according to the datasheet of the atmega it can only (reliably) wake from a low level on the interrupt pin. If your sensor reports a low /high transition when it senses something this will probably not be detected by the atmega. It should cause a low level on the interrupt pin for the atmega to wake from sleep. Then in the interrupt handler you should wait for the low level to disappear again before returning, otherwise you'll enter the interrupt again immediately.

    Which motion sensor are you using? It might help in the discussion.


  • Mod

    @Yveaux I have one of each of these:
    https://www.sparkfun.com/datasheets/Sensors/Proximity/SE-10.pdf
    http://www.mpja.com/download/31227sc.pdf

    I assume that I have to do some engineering if I can not use the signal like it is

    To be honest, if that is the case this is beyond my knowledge.
    Can you or someone else give me pointers what to do and/or point me to some good reading on the subject.

    'Me simple sales guy with knowledge in programming but no electronics yet' 🙂


  • Mod

    @marceltrapman the se-10 is powered at 12v so the trigger output might also produce 12v, or ttl; it is not in the datasheet so verify with a multimeter. The signal will probably be high on detection for both sensors, so if the atmega datasheet is right and a low level is required this will not work without additional hardware...
    You could try with the interrupt configured to trigger on rising edge (low-high transition) but as said this might not wake the atmega. Just try to see if it works...
    If it doesn't work you need to invert the trigger signal, using e. g. a transistor or ttl inverter ic.


  • Mod

    @marceltrapman had another look at the datasheet. Another option is to use pin-change interrupts which seem to act on level triggers during sleep.
    Have a look at http://playground.arduino.cc/Learning/arduinoSleepCode and https://code.google.com/p/arduino-pinchangeint/wiki/Usage


  • Mod

    I couldn't stand it and wired up the motion sensor I have (HC-SR501) and tested with the MotionSensor example code (MySensors 1.4b).
    Sensor supply is 5V, sensor output is connected to pin 2 or Arduino. Pin 2 is configured to be an input pin and generate an interrupt when any change on the pin state is detected. You don't need to attach a resistor as the sensor outputs either a low state or high state (3V3 according to my data). You *could *connect a small resistor (e.g. 100ohms) between sensor output and Arduino pin to limit the current.
    I only changed the SLEEP_TIME to 30000 and DIGITAL_INPUT_SENSOR to 2. Downloaded the sketch to Uno and ran it.
    Works as expected! Sensor sleeps and is woken by any change in interrupt pin (this is a contradiction with the ATmega datasheet which states it should only act on low level!).
    So a value of 1 is sent when the sensor detects motion, 0 when motion 'goes away'.

    Hopefully this answers your question 🙂


  • Mod

    @Yveaux said:

    Hopefully this answers your question 🙂

    Thank you soooo much for doing this!

    I will do the same this weekend (work, sports etc is also important 🙂 ).


  • Hero Member

    While you guys are at it, can you also confirm that the PIR module does indeed work as intended on 3.3V input like this guy claims:
    http://techgurka.blogspot.se/2013/05/cheap-pyroelectric-infrared-pir-motion.html
    There are a couple of different revisions of the HC-SR501 through so not all of them have actual pins for for H/L selection. Some just have small solder pads.

    Bypassing the regulator, and eventually removing it would solve a lot of problems for battery sensors. But as noted, it should probably output 3.3V when HIGH regardless so no need to worry.


  • Mod

    @bjornhallberg thanks for the hint! The 5v supply kept me from battery powering it.
    I seem to have the same sensor as in the article.
    I'll setup some test and also measure the current the sensor consumes to get an estimation of battery life.
    To be continued....


  • Mod

    Here it is.

    The HC-sr501 seems to work with 3.3v (have not tested it with 3v though).

    With 5v the output pin generates about 500mv low and 3.5v high.
    With 3.3v the output pint generates about 390mv low and a little under 3v high.

    Nice I think...


  • Mod

    Tested HC-SR501 with 2xAA Alkaline (2.86V) still works OK.

    Measured power usage with uCurrent & Scope (2.86V, 7133-1 voltage converter bypassed):

    upload-75f69108-ac9f-4819-af43-1cdb9bbdd0c9

    Blue = current in micro-Amps., Red = detection output
    So sleeping current is roughly 60uA (171uW), peak current is 212uA.
    Probably this will improve by disconnecting the 7133-1 voltage converter.
    Update: Repeated measurement with 7133-1 completely removed from PCB -- Makes no difference, so there's no need to remove it.

    Given the example battery-life calculation from MySensors (http://www.mysensors.org/build/battery) you could run this sensor (alone!) from a battery for roughly 16months!

    Same chart for 4.73V supply (7133-1 voltage converter used):
    upload-c3fa3a5b-3986-443b-a33f-8fc4fb034e6b

    Blue = current in micro-Amps., Red = detection output
    So sleeping current is roughly 66uA (312uW), peak current is 272uA.


  • Mod

    @Yveaux Nice, have not yet tested the other sensor though.


  • Mod

    Got it working, changed the sketch a little though.

    I wanted 2 things:

    1. No reporting of status when there is no change
    2. 4 minutes real sleep before the next update when motion was detected

    Work like a charm 🙂

    Thank you guys!!!

    void loop() {     
      // Read digital motion value
      boolean motion = digitalRead( DIGITAL_INPUT_SENSOR ) == LOW; 
    
      // Send debug output to serial monitor
      mprintln(PSTR("Motion sensor %s"), motion ? "ON" : "OFF" );
    
      if (lastMotion != motion) {
        lastMotion = motion;
    
        // Send motion value to sensor
        gw.send( msg.set( motion ? "1" : "0" ) );
      
        if (motion) {
          gw.sleep( SLEEP_TIME );
        }
      }
      
      gw.sleep( INTERRUPT, CHANGE, SLEEP_TIME );
    }

  • Mod

    @marceltrapman Great you managed to get it working!
    Just wondering about one thing:

    boolean motion = digitalRead( DIGITAL_INPUT_SENSOR ) == LOW; 
    

    This suggests motion is detected when input pin is LOW, while I clearly see it rise when motion is detected...
    Where's the catch?


  • Mod

    @Yveaux said:

    Where's the catch?

    Because I was testing 2 different types of motion sensors I decided (for now) against the HC-SR501.
    I was just being lazy and did not want to bother with checking/setting the timeout and sensibility on the sensor itself.
    The other one behaves correct with this test and not when I set it to HIGH.
    And behaviour is consistent...


  • Mod

    @Yveaux Update: Repeated measurement with 7133-1 completely removed from PCB @ 3v3 -- Makes no difference, so there's no need to remove it.


  • Hero Member

    @Yveaux said:

    @Yveaux Update: Repeated measurement with 7133-1 completely removed from PCB @ 3v3 -- Makes no difference, so there's no need to remove it.

    Let me be sure I understand. You are comparing feeding battery power to the 3.3v circuit of the motion detector, with and without the 7133-1 connected, right? (When the 7133-1 is connected, you are feeding power to its output), right?

    EDIT - It was a dumb question, followed the link to read that the regulator has a 1.7v dropout, so obviously you are not going thru it!

    Some regulators don't like being fed power to their output and waste current, but apparently this one doesn't care, which is handy.


  • Hero Member

    While you guys are at it, can you also confirm that the PIR module does indeed work as intended on 3.3V input like this guy claims:
    http://techgurka.blogspot.se/2013/05/cheap-pyroelectric-infrared-pir-motion.html
    There are a couple of different revisions of the HC-SR501 through so not all of them have actual pins for for H/L selection. Some just have small solder pads.

    Hi all, does anyone know of an eBay listing that actually ships the HC-SR501 with the pins for H/L selection? I bought some of these: http://www.ebay.com/itm/310574919531, which shows the pins in the pictures and the description mentions being able to select H/L with a jumper, but the ones that arrived don't actually have the pins and have the solder pads instead.

    Thanks
    Al


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 2
  • 1
  • 2
  • 2

21
Online

11.2k
Users

11.1k
Topics

112.5k
Posts