Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Interrupt driven contact sensor

Interrupt driven contact sensor

Scheduled Pinned Locked Moved My Project
3 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clippermiami
    Hero Member
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bandra
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • B Bandra

        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.

        C Offline
        C Offline
        clippermiami
        Hero Member
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        18

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular