Interrupt driven contact sensor


  • Hero Member

    I've modified the sketch I use for temperature/humidity/barometer to remove the barometer and implement a magnetic door sensor. My plan is for this to be installed in/on my gun safe to monitor interior temperature and humidity and log whenever the safe is opened/closed.

    Basically the contact sensor works but of course its loop-driven so it doesn't report when the door is actually opened/closed. It also reports every OTHER reporting cycle for some reason.

    I have the sensor wired to Arduino Pin D3. Can someone guide me in making the contact sensor interrupt driven to report immediately?

    Thanks
    John



  • In your sketch you may just be sleeping on a timer. Ie:

    gw.sleep(SLEEP_TIME);
    

    With the 1.4 beta improvements, there's now provision to sleep on timer AND on interrupt. Like this:

    #define DIGITAL_INPUT_SENSOR 3   // D3 is the only interrupt pin left (radio uses D2)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2
    unsigned long SLEEP_TIME = 30000;
    
    void setup() {
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the digital pin as input
    }
    
    void loop() {
        ...
        gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    

    That may not all be exactly right, but it should be pretty close.


  • Hero Member

    @Bandra Looks fairly simple, maybe its time to upgrade to 1.4


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts