💬 Door, Window and Push-button Sensor


  • Admin

    This thread contains comments for the article "Door, Window and Push-button Sensor" posted on MySensors.org.



  • Hello. I used that example for open gate and doorbell and i think the 1 / 0 values are reversed.
    I mean . Switch button it's connected between , by example PIN 2 ... and ground ,so PIN 2 its always ** 1** (),when i press the switch button it goes to 0. That cause my Vera have trigger values reversed... it's always triggered if i not change advance option trigger. should i change : send(msg2.set(value==HIGHT ? 1 : 0)); TO send(msg2.set(value==LOW ? 1 : 0)); ????


  • Mod

    @Tmaster yes that will work.

    You can also apply the techinque used in https://www.mysensors.org/build/relay where RELAY_ON/OFF are set by defines.



  • Is it possible to add multiple reed sensors to the one node? If so, can you just copy the basic code provided and paste it below that in the same sketch and change the arduino pins appropriately??


  • Mod

    @breimann yes



  • My sketch have 2 binary switches. Working very good.



  • what is "debouncer" for? I removed it from my sketch and it still works...


  • Mod

    @siod when a switch is pressed it can bounce, which can look like several presses to the mcu. More information is available at http://www.allaboutcircuits.com/textbook/digital/chpt-4/contact-bounce/


  • Hardware Contributor

    I did just build a similar sensor based on my small sensor node. I think the example code here isn't really perfect though (although its very basic, perhaps that was the only goal).

    As I wanted to use this with batteries I used an interrupt and sleep(). The deboucing library isn't really need, a short gw.wait(50); did it for me too.
    Here is my code (not yet updated to mysensors 2). Any comments? Perhaps we could update the example code too.



  • Dont forget to add a 10K resistor between GND and your PIN (in this example pin3)


  • Hardware Contributor

    @janvier123 Do you really need that? Shouldn't the internal pullups be enough?

    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);
    


  • for some reason the value was always "1" untill i "pushed the button" => then i got "0"
    however ive added an 10K resistors between the pin and gnd, and now it works fine :)

    maybe because its not an official UNO board?



  • i don't why, but debouncer.read(); always return 1, i was never able to send the status of the door, however, digitalRead(BUTTON_PIN) returns the actual value.

    since i am using this for reed switch, i believe i don't need the debouncing functionality do i ?


  • Hero Member

    @Meshx86 said:

    i don't why, but debouncer.read(); always return 1, i was never able to send the status of the door, however, digitalRead(BUTTON_PIN) returns the actual value.

    since i am using this for reed switch, i believe i don't need the debouncing functionality do i ?

    Hello,

    yes you can get rid of the debouncing stuff for your reed switch (or any physical switch) if you are sleeping and waking up on interrupt, just add a little wait before you read the value to let the switch settle.
    If you are running at 1MHz then the time to wake up from sleep is longer (45ms if I remember well) and you don't even need the sleep.



  • What is the way to put the sketch on a sensebender with battery powered ?



  • Is the BinarySwitchSleepSensor a good answer ?



  • @Meshx86

    I have the same problem, when I use the bounce library to read my reed switch I always read "1". If I use digitalRead I get an bounce error.
    I have an arduino compatible, configure it for 1Mhz, 1M resistor for the reed switch and 2 AA battery.
    Someone has a similar one working?



  • @Jic i was wondering what's the purpose of the 1 M resistor on the reed switch ?
    i used 2 x AA battery, digitalRead, 8 MHz stock clock and no resistor, i know this might not be the most optimized power consumption setup



  • Nuub here..
    Thinking about building this in my mailbox..
    AND if possible set a green light diode to start light when box is opened and stop when its opened again.

    That way i would see when i come home if someone has opened the mailbox or not.. Sure push notifications work aswell but it would be a nice touch for the wifey


  • Hero Member

    @meanmrgreen if you use a led it will draw a few mA when on and battery life will be poor.
    At best you could wake up every few seconds and flash it briefly (like 100ms or less). In that case use a low value current limiting resistor to have an intense flash, and probably a red LED is better.
    To stop the blinking why not use a button (or touch button, check TTP223 in AliExpress) inside the mailbox ?


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.