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. Help troubleshooting code

Help troubleshooting code

Scheduled Pinned Locked Moved Troubleshooting
13 Posts 3 Posters 2.4k Views 3 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.
  • martinhjelmareM martinhjelmare

    @barduino

    Don't confuse MOTION_A_TRIGGER_PIN with MOTION_A_CHILD_ID.

    barduinoB Offline
    barduinoB Offline
    barduino
    wrote on last edited by
    #4

    @martinhjelmare

    You're right it should be MOTION_A_TRIGGER_PIN. And it should be -1 not -2 confirm?

    martinhjelmareM 1 Reply Last reply
    0
    • barduinoB barduino

      @martinhjelmare

      You're right it should be MOTION_A_TRIGGER_PIN. And it should be -1 not -2 confirm?

      martinhjelmareM Offline
      martinhjelmareM Offline
      martinhjelmare
      Plugin Developer
      wrote on last edited by martinhjelmare
      #5

      @barduino

      The interrupt number is usually pin - 2 on our boards. But I would rather use the function provided by arduino to get the correct interrupt number for a pin, digitalPinToInterrupt.

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

        Thanks for the help, the sketch complies and runs now. But where and how do I specify the timing in the sketch. This is what I want.

        1 PIR detects movement
        2 PIR is disabled for 30 seconds
        3 Both ultrasonic sensors is enbabled for 30 seconds
        4 Ultrasonic sensors OFF PIR ON
        5 --> Step one

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

          I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under

          if (tripped)
          

          runs, but for how long are the ultrasonic sensors active? And how do I make it so that they are active for 30 sec before they are disabled and the PIR starts again.

          martinhjelmareM 1 Reply Last reply
          0
          • Cliff KarlssonC Cliff Karlsson

            I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under

            if (tripped)
            

            runs, but for how long are the ultrasonic sensors active? And how do I make it so that they are active for 30 sec before they are disabled and the PIR starts again.

            martinhjelmareM Offline
            martinhjelmareM Offline
            martinhjelmare
            Plugin Developer
            wrote on last edited by
            #8

            @Cliff-Karlsson

            Should the node sleep in between pinging during the 30 secs that the sonars should be active?

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

              @Cliff-Karlsson said:

              I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under

              No I only want the sensor to sleep until it gets interrupted from the PIR. Then I want the ultrasonic sensors to ping continuously during the 30 secs.

              1 Reply Last reply
              0
              • martinhjelmareM Offline
                martinhjelmareM Offline
                martinhjelmare
                Plugin Developer
                wrote on last edited by
                #10

                Right now there's a call to wait method in between A and B pings, waiting 1 second. Is that intended? For 30 secs, ping A and B alternatively every 1 second?

                Cliff KarlssonC 1 Reply Last reply
                0
                • martinhjelmareM martinhjelmare

                  Right now there's a call to wait method in between A and B pings, waiting 1 second. Is that intended? For 30 secs, ping A and B alternatively every 1 second?

                  Cliff KarlssonC Offline
                  Cliff KarlssonC Offline
                  Cliff Karlsson
                  wrote on last edited by
                  #11

                  @martinhjelmare

                  Well I thing the sketch was created mostly using copy/paste so that bit is not exactly what I wanted.

                  For 30secs, ping A and B alternatively every 100ms would probably be better.

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

                    I don't understand where and how I should specify that the ultrasonic part should run for 30 sec.

                    void loop()      
                    {     
                      
                      boolean tripped = digitalRead(MOTION_A_TRIGGER_PIN) == HIGH; 
                      
                        
                      Serial.println(tripped);
                      send(MOTION_A_msg.set(tripped?"1":"0"));  // Send tripped value to gw 
                     if(tripped)  {
                      
                      int SONAR_A_dist = metric?sonar_A.ping_cm():sonar_A.ping_in();
                      Serial.print("Ping Sonar A: ");
                      Serial.print(SONAR_A_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
                      Serial.println(metric?" cm":" in");
                    
                      if (SONAR_A_dist != SONAR_A_lastDist) {
                          send(SONAR_A_msg.set(SONAR_A_dist));
                          SONAR_A_lastDist = SONAR_A_dist;
                      }
                      
                      wait(1000);
                    
                      int SONAR_B_dist = metric?sonar_B.ping_cm():sonar_B.ping_in();
                      Serial.print("Ping Sonar B: ");
                      Serial.print(SONAR_B_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
                      Serial.println(metric?" cm":" in");
                    
                      if (SONAR_B_dist != SONAR_B_lastDist) {
                          send(SONAR_B_msg.set(SONAR_B_dist));
                          SONAR_B_lastDist = SONAR_B_dist;
                      }
                    
                      sleep(SLEEP_TIME);
                    }
                                }
                    //else{
                      // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
                      sleep(INTERRUPT,CHANGE, MOTION_SLEEP_TIME);```
                    1 Reply Last reply
                    0
                    • martinhjelmareM Offline
                      martinhjelmareM Offline
                      martinhjelmare
                      Plugin Developer
                      wrote on last edited by
                      #13

                      You have to add a timer, and an if statement. Start the timer after motion is tripped. If time is less than 30 s, ping. Else reset timer and sleep with motion interrupt.

                      I can post some example code later perhaps.

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


                      24

                      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