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. Hardware
  3. Motion sensor withput the interrupt

Motion sensor withput the interrupt

Scheduled Pinned Locked Moved Hardware
8 Posts 5 Posters 2.8k 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.
  • ferpandoF Offline
    ferpandoF Offline
    ferpando
    Hero Member
    wrote on last edited by
    #1

    Hello,
    I'm planning on building a node with motion sensor, light detector and a dimmer.
    For it to work, I guess I can't have the node to sleep, so it will be able to receive command from the gateway.
    So my question is how to adapt the motion sensor sketch to not use the interrupt.

    Would something like this work?

    void loop()    
    { 
    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) 
    if(tripped== HIGH) sendTripped();
    
    //send light level if changed
    
    //dimmer control code
    }
    
    function sendTripped()
    {
    Serial.println(tripped);
    gw.sendVariable(CHILD_ID, V_TRIPPED, "1");  
    }
    
    YveauxY 1 Reply Last reply
    0
    • JohnJ Offline
      JohnJ Offline
      John
      Plugin Developer
      wrote on last edited by
      #2

      The above should work, but i would also set an extra variable to check if there has been no movement at first. Otherwise it could continuously send movement.
      Just as example:

      boolean tripped = false;
      boolean prevTripped = false;
      
      void loop()    
      { 
          tripped = (digitalRead(DIGITAL_INPUT_SENSOR)==HIGH)?true:false;
          //// Only send when there has been no movement first.
          if(tripped==true and prevTripped==false) {
             sendTripped();
          }
          prevTripped = tripped;
          
          //send light level if changed
          
          //dimmer control code
      }
      
      function sendTripped()
      {
          Serial.println(tripped);
          gw.sendVariable(CHILD_ID, V_TRIPPED, "1");  
      }
      

      My Domotica project: http://www.pidome.org

      ferpandoF 1 Reply Last reply
      0
      • ferpandoF ferpando

        Hello,
        I'm planning on building a node with motion sensor, light detector and a dimmer.
        For it to work, I guess I can't have the node to sleep, so it will be able to receive command from the gateway.
        So my question is how to adapt the motion sensor sketch to not use the interrupt.

        Would something like this work?

        void loop()    
        { 
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) 
        if(tripped== HIGH) sendTripped();
        
        //send light level if changed
        
        //dimmer control code
        }
        
        function sendTripped()
        {
        Serial.println(tripped);
        gw.sendVariable(CHILD_ID, V_TRIPPED, "1");  
        }
        
        YveauxY Offline
        YveauxY Offline
        Yveaux
        Mod
        wrote on last edited by
        #3

        @ferpando You can just leave the interrupt in. It will no longer wake the Arduino from sleep (as it won't be sleeping) but the interrupt will still be handled on motion!

        http://yveaux.blogspot.nl

        1 Reply Last reply
        0
        • ferpandoF Offline
          ferpandoF Offline
          ferpando
          Hero Member
          wrote on last edited by
          #4

          Yes I thought so, but also thought the interrupt could mess with the rest of the sketch?
          If the node receives a message from gateway and an interrupt happens, how would it behave?

          JohnJ 1 Reply Last reply
          0
          • JohnJ John

            The above should work, but i would also set an extra variable to check if there has been no movement at first. Otherwise it could continuously send movement.
            Just as example:

            boolean tripped = false;
            boolean prevTripped = false;
            
            void loop()    
            { 
                tripped = (digitalRead(DIGITAL_INPUT_SENSOR)==HIGH)?true:false;
                //// Only send when there has been no movement first.
                if(tripped==true and prevTripped==false) {
                   sendTripped();
                }
                prevTripped = tripped;
                
                //send light level if changed
                
                //dimmer control code
            }
            
            function sendTripped()
            {
                Serial.println(tripped);
                gw.sendVariable(CHILD_ID, V_TRIPPED, "1");  
            }
            
            ferpandoF Offline
            ferpandoF Offline
            ferpando
            Hero Member
            wrote on last edited by
            #5

            @John
            It was just a quick proof of concept.. I guess I should set tripped to false once the message is sent

            Z 1 Reply Last reply
            0
            • ferpandoF ferpando

              Yes I thought so, but also thought the interrupt could mess with the rest of the sketch?
              If the node receives a message from gateway and an interrupt happens, how would it behave?

              JohnJ Offline
              JohnJ Offline
              John
              Plugin Developer
              wrote on last edited by
              #6

              @ferpando

              If the node receives a message from gateway and an interrupt happens, how would it behave?

              I asked almost the same question in an other thread, and i got the answer it is not interrupt save... I can not exactly say how it would behave.

              My Domotica project: http://www.pidome.org

              1 Reply Last reply
              0
              • NuubiN Offline
                NuubiN Offline
                Nuubi
                wrote on last edited by
                #7

                Out of curiosity...how did you solve this?

                1 Reply Last reply
                0
                • ferpandoF ferpando

                  @John
                  It was just a quick proof of concept.. I guess I should set tripped to false once the message is sent

                  Z Offline
                  Z Offline
                  Zeph
                  Hero Member
                  wrote on last edited by Zeph
                  #8

                  I think you are on the right track. There' s no need for the interrupt in your case. So you don't have to worry about what process is being interrupted.

                  @ferpando said:

                  It was just a quick proof of concept.. I guess I should set tripped to false once the message is sent

                  John had the right logic. You don't want to set tripped false until the input (ie: motion dectector output) goes false, not when a message is sent.

                  His suggested logic sends one message whenever the motion detector goes active, and not again until it goes inactive and active again.

                  (Which happens after no motion for some time period adjustable via a pot on the motion detector).

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  16

                  Online

                  11.7k

                  Users

                  11.2k

                  Topics

                  113.0k

                  Posts


                  Copyright 2019 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