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. Feature Requests
  3. Motion sensor increase Time high status via software

Motion sensor increase Time high status via software

Scheduled Pinned Locked Moved Feature Requests
11 Posts 5 Posters 943 Views 4 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.
  • S Offline
    S Offline
    sindrome73
    wrote on last edited by
    #1

    Hello!!
    I would need a little help, if possible !! I'm building a Movement node with the PIR sensor HC-SR501, and I started from the example already present on the MySensors site.
    With this sensor there is a potentiometer that allows you to adjust once passed in the HIGH state, how long it must last before returning LOW.
    What I want to do is put the potentiometer at 0 and do this work in the Code
    So every time there is a movement must communicate the new state to the gateway, stay a time of 10 seconds ON and then if the status is New LOW communicate the new state or at each movement lengthen those 10 seconds

    I don't know how to create the code, does anyone have any examples or can you help me ??

    1 Reply Last reply
    0
    • skywatchS Offline
      skywatchS Offline
      skywatch
      wrote on last edited by
      #2

      I have this for lighting and it is so easy.....

      Set trigger (as you said) to minimum value on pir.

      Then in code detect motion (use arduino uno pin 2 or 3 as interrupt). Then simply put a wait(time-in-milliseconds) after that.

      Here is my example....

      void loop()
      {
        //sendHeartbeat();
      	// Read digital motion value
         bool tripped = digitalRead(DIGITAL_INPUT_SENSOR);
      //	 send(msg.set(tripped?"1":"0"),true);  // Send tripped value to gw
         if (tripped == HIGH){
         send(msg.set(tripped = 0),true);
         }
         while(tripped == HIGH){
         tripped = digitalRead(DIGITAL_INPUT_SENSOR);
         wait(5000);
         }
         send(msg.set(tripped = 1),true);  
      	
      	// Sleep until interrupt on motion sensor. Send update every ten minutes.
      	sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
      }
      

      Just change wait(5000) to wait(10000).

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sindrome73
        wrote on last edited by
        #3

        I had thought of WAIT or rather DELAY, but the sketch is more complex than just the motion sensor, and using DELAY is not correct because it would block the execution of the code.
        But can't I find other solutions ???

        skywatchS 1 Reply Last reply
        0
        • scalzS Offline
          scalzS Offline
          scalz
          Hardware Contributor
          wrote on last edited by scalz
          #4

          You should better use async coding, it won't block like wait() ;)
          I did that for some old avr+analog pir nodes (custom pir state machine).

          So you simply need to use millis() + async coding. Below an example which explains how to blink a led without using any delay.
          https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

          By doing this way, your loop will never be blocked, and will run multiple times as you wish.
          So you'll need to use some vars to store time/durations. And some booleans for your pir states, time to sleep node etc.

          1 Reply Last reply
          0
          • S sindrome73

            I had thought of WAIT or rather DELAY, but the sketch is more complex than just the motion sensor, and using DELAY is not correct because it would block the execution of the code.
            But can't I find other solutions ???

            skywatchS Offline
            skywatchS Offline
            skywatch
            wrote on last edited by skywatch
            #5

            @sindrome73

            I never said use 'DELAY'.

            My code does not use 'DELAY'.

            'WAIT' and 'DELAY' are not the same thing.

            S electrikE 2 Replies Last reply
            0
            • S Offline
              S Offline
              sindrome73
              wrote on last edited by
              #6

              @scalz said in Motion sensor increase Time high status via software:

              o non verrà mai bloccato e verrà eseguito più volte come desideri.
              Quindi dovrai usare alcune vars per memorizzare tempo / durata. E alcuni b

              We know Millis, it's already been used several times, but what I can't solve is the code, I can't process the code !!

              1 Reply Last reply
              0
              • skywatchS skywatch

                @sindrome73

                I never said use 'DELAY'.

                My code does not use 'DELAY'.

                'WAIT' and 'DELAY' are not the same thing.

                S Offline
                S Offline
                sindrome73
                wrote on last edited by sindrome73
                #7

                @skywatch
                WAIT and DELAY, aren't they the same thing ??
                You can explain me better, because I didn't know this difference, thanks in advance for your availability

                Searching, I found this
                link text

                mfalkviddM 1 Reply Last reply
                0
                • S sindrome73

                  @skywatch
                  WAIT and DELAY, aren't they the same thing ??
                  You can explain me better, because I didn't know this difference, thanks in advance for your availability

                  Searching, I found this
                  link text

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #8

                  @sindrome73 MySensors' wait() is different from Arduino's delay(). See https://www.mysensors.org/download/sensor_api_20#waiting

                  1 Reply Last reply
                  0
                  • skywatchS skywatch

                    @sindrome73

                    I never said use 'DELAY'.

                    My code does not use 'DELAY'.

                    'WAIT' and 'DELAY' are not the same thing.

                    electrikE Offline
                    electrikE Offline
                    electrik
                    wrote on last edited by
                    #9

                    @skywatch still if you use wait(), the rest of the code in the loop is not executed during the waiting time. Only the mysensors core is executed

                    1 Reply Last reply
                    1
                    • skywatchS Offline
                      skywatchS Offline
                      skywatch
                      wrote on last edited by
                      #10

                      @electrik Since you haven't bothered to even post your full code, how is anyone to know what you want to do?

                      You asked a specific question and I tried to help without knowing anything about your hardware, code or desired operation.

                      S 1 Reply Last reply
                      0
                      • skywatchS skywatch

                        @electrik Since you haven't bothered to even post your full code, how is anyone to know what you want to do?

                        You asked a specific question and I tried to help without knowing anything about your hardware, code or desired operation.

                        S Offline
                        S Offline
                        sindrome73
                        wrote on last edited by
                        #11

                        @skywatch said in Motion sensor increase Time high status via software:

                        ti sei

                        Hello and sorry, if I gave the idea of being courteous !! sorry again
                        I didn't publish the code because I really don't know where to start, but now that I understand WAIT, that in MySensors and a separate thing, I also understand your example, and I thank you for helping me !!
                        But then again I didn't know that this WAIT, was something different from DELAY
                        I answer little, because I'm a little busy these days ..... But anyway for now thanks again for help

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


                        23

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        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