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. Troubleshooting
  3. Repeater and motion

Repeater and motion

Scheduled Pinned Locked Moved Troubleshooting
4 Posts 3 Posters 1.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.
  • I Offline
    I Offline
    insomnia
    wrote on last edited by
    #1

    The sketch works only it is sending the motion every second. I only want the sensor to send if there is motion. Who can help me with the code?

    #include <MySensor.h>  
    #include <SPI.h>
    
    #define DIGITAL_INPUT_SENSOR 3   // 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)
    #define CHILD_ID 1   // Id of the sensor child
    
    MySensor gw;
    // Initialize motion message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      // The third argument enables repeater mode.
      gw.begin(NULL, AUTO, true);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Motion Sensor/Repeater", "1.0");
    
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_MOTION);
      
    }
    
    void loop()     
    {     
      // By calling process() you route messages in the background
      gw.process();
      
      // Read digital motion value
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
            
      Serial.println(tripped);
      gw.send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
     
    }
    
    D 1 Reply Last reply
    0
    • S Offline
      S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by
      #2

      Is your sensor giving you a HIGH reading all the time?

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      1 Reply Last reply
      0
      • I insomnia

        The sketch works only it is sending the motion every second. I only want the sensor to send if there is motion. Who can help me with the code?

        #include <MySensor.h>  
        #include <SPI.h>
        
        #define DIGITAL_INPUT_SENSOR 3   // 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)
        #define CHILD_ID 1   // Id of the sensor child
        
        MySensor gw;
        // Initialize motion message
        MyMessage msg(CHILD_ID, V_TRIPPED);
        
        void setup()  
        {  
          // The third argument enables repeater mode.
          gw.begin(NULL, AUTO, true);
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Motion Sensor/Repeater", "1.0");
        
          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
          // Register all sensors to gw (they will be created as child devices)
          gw.present(CHILD_ID, S_MOTION);
          
        }
        
        void loop()     
        {     
          // By calling process() you route messages in the background
          gw.process();
          
          // Read digital motion value
          boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                
          Serial.println(tripped);
          gw.send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
         
        }
        
        D Offline
        D Offline
        Dwalt
        wrote on last edited by Dwalt
        #3

        @insomnia

        Your sketch has the motion sensor sending its status every time through the loop, add a qualifier to only send when the status changes:

        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
          if (tripped != lastTrippedState)
          {  
            Serial.println(tripped? "tripped" : "not tripped");
            gw.send(msg.set(tripped?"1":"0"));// Send tripped value to gw//
            lastTrippedState = tripped
          }
        

        Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

        1 Reply Last reply
        0
        • I Offline
          I Offline
          insomnia
          wrote on last edited by
          #4

          @Dwalt That was what i needed. It works now :-)

          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


          20

          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