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. Add a second distance sensor to the same arduino?

Add a second distance sensor to the same arduino?

Scheduled Pinned Locked Moved Troubleshooting
18 Posts 3 Posters 3.7k 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.
  • Cliff KarlssonC Offline
    Cliff KarlssonC Offline
    Cliff Karlsson
    wrote on last edited by
    #9

    Absolutley none offence taken, I really suck at coding and my main methods are copy/paste and click on verify to check if it worked.

    I am using the developer branch that does not use the gw. stuff if that is what you mean?

    This is what I have tried for now but ofcourse it does not work.

    // Enable debug prints
    #define MY_DEBUG
    #define MY_BAUD_RATE 115200
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensor.h>  
    #include <NewPing.h>
    
    #define SONAR_A_CHILD_ID 1
    #define SONAR_B_CHILD_ID 2
    #define MOTION_A_CHILD_ID 3
    
    
    #define SONAR_A_TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define SONAR_A_ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MOTION_A_TRIGGER_PIN  2
    
    #define SONAR_B_TRIGGER_PIN  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define SONAR_B_ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
    
    #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
    
    unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    
    NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    
    
    MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
    int SONAR_A_lastDist;
    
    MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
    int SONAR_B_lastDist;
    
    MyMessage msg(MOTION_A_msg, V_TRIPPED);
    
    boolean metric = true; 
    
    void setup()  
    { 
      metric = getConfig().isMetric;
      pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Distance+Motion Sensor", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(SONAR_A_CHILD_ID, S_DISTANCE);
      present(SONAR_B_CHILD_ID, S_DISTANCE);
      present(MOTION_A_TRIGGER_PIN, S_MOTION);
    }
    
    void loop()      
    {     
      
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
      
        
      Serial.println(tripped);
      send(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);
    }
    }
    

    Error: 'MOTION_A_msg' was not declared in this scope

    TheoLT 2 Replies Last reply
    0
    • Cliff KarlssonC Cliff Karlsson

      Absolutley none offence taken, I really suck at coding and my main methods are copy/paste and click on verify to check if it worked.

      I am using the developer branch that does not use the gw. stuff if that is what you mean?

      This is what I have tried for now but ofcourse it does not work.

      // Enable debug prints
      #define MY_DEBUG
      #define MY_BAUD_RATE 115200
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensor.h>  
      #include <NewPing.h>
      
      #define SONAR_A_CHILD_ID 1
      #define SONAR_B_CHILD_ID 2
      #define MOTION_A_CHILD_ID 3
      
      
      #define SONAR_A_TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define SONAR_A_ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
      #define MOTION_A_TRIGGER_PIN  2
      
      #define SONAR_B_TRIGGER_PIN  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define SONAR_B_ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
      unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
      
      unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
      
      NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      
      MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
      int SONAR_A_lastDist;
      
      MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
      int SONAR_B_lastDist;
      
      MyMessage msg(MOTION_A_msg, V_TRIPPED);
      
      boolean metric = true; 
      
      void setup()  
      { 
        metric = getConfig().isMetric;
        pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Distance+Motion Sensor", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(SONAR_A_CHILD_ID, S_DISTANCE);
        present(SONAR_B_CHILD_ID, S_DISTANCE);
        present(MOTION_A_TRIGGER_PIN, S_MOTION);
      }
      
      void loop()      
      {     
        
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
        
          
        Serial.println(tripped);
        send(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);
      }
      }
      

      Error: 'MOTION_A_msg' was not declared in this scope

      TheoLT Offline
      TheoLT Offline
      TheoL
      Contest Winner
      wrote on last edited by
      #10

      @Cliff-Karlsson I'm sorry I haven't played with the development branch. I'm just using 1.5.4. But the part abount interrupts and pin2 and 3 stays the same. It's just how the Arduino works.

      1 Reply Last reply
      0
      • Cliff KarlssonC Cliff Karlsson

        Absolutley none offence taken, I really suck at coding and my main methods are copy/paste and click on verify to check if it worked.

        I am using the developer branch that does not use the gw. stuff if that is what you mean?

        This is what I have tried for now but ofcourse it does not work.

        // Enable debug prints
        #define MY_DEBUG
        #define MY_BAUD_RATE 115200
        // Enable and select radio type attached
        #define MY_RADIO_NRF24
        //#define MY_RADIO_RFM69
        
        #include <SPI.h>
        #include <MySensor.h>  
        #include <NewPing.h>
        
        #define SONAR_A_CHILD_ID 1
        #define SONAR_B_CHILD_ID 2
        #define MOTION_A_CHILD_ID 3
        
        
        #define SONAR_A_TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
        #define SONAR_A_ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
        #define MOTION_A_TRIGGER_PIN  2
        
        #define SONAR_B_TRIGGER_PIN  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
        #define SONAR_B_ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
        
        #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
        unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
        
        unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
        #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
        
        NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
        NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
        
        
        MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
        int SONAR_A_lastDist;
        
        MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
        int SONAR_B_lastDist;
        
        MyMessage msg(MOTION_A_msg, V_TRIPPED);
        
        boolean metric = true; 
        
        void setup()  
        { 
          metric = getConfig().isMetric;
          pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
        }
        
        void presentation() {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Distance+Motion Sensor", "1.0");
        
          // Register all sensors to gw (they will be created as child devices)
          present(SONAR_A_CHILD_ID, S_DISTANCE);
          present(SONAR_B_CHILD_ID, S_DISTANCE);
          present(MOTION_A_TRIGGER_PIN, S_MOTION);
        }
        
        void loop()      
        {     
          
          boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
          
            
          Serial.println(tripped);
          send(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);
        }
        }
        

        Error: 'MOTION_A_msg' was not declared in this scope

        TheoLT Offline
        TheoLT Offline
        TheoL
        Contest Winner
        wrote on last edited by
        #11

        @Cliff-Karlsson I think you want this:

        MyMessage msg(MOTION_A_CHILD_ID, V_TRIPPED);
        
        boolean metric = true; 
        

        instead of

        MyMessage msg(MOTION_A_msg, V_TRIPPED);
        
        boolean metric = true; 
        
        
        1 Reply Last reply
        0
        • Cliff KarlssonC Offline
          Cliff KarlssonC Offline
          Cliff Karlsson
          wrote on last edited by
          #12

          Thanks, sorry fore code-spamming but it feels like I am starting to get close to the first step witch is a succesful verify.
          The whole sketch verifies ok until it gets to the last "sleep" then I get this error:

          "expected constructor, destructor, or type conversion before '(' token"

          // Enable debug prints
          #define MY_DEBUG
          #define MY_BAUD_RATE 115200
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          #include <SPI.h>
          #include <MySensor.h>  
          #include <NewPing.h>
          
          #define SONAR_A_CHILD_ID 1
          #define SONAR_B_CHILD_ID 2
          #define MOTION_A_CHILD_ID 3
          
          
          #define SONAR_A_TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
          #define SONAR_A_ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
          #define MOTION_A_TRIGGER_PIN  2
          
          #define SONAR_B_TRIGGER_PIN  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
          #define SONAR_B_ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
          
          #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
          unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
          
          unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
          #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
          
          NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
          NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
          
          
          MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
          int SONAR_A_lastDist;
          
          MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
          int SONAR_B_lastDist;
          
          MyMessage MOTION_A_msg(MOTION_A_CHILD_ID, V_TRIPPED);
          
          boolean metric = true; 
          
          void setup()  
          { 
            metric = getConfig().isMetric;
            pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
          }
          
          void presentation() {
            // Send the sketch version information to the gateway and Controller
            sendSketchInfo("Distance+Motion Sensor", "1.0");
          
            // Register all sensors to gw (they will be created as child devices)
            present(SONAR_A_CHILD_ID, S_DISTANCE);
            present(SONAR_B_CHILD_ID, S_DISTANCE);
            present(MOTION_A_TRIGGER_PIN, S_MOTION);
          }
          
          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);
          //}
          }
          
          TheoLT 1 Reply Last reply
          0
          • Cliff KarlssonC Cliff Karlsson

            Thanks, sorry fore code-spamming but it feels like I am starting to get close to the first step witch is a succesful verify.
            The whole sketch verifies ok until it gets to the last "sleep" then I get this error:

            "expected constructor, destructor, or type conversion before '(' token"

            // Enable debug prints
            #define MY_DEBUG
            #define MY_BAUD_RATE 115200
            // Enable and select radio type attached
            #define MY_RADIO_NRF24
            //#define MY_RADIO_RFM69
            
            #include <SPI.h>
            #include <MySensor.h>  
            #include <NewPing.h>
            
            #define SONAR_A_CHILD_ID 1
            #define SONAR_B_CHILD_ID 2
            #define MOTION_A_CHILD_ID 3
            
            
            #define SONAR_A_TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
            #define SONAR_A_ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
            #define MOTION_A_TRIGGER_PIN  2
            
            #define SONAR_B_TRIGGER_PIN  8  // Arduino pin tied to trigger pin on the ultrasonic sensor.
            #define SONAR_B_ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
            
            #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
            unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
            
            unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
            #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
            
            NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
            NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
            
            
            MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
            int SONAR_A_lastDist;
            
            MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
            int SONAR_B_lastDist;
            
            MyMessage MOTION_A_msg(MOTION_A_CHILD_ID, V_TRIPPED);
            
            boolean metric = true; 
            
            void setup()  
            { 
              metric = getConfig().isMetric;
              pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
            }
            
            void presentation() {
              // Send the sketch version information to the gateway and Controller
              sendSketchInfo("Distance+Motion Sensor", "1.0");
            
              // Register all sensors to gw (they will be created as child devices)
              present(SONAR_A_CHILD_ID, S_DISTANCE);
              present(SONAR_B_CHILD_ID, S_DISTANCE);
              present(MOTION_A_TRIGGER_PIN, S_MOTION);
            }
            
            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);
            //}
            }
            
            TheoLT Offline
            TheoLT Offline
            TheoL
            Contest Winner
            wrote on last edited by
            #13

            @Cliff-Karlsson To me that's what this community is about. I'll have a loop. But no promise, as said before I haven't played with the development branch yet. But I do understand the compiler error

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

              @TheoL said:

              what this community is about. I'll have a loop. But no promise, as said before I haven't played with the development branch yet. But I do understand the compiler error

              Thanks.
              And if unclear I am trying to achieve in the end is:

              When PIR senses motion, activate both distance sensors for 30 seconds and deactivate PIR.
              After 30 seconds deactivate distance sensors and activate PIR again.

              TheoLT 2 Replies Last reply
              0
              • Cliff KarlssonC Cliff Karlsson

                @TheoL said:

                what this community is about. I'll have a loop. But no promise, as said before I haven't played with the development branch yet. But I do understand the compiler error

                Thanks.
                And if unclear I am trying to achieve in the end is:

                When PIR senses motion, activate both distance sensors for 30 seconds and deactivate PIR.
                After 30 seconds deactivate distance sensors and activate PIR again.

                TheoLT Offline
                TheoLT Offline
                TheoL
                Contest Winner
                wrote on last edited by
                #15

                @Cliff-Karlsson Is it giving the error on the first or the second sleep?

                I have to compliment @Hek and the other guys. They've made MySensors easier to program. The branch looks really great. Love it.

                1 Reply Last reply
                0
                • Cliff KarlssonC Cliff Karlsson

                  @TheoL said:

                  what this community is about. I'll have a loop. But no promise, as said before I haven't played with the development branch yet. But I do understand the compiler error

                  Thanks.
                  And if unclear I am trying to achieve in the end is:

                  When PIR senses motion, activate both distance sensors for 30 seconds and deactivate PIR.
                  After 30 seconds deactivate distance sensors and activate PIR again.

                  TheoLT Offline
                  TheoLT Offline
                  TheoL
                  Contest Winner
                  wrote on last edited by
                  #16

                  @Cliff-Karlsson I think I found it.

                  it's in this part

                  
                      sleep(SLEEP_TIME);
                    }
                              } // <--------- this ends the loop() method
                  //else{
                    // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
                    sleep(INTERRUPT,CHANGE, MOTION_SLEEP_TIME); // <---- so this is not in the method
                  //}
                  } // <-------- int this is also outside of the loop method
                  

                  Change it to:

                  
                      sleep(SLEEP_TIME);
                    }
                   //           }  // comment brace
                  //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
                  • Cliff KarlssonC Offline
                    Cliff KarlssonC Offline
                    Cliff Karlsson
                    wrote on last edited by
                    #17

                    After commenting the bracket I get : 'DIGITAL_INPUT_SENSOR' was not declared in this scope

                    TheoLT 1 Reply Last reply
                    0
                    • Cliff KarlssonC Cliff Karlsson

                      After commenting the bracket I get : 'DIGITAL_INPUT_SENSOR' was not declared in this scope

                      TheoLT Offline
                      TheoLT Offline
                      TheoL
                      Contest Winner
                      wrote on last edited by
                      #18

                      @Cliff-Karlsson I'm sorry would love help you further. But it's getting late over here and my better half wants me to turn off the laptop.

                      1 Reply Last reply
                      0
                      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