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. Announcements
  3. 💬 Motion Sensor

💬 Motion Sensor

Scheduled Pinned Locked Moved Announcements
63 Posts 30 Posters 19.6k Views 31 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #26

    Hi all,

    The motion sensor project is my first using Arduino and MySensors! I've managed to get the Gateway all up and running and the motion sensor to communicate with it (using the standard ino file from the project page), but I seem to have a couple of issues:

    • Despite the default sleep time it seems to be communicating with the Gateway constantly.
    • Permanently displayed as in an 'On' state in Domoticz.

    I've tried adjusting the sensitivity and time but it doesn't seem to make a difference.

    I don't know which bit is supposed to contain the values which I can decipher with the serial protocol guide so apologies if the answer is staring me in the face!

    Gateway received
    0;255;3;0;9;TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
    1;1;1;0;16;1

    Node sent
    0
    1383086 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
    1383106 MCO:SLP:MS=120000,SMS=0,I1=1,M1=1,I2=255,M2=255
    1383120 MCO:SLP:TPD
    1383127 MCO:SLP:WUP=1

    Any help would be appreciated :)

    ? 1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #27

      try to use a 10uF or bigger capacitor on the 5v and GND, I had issues with mine triggering randomly and after using a stable 5v supply it got back to normal: in fact later on when I added the capacitor to help the NRF24 radio it also stabilized the 5V for the sensor and it is now working fine.
      Did you try to use just a sleep(2000) without the interrupt? Just to check if it is going to sleep correctly

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Daanozz
        wrote on last edited by
        #28

        Hi,

        i'm trying to get my motionsensor working, but i see only 0 in the terminal what send to the gateway. Does anyone know why i only see that 0 and not a 1? I'm asuming that 1 is a movement.

        1 Reply Last reply
        0
        • bgunnarbB Offline
          bgunnarbB Offline
          bgunnarb
          wrote on last edited by
          #29

          I have found in my experiments with the PIR motion sensor that at least the type that I am using is extremely sensitive to ripple in the Vcc voltage.

          First of all, it is unstable as the feed voltage approaches 5V and then it triggers spontaneously again and again. I then tried to rise the voltage to around 11V which is the voltage that the battery eliminator gives. But that voltage has a ripple of 0.1 volt amplitude so this triggers the sensor again and again also since the arduino introduces small changes in the voltage when it processes the script.

          The solution was to install a LM317 voltage regulator to bring down the voltage to 8V which is then ripple free and stable. Now the PIR works very well and does not give false triggers.

          The arduino is fed from a separate voltage regulator giving 5V. I tried to connect the battery eliminator directly to RAW but that released the smoke from the on-board voltage regulator and as you know, when you let the smoke out from components, they no longer work. :grinning:

          Apparently the battery eliminator also produces some voltage spikes that are not healthy.

          I have never been so busy since I retired!

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #30

            I solved my random pir triggers with a Capacitor on the 5v pin.

            1 Reply Last reply
            0
            • ? A Former User

              Hi all,

              The motion sensor project is my first using Arduino and MySensors! I've managed to get the Gateway all up and running and the motion sensor to communicate with it (using the standard ino file from the project page), but I seem to have a couple of issues:

              • Despite the default sleep time it seems to be communicating with the Gateway constantly.
              • Permanently displayed as in an 'On' state in Domoticz.

              I've tried adjusting the sensitivity and time but it doesn't seem to make a difference.

              I don't know which bit is supposed to contain the values which I can decipher with the serial protocol guide so apologies if the answer is staring me in the face!

              Gateway received
              0;255;3;0;9;TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
              1;1;1;0;16;1

              Node sent
              0
              1383086 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
              1383106 MCO:SLP:MS=120000,SMS=0,I1=1,M1=1,I2=255,M2=255
              1383120 MCO:SLP:TPD
              1383127 MCO:SLP:WUP=1

              Any help would be appreciated :)

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #31

              @Kieren-Perry said in 💬 Motion Sensor:

              Hi all,

              The motion sensor project is my first using Arduino and MySensors! I've managed to get the Gateway all up and running and the motion sensor to communicate with it (using the standard ino file from the project page), but I seem to have a couple of issues:

              • Despite the default sleep time it seems to be communicating with the Gateway constantly.
              • Permanently displayed as in an 'On' state in Domoticz.

              I've tried adjusting the sensitivity and time but it doesn't seem to make a difference.

              I don't know which bit is supposed to contain the values which I can decipher with the serial protocol guide so apologies if the answer is staring me in the face!

              Gateway received
              0;255;3;0;9;TSF:MSG:READ,1-1-0,s=1,c=1,t=16,pt=0,l=1,sg=0:1
              1;1;1;0;16;1

              Node sent
              0
              1383086 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0
              1383106 MCO:SLP:MS=120000,SMS=0,I1=1,M1=1,I2=255,M2=255
              1383120 MCO:SLP:TPD
              1383127 MCO:SLP:WUP=1

              Any help would be appreciated :)

              Thanks for all your comments! Tried the capacitor route but no dice. In the end, connected a 9v battery to the jack and the PIR to the VIN as the voltage from the 5v pin and USB was a little below what it should have been.

              1 Reply Last reply
              0
              • Cliff KarlssonC Offline
                Cliff KarlssonC Offline
                Cliff Karlsson
                wrote on last edited by
                #32

                If I want something to run for 10 seconds after a motion have been detected, how would I make this happend?

                1 Reply Last reply
                0
                • gohanG Offline
                  gohanG Offline
                  gohan
                  Mod
                  wrote on last edited by
                  #33

                  Set a timer in the code, that's shouldn't be very hard to do.

                  1 Reply Last reply
                  0
                  • Cliff KarlssonC Offline
                    Cliff KarlssonC Offline
                    Cliff Karlsson
                    wrote on last edited by
                    #34

                    I have never used timers but I looked at the blink without delay sketch from the arduino website. Do I replace the if -statement with a while loop?

                    const int ledPin =  LED_BUILTIN;// the number of the LED pin
                    
                    // Variables will change :
                    int ledState = LOW;             // ledState used to set the LED
                    
                    // Generally, you should use "unsigned long" for variables that hold time
                    // The value will quickly become too large for an int to store
                    unsigned long previousMillis = 0;        // will store last time LED was updated
                    
                    // constants won't change :
                    const long interval = 1000;           // interval at which to blink (milliseconds)
                    
                    void setup() {
                      // set the digital pin as output:
                      pinMode(ledPin, OUTPUT);
                    }
                    
                    void loop() {
                      // here is where you'd put code that needs to be running all the time.
                    
                      // check to see if it's time to blink the LED; that is, if the
                      // difference between the current time and last time you blinked
                      // the LED is bigger than the interval at which you want to
                      // blink the LED.
                      unsigned long currentMillis = millis();
                    
                      if (currentMillis - previousMillis >= interval) {
                        // save the last time you blinked the LED
                        previousMillis = currentMillis;
                    
                        // if the LED is off turn it on and vice-versa:
                        if (ledState == LOW) {
                          ledState = HIGH;
                        } else {
                          ledState = LOW;
                        }
                    
                        // set the LED with the ledState of the variable:
                        digitalWrite(ledPin, ledState);
                      }
                    }
                    
                    1 Reply Last reply
                    0
                    • gohanG Offline
                      gohanG Offline
                      gohan
                      Mod
                      wrote on last edited by
                      #35

                      Just leave it as it is, just put a condition that will trigger the if statement only once the pir sensor got triggered

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        LastSamurai
                        Hardware Contributor
                        wrote on last edited by
                        #36

                        I would actually not do this in a node but in the controller (at least if I get what you are trying to do right). I have done that with some scripting in domoticz. I have lights that that are switched on for 5 minutes when motion is detected and shut down 5 minutes after the last motion stopped. Motion sensor and rgbw controller are different mysensor nodes. Much more versatile then hardcoding this in you node's code.

                        ben999B 1 Reply Last reply
                        0
                        • L LastSamurai

                          I would actually not do this in a node but in the controller (at least if I get what you are trying to do right). I have done that with some scripting in domoticz. I have lights that that are switched on for 5 minutes when motion is detected and shut down 5 minutes after the last motion stopped. Motion sensor and rgbw controller are different mysensor nodes. Much more versatile then hardcoding this in you node's code.

                          ben999B Offline
                          ben999B Offline
                          ben999
                          wrote on last edited by
                          #37

                          @LastSamurai
                          Would you do that through "rules" ?

                          gohanG 1 Reply Last reply
                          0
                          • ben999B ben999

                            @LastSamurai
                            Would you do that through "rules" ?

                            gohanG Offline
                            gohanG Offline
                            gohan
                            Mod
                            wrote on last edited by
                            #38

                            @ben999 yes.

                            @LastSamurai I know that hardcoding is less flexible, but at least it can work even if controller is down or disconnected, of course it depends how critical is the actuator.

                            1 Reply Last reply
                            0
                            • maghacM Offline
                              maghacM Offline
                              maghac
                              wrote on last edited by
                              #39

                              So, I notice that the HC-SR501 has a 7133-1 voltage regulator on-board which I guess means that the logic is actually driven with 3.3V and not 5V.

                              Is it possible to bypass the regulator and power the sensor directly with the 3.3V I am using to power my nano with?

                              maghacM 1 Reply Last reply
                              0
                              • maghacM maghac

                                So, I notice that the HC-SR501 has a 7133-1 voltage regulator on-board which I guess means that the logic is actually driven with 3.3V and not 5V.

                                Is it possible to bypass the regulator and power the sensor directly with the 3.3V I am using to power my nano with?

                                maghacM Offline
                                maghacM Offline
                                maghac
                                wrote on last edited by
                                #40

                                @maghac Aha, guess I should read old posts first :)

                                1 Reply Last reply
                                1
                                • gohanG Offline
                                  gohanG Offline
                                  gohan
                                  Mod
                                  wrote on last edited by
                                  #41

                                  Just make sure the power source is stable otherwise you will end up with random triggers from pir sensor

                                  ben999B 1 Reply Last reply
                                  1
                                  • gohanG gohan

                                    Just make sure the power source is stable otherwise you will end up with random triggers from pir sensor

                                    ben999B Offline
                                    ben999B Offline
                                    ben999
                                    wrote on last edited by
                                    #42

                                    @gohan @maghac

                                    From my little experience : when running from 2 AA batteries with sketch as it is I got random triggers continuousely

                                    Adding a delay() before entering sleep() sorted things out (something like 3 sec is necessary to get power stable again)

                                    Not sure it's the smartest way of doing it, but it works...

                                    Any comment on the security side of it? Could my node miss some action during these 3 sec ? Or the interrupt pin would still listen to the PIR sensor pin ?

                                    1 Reply Last reply
                                    0
                                    • gohanG Offline
                                      gohanG Offline
                                      gohan
                                      Mod
                                      wrote on last edited by
                                      #43

                                      I think it will miss the pir trigger

                                      ben999B 1 Reply Last reply
                                      0
                                      • gohanG gohan

                                        I think it will miss the pir trigger

                                        ben999B Offline
                                        ben999B Offline
                                        ben999
                                        wrote on last edited by
                                        #44

                                        @gohan

                                        Thank you for your reply

                                        Could you please explain a bit further ?

                                        Interrupt pin would still read the trigger during delay()?
                                        Data would be lost as the sketch is frozen during delay() ?
                                        Or data is saved in some buffer, ready to be used as soon as sketch comes back to life ?

                                        My view is that it shouldn't matter too much if i miss a trigger after a trigger : the first trigger will wake my node and transmit to gateway. So job done. Alarm goes off.

                                        On the other hand, I guess a millis() would be neater ?

                                        Thanks a lot for your input

                                        1 Reply Last reply
                                        0
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #45

                                          I am saying that during delay no code is executed and interrupt only attaches to pin when executing the sleep function, so if motion if triggered during the delay it will not be detected by interrupt; maybe it could detect the CHANGE when pir goes from high to low but it will then report "no motion" and it will not trigger alarm if it set to go off on "motion" only.

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


                                          21

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          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