💬 Door, Window and Push-button Sensor



  • Thank you I'll give that a go.



  • Hi,
    Maybe it is a little off-topic here, but maybe you could point me to the right direction: I want to build nice wall switch, and from technological point of view it is not that difficult using mysensors, this part is clear, including battery powering or making some kind of power conversion from AC to DC (in openhardware there are quite a few examples on that). What is bothering me is the switch "enclosure". I have one example from TKB Home:
    http://www.ebay.de/itm/TKB-Home-Z-Wave-Plus-Dual-Paddle-Wall-Switch-TZ56D-ZW5-/122201876698?ssPageName=ADME:X:EAC:GB:1120
    that I have bought to try with smarttnings controller (which is not intended to work with, now I know), but what it has - it is the enclosure: it is nice switch with 2 micro switches inside (4 in total, since it is dual wall switch), that are not locking in the pressed position - you press up and it clicks one button/switch and returns back to its initial "neutral" position, you press down - again, click and back to "neutral".
    I think the similar are are in aliexpress, that are called like wall wireless remote switch Transmitter, but I'm not sure about that, since I didn't bought one to disassemble.
    Maybe some one have met something similar for making some nice RF controlled wall switches?

    Thanks in advance!
    Regards


  • Hardware Contributor

    @Justas Hello, please check the dedicated category, if you don't find your hapiness please post there 🙂

    https://forum.mysensors.org/category/42/enclosures-3d-printing



  • I tried this today and it wouldn't find a parent.

    Adding #define MY_NODE_ID 1 seems to have solved the problem, so maybe this (and other) examples need to be updated with this info?

    Thanks for the work on this project though, I think it will be a lort of fun when I get it all working! 🙂


  • Mod

    @skywatch that shouldn't bee needed. Would it be possible for you to post the entire log from when the node was unable to find parent?



  • I'll see if I can replicate it ...been nusy trying to sork out a controller now Heheh.....Not fun!



  • I just uploaded the sketch again without the define and it is working - I didn't clear the eeprom before uploading so maybe that would have made a difference? Is there a list of what is held in eeprom anywhere?



  • Hi instead of using a arduino nano can i use esp8266 for a sensor


  • Mod

    @joseyapor yes you can but the esp8266 has very few usable io pins so connecting a radio and sensor at the same time might be difficult.



  • @joseyapor Yes no problem. 8 digital I/O. One of them a bit problematic as input (used for program mode)



  • Another newbie sorry.
    Trying to use this as a simple doorbell, just to send a trigger to Domoticz.

    I connect doorbell button to digital pin 3, the Node appears in Domoticz ok as a "security sensor" but shows as state "ON". However pressing the button appears to do nothing sadly, switch status stays as on, and log shows no activity at all?

    Using a Uno (clone) and wondering if somethings up with it? 😞


  • Hardware Contributor

    What does the nodes and/or the gateways log say?
    It might not change in domoticz if you just send on but no off signals but it should still be visible in the nodes log (arduino and in domotizc)



  • Hold that thought, embarrassingly it might just be a bad connection! Oops
    Just took it all apart in frustration, had a cuppa and put it back together.
    And something is triggering now, need to play some more, but first hurdle looks like possibly a simply connection maybe.
    I'll let you know.



  • Not sure what I'm doing wrong but I tried to add more than one sensor and didn't get very far. Was hoping to do a motion and a door sensor from the same arduino.



  • As doors and windows are usually not near power sources would it not be better to have this sketch with a SLEEP function and trigger on interupt?



  • what is the logic of the variable "V_TRIPPED"to use? I just messed a little with the MyController application, and by using the V_TRIPPED the value changes from off to on,and stays on,even if the button is released? ( simular to close an opened door)
    Should the variable not be of a binary type with according sensor type?



  • Hi,
    I have my sensor working well, Arduino pro mini with an Ethernet gateway using Home Assistant. .This is the first sensor I'm actually using a battery, so I've never really needed it, I see the battery level in HA as 0, how do I turn that on and use the battery level? Any pointers?
    Thanks!
    Jim



  • Dumb question, but how would I set this sketch to have an array of 5 switches? I’ve tried a couple of things but I’m lost





  • Hi,
    I rewrite sketch for doors/window/buttons to work with multiple buttons (no rellays) .It shows up in Domoticz but it did not change status buttons if pressed.
    Can someone look for the skech what I am doing wrong

    /**
      The MySensors Arduino library handles the wireless radio link and protocol
      between your home built sensors/actuators and HA controller of choice.
      The sensors forms a self healing radio network with optional repeaters. Each
      repeater and gateway builds a routing tables in EEPROM which keeps track of the
      network topology allowing messages to be routed to nodes.
    
      Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
      Copyright (C) 2013-2015 Sensnology AB
      Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    
      Documentation: http://www.mysensors.org
      Support Forum: http://forum.mysensors.org
    
      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      version 2 as published by the Free Software Foundation.
    
    *******************************
    
      DESCRIPTION
    
      Simple binary switch example updated  for 2 switches
      Connect button or door/window reed switch between
      digitial I/O pin 3 (BUTTON_PIN below) and GND.
      http://www.mysensors.org/build/binary
    */
    
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_GATEWAY_SERIAL
    
    //#include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define FIRST_PIN  8  // Arduino Digital I/O pin for button/reed switch
    #define noButtons 4
    const int buttonPin[noButtons];
    
    Bounce debouncer[noButtons] = Bounce();
    
    int oldValue[noButtons];
    
    MyMessage msg[noButtons];
    
    void setup() {
    
     for (int i = 0; i < noButtons; i++) {
    
       msg[i].sensor = i;                                   // initialize messages
       msg[i].type = V_TRIPPED; //
    
       pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);
       digitalWrite(buttonPin[i + FIRST_PIN], HIGH);
       debouncer[i] = Bounce();                        // initialize debouncer
       debouncer[i].attach(buttonPin[i + FIRST_PIN]);
       debouncer[i].interval(30);
     }
    }
    
    void presentation() {
     sendSketchInfo("Doors", "1.0");
     for (int i = 0; i < noButtons; i++)
       present(i, S_DOOR);                               // present sensor to gateway
    
    
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
     for (int i = 0; i < noButtons; i++) {
       debouncer[i].update();
    
       int value = debouncer[i].read();
       if (value != oldValue[i]) {
    
         // Send in the new value
         send(msg[i].set(value == HIGH ? 1 : 0));
         oldValue[i] = value;
       }
    
     }
    }
    

  • Mod

    @rodaman 0_1474354717994_upload-0e56e228-365f-4d94-90b3-5cf1305c6fae

    I fixed it for you.



  • @mfalkvidd
    thank you, i hope will be good soul who fix my sketch itself to work... 🙂


  • Admin

    @rodaman said in 💬 Door, Window and Push-button Sensor:

    What is the purpose of the buttonPin-array?

    E.g.

    pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);

    This will fetch a random (probably 0-initialised) value from the array and set pinmode on that value...



  • @hek
    That part was in original sketch for establish internal pullup as I understand. I used array to do it for each pins.



  • @hek
    I have changed

    pinMode(buttonPin[i + FIRST_PIN], INPUT_PULLUP);
    

    to

    pinMode(buttonPin[i + FIRST_PIN], INPUT);
    

    thanks, but sadlly still does not work...


  • Admin

    @rodaman said in 💬 Door, Window and Push-button Sensor:

    http://www.mysensors.org/build/binary

    I don't get the buttonPin array thing at all?

    Why not just:
    pinMode(i + FIRST_PIN, INPUT_PULLUP);


  • Mod

    @hek if the array was initialized, it could be used to set arbitrary pins. So pin 4,5,6,7,8,A0,A1,A2,A3 could be used for example (to avoid conflicts with the standard nrf24 wiring but still allow a lot of buttons). But as you mentioned before, without initializing the array the behavior will be strange.



  • @hek said in 💬 Door, Window and Push-button Sensor:

    pinMode(i + FIRST_PIN, INPUT_PULLUP);

    Big Thanks!
    I have changed all array parts in setup in the same manner like above and it works 🙂



  • @rodaman
    Hi,
    Here is a sketch for multi buttons (no relays, no repeated parts of code for each buttons) just enter number of buttons and first digital pin where buttons are attached.
    Thanks to @hek for help...

    /**
       The MySensors Arduino library handles the wireless radio link and protocol
       between your home built sensors/actuators and HA controller of choice.
       The sensors forms a self healing radio network with optional repeaters. Each
       repeater and gateway builds a routing tables in EEPROM which keeps track of the
       network topology allowing messages to be routed to nodes.
    
       Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       Copyright (C) 2013-2015 Sensnology AB
       Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    
       Documentation: http://www.mysensors.org
       Support Forum: http://forum.mysensors.org
    
       This program is free software; you can redistribute it and/or
       modify it under the terms of the GNU General Public License
       version 2 as published by the Free Software Foundation.
    
     *******************************
    
       DESCRIPTION
    
       Simple binary switch example updated  for multi switches
       Connect buttons or door/window reed switches between
       digitial I/O choosen pin  (FIRST_PIN below) and GND.
       http://www.mysensors.org/build/binary
    */
    
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_GATEWAY_SERIAL
    
    //#include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define FIRST_PIN  2  // Arduino Digital I/O pin for button/reed switch
    #define noButtons 6
    
    
    Bounce debouncer[noButtons] = Bounce();
    
    int oldValue[noButtons];
    int value;
    MyMessage msg[noButtons];
    
    void setup() {
    
      for (int i = 0; i < noButtons; i++) {
    
        oldValue[i] = -1;
        
        msg[i].sensor = i;                                   // initialize messages
        msg[i].type = V_TRIPPED; //
        pinMode(i + FIRST_PIN, INPUT_PULLUP);
        digitalWrite(i + FIRST_PIN, HIGH);
      
        debouncer[i] = Bounce();                        // initialize debouncer
        debouncer[i].attach(i + FIRST_PIN);
        debouncer[i].interval(3);
      }
    }
    
    void presentation() {
      sendSketchInfo("Doors", "1.0");
      for (int i = 0; i < noButtons; i++)
        present(i, S_DOOR);                               // present sensor to gateway
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
      for (int i = 0; i < noButtons; i++) {
        debouncer[i].update();
    
        value = debouncer[i].read();
        if (value != oldValue[i]) {
        // Send in the new value
          send(msg[i].set(value == HIGH ? 1 : 0));
          oldValue[i] = value;
        }
     }
    }
    
    

  • Mod

    Could these reed switches be used in the NC configuration for door/window sensor to save more battery?


  • Hardware Contributor

    @gohan
    yes exactly.
    i made a nrf5 board using this principle.


  • Mod

    did you use those with 3 pins?


  • Hardware Contributor

    yes no-nc reed, connect them to IOs of your mcu and switch between input and output


  • Hardware Contributor

    @gohan said in 💬 Door, Window and Push-button Sensor:

    did you use those with 3 pins?

    I use them, with one wire connected to each interrupt pin (I only activate the one that's not connected) and they work fine.
    Else you can cheat with a basic reed switch, you just need an additional magnet on the other side of your switch that's weaker than the door magnet, and turn your reed 180°.
    You make the weak magnet close the reed when door is opened and far from the strong door magnet. When you close the door the strong magnet will open the reed switch.


  • Mod

    given the low price, I think it is not worth the extra work to "mod" the normal reed switches 😄


  • Plugin Developer

    I'd like to go even simpler:

    • Window is closed - magnet pulls reed switch so that no power flows to the NRF5.
    • Window is opened - The NRF5 now gets power, boots, connects to the MySensors network, and sends a "window is open" message every 10 minutes.
    • Window is closed again - NRF5 loses power.

    Seems to me that this would be quite energy efficient?

    Perhaps build it into this case:
    https://www.aliexpress.com/item/Home-Burglar-Alarm-Wireless-Home-Security-Door-Window-Entry-Burglar-Alarm-System-Magnetic-Sensor-drop-shipping/32876055564.html
    (runs on 2 AAA batteries)


  • Hardware Contributor

    @alowhum
    I would say this technique is efficient depending on the usecase.
    For example, for basic ambiant sensors not needing any security why not. On other side, for main doors which could benefit security, I prefer to use hearbeat with less interval time, so it's possible to know if the sensor is offline. else controller wouldn't know this if the sensor only update when door state change.


  • Plugin Developer

    Totally true.

    I was wondering what the state of Attiny85 support is. For absolute beginners (in workshops) it might be easier to connect the radio to a digispark.

    // cancel that. It could never support encryption.



  • I have some troubles with this device.
    Sometimes it does not respond to the first click, sometimes it remains switched on after first click until second click

    When I press the button once - I see the LED on my gateway blinks always 3 times
    1 RX TX
    2 RX ERR
    3 RX ERR

    Device powered with CR2032 and running on 1Mhz@1.8V (internal clock)
    Button input pulled to GND with resistor 47K and waking up if VCC connected through the button
    Also have a 10uF tantal capacitor on power supply pins +several 0,1uF ceramic capacitors

    Actually I dont know how to debug/log my gateway messages on Linux

    Node code:

    
    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    #define MY_RF24_PA_LEVEL RF24_PA_HIGH
    
    #include <MySensors.h>
    
    #define SKETCH_NAME "Door button"
    #define SKETCH_MAJOR_VER "1"
    #define SKETCH_MINOR_VER "0"
    
    #define PRIMARY_CHILD_ID 3
    #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
    //#define BATTERY_SENSE_PIN A6  // select the input pin for the battery sense point
    int oldBatteryPcnt = 0;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
    
    void setup()
    {
      // Setup the buttons
      pinMode(PRIMARY_BUTTON_PIN, INPUT);
      //	pinMode(SECONDARY_BUTTON_PIN, INPUT_PULLUP);
    
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
      present(PRIMARY_CHILD_ID, S_DOOR);
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop()
    {
      uint8_t value;
      static uint8_t sentValue = 2;
    
      // Short delay to allow buttons to properly settle
      sleep(5);
    
      value = digitalRead(PRIMARY_BUTTON_PIN);
    
      if (value != sentValue) {
        // Value has changed from last transmission, send the updated value
        send(msg.set(value == HIGH));
        sentValue = value;
      }
    
      // Sleep until something happens with the sensor
      sleep(PRIMARY_BUTTON_PIN - 2, CHANGE, 0);
    }
    

    Serial data, one line = one button click

    4;3;1;0;16;0
    4;3;1;0;16;1
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;1
    4;3;1;0;16;1
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;1
    4;3;1;0;16;1
    4;3;1;0;16;1
    4;3;1;0;16;1
    4;3;1;0;16;1
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;0
    4;3;1;0;16;1
    4;3;1;0;16;0
    4;3;1;0;16;1
    

  • Mod

    Uncomment the my_debug and you should see all the debug info.



  • @gohan I cant to set correct speed for the serial port because used 1mhz@int osc
    I tried all options...


  • Mod

    You can do it on the gateway at least



  • @gohan already done but not possible to see anything
    Every line was shifted to the right side and finally no space left.
    I use minicom app for monitoring serial port

    ,1-1-0,s=3,c=1,t=16,pt=1,l=1,sg=,1-1-0,s=3,c=1,t=16,pt=1,l=1,sg=0:0
                                                                       ,1-1-0,s=3,c=1,t=16,pt=1,l=1,sg=0;255;3;0;9;3726496 TSF:MSG:READ0:0
                                                                                                                                          1;3;1;0;16;0
                                                                                                                                                      ,1-1-0,s=3,c=1,t=16,pt=1,l=1,sg=0;255;3;0;9;3727488 TSF:MSG:READ0:0
                                                                                                                                                                                                                         1;3;1;0;16;0
                                                                                                                                                                                                                                     ,1-1-0,s=3,c=1,t=16,pt=1,l=1,sg=0;255;3;0;9;3728475 TSF:MSG:READ0:0
                                                                                                                                                                                                                                                                                                        1;3;1;0;16;0
                                                                                                                                                                                                                                                                                                                    ,1-1-0,s=3,c1
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                0
                                                                                                                                                                                                                                                                                                                                0
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                =
    
    

    Actually i need to make 100-1000 clicks to catch a fail moment
    Here is working fine


  • Mod

    Can't you just use the arduino ide serial monitor?



  • This post is deleted!


  • This post is deleted!


  • I was build a new button node with new arduino (8mhz) and new nrf24, then update to 2.3.0 gateway and all other devices
    But now have a worse result than before

    16 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.3.0
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=11
    38 TSM:FPAR
    75 TSF:MSG:SEND,11-11-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    403 TSF:MSG:READ,0-0-11,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    409 TSF:MSG:FPAR OK,ID=0,D=1
    2084 TSM:FPAR:OK
    2084 TSM:ID
    2086 TSM:ID:OK
    2088 TSM:UPL
    2093 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2099 TSF:MSG:READ,0-0-11,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2105 TSF:MSG:PONG RECV,HP=1
    2109 TSM:UPL:OK
    2111 TSM:READY:ID=11,PAR=0,DIS=1
    2129 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2138 TSF:MSG:READ,0-0-11,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2168 TSF:MSG:SEND,11-11-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.0
    2179 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2187 TSF:MSG:READ,0-0-11,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2220 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:Door button
    2230 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.5
    2240 TSF:MSG:SEND,11-11-0-0,s=3,c=0,t=0,pt=0,l=0,sg=0,ft=0,st=OK:
    2246 MCO:REG:REQ
    2252 TSF:MSG:SEND,11-11-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2260 TSF:MSG:READ,0-0-11,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2267 MCO:PIM:NODE REG=1
    2269 MCO:BGN:STP
    2271 MCO:BGN:INIT OK,TSP=1
    2275 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    2279 TSF:TDI:TSL
    2281 MCO:SLP:WUP=-1
    2283 TSF:TRI:TSB
    2287 TSF:MSG:SEND,11-11-0-0,s=3,c=1,t=16,pt=1,l=1,sg=0,ft=0,st=OK:0
    2295 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    2299 TSF:TDI:TSL
    

    the pressing button twice

    30343 MCO:SLP:WUP=0
    30345 TSF:TRI:TSB
    30347 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    30353 TSF:TDI:TSL
    30355 MCO:SLP:WUP=-1
    30357 TSF:TRI:TSB
    32043 !TSF:MSG:SEND,11-11-0-0,s=3,c=1,t=16,pt=1,l=1,sg=0,ft=3,st=NACK:1
    32049 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    32055 TSF:TDI:TSL
    32057 MCO:SLP:WUP=0
    32059 TSF:TRI:TSB
    32061 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    32067 TSF:TDI:TSL
    32069 MCO:SLP:WUP=-1
    32071 TSF:TRI:TSB
    32073 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    32079 TSF:TDI:TSL
    32081 MCO:SLP:WUP=0
    32083 TSF:TRI:TSB
    32086 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    32092 TSF:TDI:TSL
    32094 MCO:SLP:WUP=-1
    32096 TSF:TRI:TSB
    33779 !TSF:MSG:SEND,11-11-0-0,s=3,c=1,t=16,pt=1,l=1,sg=0,ft=4,st=NACK:0
    33787 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    33794 TSF:TDI:TSL
    

    But no incoming messages at the gateway. Only several random messages coming to controller from one hundred button clicks
    Sometimes after fast series of clicks I get this:

    23179 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23183 !MCO:SLP:TNR
    23185 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23191 !MCO:SLP:TNR
    23218 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23222 !MCO:SLP:TNR
    23224 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23230 !MCO:SLP:TNR
    23257 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23261 !MCO:SLP:TNR
    23263 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23269 !MCO:SLP:TNR
    23296 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23300 !MCO:SLP:TNR
    23302 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23308 !MCO:SLP:TNR
    23336 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23341 !MCO:SLP:TNR
    23343 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23349 !MCO:SLP:TNR
    23377 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23382 !MCO:SLP:TNR
    23384 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23390 !MCO:SLP:TNR
    23418 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23422 !MCO:SLP:TNR
    23425 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23431 !MCO:SLP:TNR
    23459 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23463 !MCO:SLP:TNR
    23465 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23472 !MCO:SLP:TNR
    23500 !TSF:SND:TNR
    23502 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23506 !MCO:SLP:TNR
    23508 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23515 !MCO:SLP:TNR
    23543 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23547 !MCO:SLP:TNR
    23549 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23556 !MCO:SLP:TNR
    23584 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23588 !MCO:SLP:TNR
    23590 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23597 !MCO:SLP:TNR
    23625 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23629 !MCO:SLP:TNR
    23631 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23638 !MCO:SLP:TNR
    23666 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23670 !MCO:SLP:TNR
    23672 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23678 !MCO:SLP:TNR
    23707 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23711 !MCO:SLP:TNR
    23713 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23719 !MCO:SLP:TNR
    23746 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23750 !MCO:SLP:TNR
    23752 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23758 !MCO:SLP:TNR
    23785 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23789 !MCO:SLP:TNR
    23791 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23797 !MCO:SLP:TNR
    23824 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23828 !MCO:SLP:TNR
    23830 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23836 !MCO:SLP:TNR
    23863 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23867 !MCO:SLP:TNR
    23869 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23875 !MCO:SLP:TNR
    23902 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23906 !MCO:SLP:TNR
    23908 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23914 !MCO:SLP:TNR
    23941 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23945 !MCO:SLP:TNR
    23947 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23953 !MCO:SLP:TNR
    23980 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    23984 !MCO:SLP:TNR
    23986 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    23992 !MCO:SLP:TNR
    24014 TSF:MSG:READ,0-0-11,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    24020 TSF:MSG:FPAR OK,ID=0,D=1
    24025 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24029 !MCO:SLP:TNR
    24031 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24037 !MCO:SLP:TNR
    24064 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24068 !MCO:SLP:TNR
    24070 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24076 !MCO:SLP:TNR
    24104 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24109 !MCO:SLP:TNR
    24111 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24117 !MCO:SLP:TNR
    24145 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24150 !MCO:SLP:TNR
    24152 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24158 !MCO:SLP:TNR
    24186 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24190 !MCO:SLP:TNR
    24193 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24199 !MCO:SLP:TNR
    24227 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24231 !MCO:SLP:TNR
    24233 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24240 !MCO:SLP:TNR
    24268 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24272 !MCO:SLP:TNR
    24274 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24281 !MCO:SLP:TNR
    24309 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24313 !MCO:SLP:TNR
    24315 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24322 !MCO:SLP:TNR
    24350 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24354 !MCO:SLP:TNR
    24356 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24363 !MCO:SLP:TNR
    24391 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24395 !MCO:SLP:TNR
    24397 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24403 !MCO:SLP:TNR
    24432 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24436 !MCO:SLP:TNR
    24438 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24444 !MCO:SLP:TNR
    24471 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24475 !MCO:SLP:TNR
    24477 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24483 !MCO:SLP:TNR
    24510 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24514 !MCO:SLP:TNR
    24516 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24522 !MCO:SLP:TNR
    24549 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24553 !MCO:SLP:TNR
    24555 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24561 !MCO:SLP:TNR
    24588 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24592 !MCO:SLP:TNR
    24594 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24600 !MCO:SLP:TNR
    24627 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24631 !MCO:SLP:TNR
    24633 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24639 !MCO:SLP:TNR
    24666 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24670 !MCO:SLP:TNR
    24672 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24678 !MCO:SLP:TNR
    24705 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24709 !MCO:SLP:TNR
    24711 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24717 !MCO:SLP:TNR
    24745 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24750 !MCO:SLP:TNR
    24752 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24758 !MCO:SLP:TNR
    24786 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24791 !MCO:SLP:TNR
    24793 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24799 !MCO:SLP:TNR
    24827 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24832 !MCO:SLP:TNR
    24834 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24840 !MCO:SLP:TNR
    24868 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24872 !MCO:SLP:TNR
    24875 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24881 !MCO:SLP:TNR
    24909 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24913 !MCO:SLP:TNR
    24915 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24922 !MCO:SLP:TNR
    24950 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24954 !MCO:SLP:TNR
    24956 MCO:SLP:MS=25,SMS=0,I1=255,M1=255,I2=255,M2=255
    24963 !MCO:SLP:TNR
    24991 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    24995 !MCO:SLP:TNR
    24997 MCO:SLP:MS=25,
    

    Then it continue works as before

    Actually I have problems only with fu@ing button, most simplest device. Several month I can't to start use it.
    All other devices are working properly even on 2.3.0 ver. 😜


  • Mod

    Have you tried with a debouce? Just in case...



  • This post is deleted!


  • @gohan the default sketch with debounce library works better, but now i see my primary problem.
    Occasionally I have an ACK errors

    4231 TSF:MSG:SEND,21-21-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    4239 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    4245 TSF:TDI:TSL
    4247 MCO:SLP:WUP=0
    4249 TSF:TRI:TSB
    4290 !TSF:MSG:SEND,21-21-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=NACK:1
    4298 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    4302 TSF:TDI:TSL
    4304 MCO:SLP:WUP=0
    4306 TSF:TRI:TSB
    4313 TSF:MSG:SEND,21-21-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=1,st=OK:0
    4321 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
    

    I tried to icrease the time ack on my controller - it does not help
    Ithink that I need to ckeck ack state on the node and send the message again, but have no idea how to do


  • Mod

    you are at the limit of the radio range I'd say so randomly it looses a message, so you need to either increase power or get a better antenna (I hope you aren't using any buck/boost converter as power supply)



  • @gohan how you know?
    Id 21 from range 0..255. Are you sure that is limit?

    Same with any different IDs, I tried sending message 3 times, this guarantees delivery of payload, but it using too much power

    Now I use power supply with 1117

    But my other nodes powered by CR2032 with boost 0.8-3.3V dc/dc with inductor coil on the NRF24 supply pin without any troubles


  • Hardware Contributor

    @pavel-polititsky said in 💬 Door, Window and Push-button Sensor:

    @gohan how you know?
    Id 21 from range 0..255. Are you sure that is limit?

    He means radio range (distance) not ID of node 😉



  • @nca78 oke, undestood
    Problem stiil not resolved. I want to send message again to the gateway if NACK but dont know how to do it.

    send(msg.set(value == HIGH), true); 
    

    in this case i have additional ack log in the serial debug, nothing more


  • Mod

    The send function returns a value, so you can check if it was successfully sent or not and in case retry


  • Plugin Developer

    A quick ACK example:

            static boolean tryAgainLater = false; // should we resend?
    
            if(send(msgDust.setSensor(CHILD_ID_DUST_PM25).set(sensorValue),1)){
              Serial.println(F("Received ACK"));
              tryAgainLater = false;
            }else {
              Serial.println(F("Connection problem, try again"));
              tryAgainLater = true;
            }
    

  • Mod

    There is no need to set the second parameter to send() to true. That parameter is unrelated to the return value (except very unfortunate similar naming). More info: https://github.com/mysensors/MySensors/issues/1103


  • Plugin Developer

    @mfalkvidd said in 💬 Door, Window and Push-button Sensor:

    https://github.com/mysensors/MySensors/issues/1103

    Ah, thanks. So ACK basically always happens?

    in that case, do you have any better example code on how to check if the ACK is received?


  • Mod

    @alowhum on nrf24, "hardware" ack is always on. "Software" ack is controlled by the second parameter in the send() function. Read https://forum.mysensors.org/post/34267 for an attempt to sort out the details. It is still quite confusing for me.



  • What will happen if i cut the power OFF of the radio after each transmission? is it needed to be initialize again before next transmission?


  • Mod

    @tiana yes.

    But don't cut the power. Use transportDisable and transportReInitialize instead.



  • Do you know how much will be power usage in transportDisable mode?


  • Mod

    @tiana depends on which transport you are using, and if using genuine or clone chips. The nrf24 is rated for 900nA.



  • Thanks for fast reply, actually 900nA is to big number and i prefer to use xxx_POWER_PIN to cut the power of the NRF module.
    I am building switch powered with CR2032 battery and i want to extend battery live as much as possible, for a switch is not needed to keep radio alive, i need it ON only when transmit signal


  • Mod

    @tiana 900nA on a cr2032 is 27.9 years battery life. The self discharge of a cr2032 is around 250nA.
    But yes, use the power pin setting if you want to.

    Would be interesting to see how long sleep times are needed to make up for the extra time needed to wake up the radio from power off compared to sleep. The mcu and the radio will need to be awake for 100ms longer time when starting from power off than when starting from sleep.



  • Hi I notice that there is not sleep in this sketch. Is it not required for this build


  • Mod

    @terence-faul the sketch will work as-is, as long as the node has a constant power supply. If you want a battery-powered node, you'll need sleep. See earlier discussions in this thread for ways to add sleep.



  • Hi
    Can i connect two sensor contact to this arduino ? First to pin 3 second to pin 4 ? But how modified this sketch to support two sensor contact ?



  • @pepson If you need the node to sleep or want to use interrupts then only digital pins 2 and 3 will do this for uno/promini.

    So otherwise 2 options really.

    If you just need to know that one of the sensors triggered (but not which one) then you can add sensors in series (for normally 'closed' sensors) or parallel (for normally 'open' sensors).

    To use interrupt and know which sensor triggered you'd have to connect both sensor to interrupt pin with blocking diodes to digital pins as well and then on interrupt you can check which digital pin activated the isr.



  • I need connect two contact sensor. And i want to know from two sensor his status...
    I need use one to door but second to door garage.



  • @pepson Then just add another sensor from ground to digital pin 2 and change the code you see in the example to accommodate the extra input.

    You'll need to add another child id, another button, another bounce function, another presentation, another send and another bounce call.



  • @skywatch
    Yes but i dont know how do it.... 😞
    I dont know programing.


  • Hardware Contributor

    @pepson said in 💬 Door, Window and Push-button Sensor:

    @skywatch
    Yes but i dont know how do it.... 😞
    I dont know programing.

    Not an excuse, it's time for you to learn 🙂


  • Mod

    @pepson then it is going to be quite difficult for you to work on DIY electronics projects if you don't how to program.



  • Perhaps it would be good to update the example code. I mean the pull-up sequence:
    "It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor." - https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/
    The following seems to be obsolete:
    // Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 10
  • 5
  • 109
  • 584

55
Online

11.4k
Users

11.1k
Topics

112.6k
Posts