Custom Interrupt routine for door sensor



  • Dear guys, i'm approaching a problem similar to the one presented in this topic: http://forum.mysensors.org/topic/271/interrupt-driven-contact-sensor/2
    I have a node with a DHT11 and a magnetic reed switch to control a door movement. My node sleeps for a determined time interval with the gw.sleep method. And iÃŽd like to wake it up when the timer runs out or when an interrupt is received ( easy to do) . My problem is that i want to perform a specific action when the interrupt is received. Something like : Node Sleeping ---> pin Interrupt ---> Custom action performed ---> other routine in the loop ----> sleep again.
    In particular when the door is opened or closed, i'd like to start a routine that reads the door interrupt pin and reports its status.
    Using instead the defined gw.sleep(IntPin,TypeOfInt,SleepTime) command
    with CHANGE i could catch the door movement but i cannot know the status of the door. Using RISING or FALLING i can get only one of the 2 moves ( open or close) , and with LOW, when door is closed, my node stucks.

    My ideal routine should be something like : interrupt received -->wake up node ---> read interrupt pin ---> send to gateway the value that has been read and blink a led--> put the node back to sleep.
    Can someone help me? i'm attaching the sketch i wrote that's not working well ( freezes). In this sketch the led blinking is missing ( but that's secondary)
    DoorAndTempAndHumIntVer2.ino


  • Contest Winner

    @funksoulbrother

    this is how the BinarySwitchSleepSensor example works, I believe that's what you want from your description...

    note it uses CHANGE mode for the interrupt...



  • Damn, didn't have that sketch in my folder, maybe i had an old release. Just found it in the latest release. Gonna try it soon and test if does the job that i need to be done. Thank you for your advice



  • I built a trip wire for the post box that I'm connecting. It's however based on a mercury tilt sensor so I'm really not sure whether I think it's a great idea putting it to use (at least not with a sturdy case...). However, I can share my code:

    #define DIGITAL_INPUT_SENSOR 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)

    MyMessage msgTripped(CHILD_ID_TRIPPED, V_TRIPPED);
    void setup()
    {
    gw.sendSketchInfo("Postal", "1.0");
    gw.present(CHILD_ID_TRIPPED, S_MOTION);

    pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
    }

    void loop()
    {
    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == LOW;

    if(tripped) {
    gw.send(msgTripped.set("1")); // Send tripped value to gw
    }

    gw.sleep(INTERRUPT,FALLING, SLEEP_TIME);
    }



Suggested Topics

21
Online

11.4k
Users

11.1k
Topics

112.7k
Posts