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. Please can you tell me where I have gone wrong here?

Please can you tell me where I have gone wrong here?

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 4 Posters 1.6k 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.
  • skywatchS Offline
    skywatchS Offline
    skywatch
    wrote on last edited by skywatch
    #1

    Hi all,

    I have a sketch to monitor a door/window and that tesed OK - Then I decided to add an anti-tamper switch to the box and whatever I try I cannot get it to work....

    Here is the code....

    
    
    // Enable debug prints
    // #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL RF24_PA_LOW  //Options are: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH or RF24_PA_MAX
    
    #include <MySensors.h>
    
    uint32_t SLEEP_TIME = 900000; // Sleep time between reports (in milliseconds) approx eveery 15 mins.
    #define DIGITAL_INPUT_SENSOR_2 2   // Anti-Tamper switch connection.
    #define DIGITAL_INPUT_SENSOR_3 3   // The digital input you attached your Door/Window sensor.
    #define CHILD_ID_1 2   // Id of the Anti-Tamper sensor child.
    #define CHILD_ID_2 3   // Id of the door/window sensor child.
    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
    int batteryPcnt = 0;
    
    // Initialize door/window message
    MyMessage msg( CHILD_ID_1, V_TRIPPED);  //Tamper.
    MyMessage msg1( CHILD_ID_2, V_TRIPPED); //Door/Window.
    
    void setup()
    {
      pinMode(DIGITAL_INPUT_SENSOR_3, INPUT);      // sets the door/window sensor digital pin as input
      digitalWrite(DIGITAL_INPUT_SENSOR_3, HIGH);
      pinMode(DIGITAL_INPUT_SENSOR_2, INPUT);      // sets the Anti-Tamper sensor digital pin as input
      digitalWrite(DIGITAL_INPUT_SENSOR_2, HIGH);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Patio Door", "3.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_1, S_DOOR, "Patio Tamper");
      present(CHILD_ID_2, S_DOOR, "Patio Door");
    }
    
    void loop()
    {
      ////to be tested ........../////
      // Read digital anti-tamper.
      {
      bool tripped = digitalRead(DIGITAL_INPUT_SENSOR_2) == HIGH;
      {
        send(msg.set(tripped ? "1" : "0")); // Send anti-tamper tripped value to gw
      }
    }
    {
      //Read digital door/window value.
      bool tripped = digitalRead(DIGITAL_INPUT_SENSOR_3) == HIGH;
      {
         send(msg1.set(tripped ? "1" : "0")); // Send door/window tripped value to gw
      }
    }  
      { 
        int sensorValue = analogRead(BATTERY_SENSE_PIN);
        batteryPcnt = sensorValue / 10;
        sendBatteryLevel(batteryPcnt);
      }
    
      // Sleep until interrupt comes in on motion sensor. Send battery update every 15 minutes.
      sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_2) || digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_3), CHANGE, SLEEP_TIME);
    }
    

    The door/window pin works and the data gets sent to the controller, but it never sees any data from the anti-tamper switch....I have tried a few things but I cannot get both switches to work - what have I got wrong here please?

    mfalkviddM 1 Reply Last reply
    0
    • skywatchS skywatch

      Hi all,

      I have a sketch to monitor a door/window and that tesed OK - Then I decided to add an anti-tamper switch to the box and whatever I try I cannot get it to work....

      Here is the code....

      
      
      // Enable debug prints
      // #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      #define MY_RF24_PA_LEVEL RF24_PA_LOW  //Options are: RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH or RF24_PA_MAX
      
      #include <MySensors.h>
      
      uint32_t SLEEP_TIME = 900000; // Sleep time between reports (in milliseconds) approx eveery 15 mins.
      #define DIGITAL_INPUT_SENSOR_2 2   // Anti-Tamper switch connection.
      #define DIGITAL_INPUT_SENSOR_3 3   // The digital input you attached your Door/Window sensor.
      #define CHILD_ID_1 2   // Id of the Anti-Tamper sensor child.
      #define CHILD_ID_2 3   // Id of the door/window sensor child.
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      int batteryPcnt = 0;
      
      // Initialize door/window message
      MyMessage msg( CHILD_ID_1, V_TRIPPED);  //Tamper.
      MyMessage msg1( CHILD_ID_2, V_TRIPPED); //Door/Window.
      
      void setup()
      {
        pinMode(DIGITAL_INPUT_SENSOR_3, INPUT);      // sets the door/window sensor digital pin as input
        digitalWrite(DIGITAL_INPUT_SENSOR_3, HIGH);
        pinMode(DIGITAL_INPUT_SENSOR_2, INPUT);      // sets the Anti-Tamper sensor digital pin as input
        digitalWrite(DIGITAL_INPUT_SENSOR_2, HIGH);
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Patio Door", "3.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_1, S_DOOR, "Patio Tamper");
        present(CHILD_ID_2, S_DOOR, "Patio Door");
      }
      
      void loop()
      {
        ////to be tested ........../////
        // Read digital anti-tamper.
        {
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR_2) == HIGH;
        {
          send(msg.set(tripped ? "1" : "0")); // Send anti-tamper tripped value to gw
        }
      }
      {
        //Read digital door/window value.
        bool tripped = digitalRead(DIGITAL_INPUT_SENSOR_3) == HIGH;
        {
           send(msg1.set(tripped ? "1" : "0")); // Send door/window tripped value to gw
        }
      }  
        { 
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          batteryPcnt = sensorValue / 10;
          sendBatteryLevel(batteryPcnt);
        }
      
        // Sleep until interrupt comes in on motion sensor. Send battery update every 15 minutes.
        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_2) || digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_3), CHANGE, SLEEP_TIME);
      }
      

      The door/window pin works and the data gets sent to the controller, but it never sees any data from the anti-tamper switch....I have tried a few things but I cannot get both switches to work - what have I got wrong here please?

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

      @skywatch the sleep call in the code is very strange. I think you want to use this function:

      int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
      

      Reference for sleep: https://www.mysensors.org/download/sensor_api_20#sleeping

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

        Hi @Mfalkvidd -

        Yes I just tracked it down to that line with w few serial.prints..... Thanks for the fast reply - I will try again! :)

        and

        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_2), CHANGE, digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_3), CHANGE, SLEEP_TIME);
        

        This way it works! :) - Thank you! :)

        1 Reply Last reply
        1
        • wallyllamaW Offline
          wallyllamaW Offline
          wallyllama
          wrote on last edited by
          #4

          The alternative answer is that you chose a hobby that will take up all your spare time and burn all your extra money.

          zboblamontZ 1 Reply Last reply
          0
          • wallyllamaW wallyllama

            The alternative answer is that you chose a hobby that will take up all your spare time and burn all your extra money.

            zboblamontZ Offline
            zboblamontZ Offline
            zboblamont
            wrote on last edited by
            #5

            @wallyllama Ah, you mean marriage? Sorry, couldn't resist.... :)

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

              @wallylama

              I already did that! :o - That's why I now need to make it all work!!! :)

              1 Reply Last reply
              2

              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


              12

              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