Which magnetic door/window switch for battery powered projects?



  • Hi,
    I am new to MySensors and planning to build battery powered window/door sensors based on a "raw" ATMEGA328P with 2xAA batteries.

    I am opting for the usual, cheap white Ali door switches (e.g. https://www.aliexpress.com/item/32255861885.html?spm=a2g0o.productlist.0.0.29ec3a95TEE6We&algo_pvid=48234541-eff1-4f39-96ee-284b1da18796&algo_expid=48234541-eff1-4f39-96ee-284b1da18796-1&btsid=2100bde316181377232332753e08a1&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_).

    But the thing confusing me is the "Normally Closed"/NC and "normally open" /NO.

    In my understanding NC means that the circuit is closed = current can flow. So for a battery project I think it is best to use NO switches, which only connect when the door/window is opened and therefore wake up the sensor to send a message.

    But, NO switches seem to be hard to come by at Ali.

    Am I missing something or do I misunderstand something? What would be the best setup for a battery powered project?



  • If you put a large resistor (>100K) between the pin you want to use for sensing and Vcc (battery voltage) then link one of the wires of the sensor to gnd and the other wire to the sense pin the circuit can then check for a change.

    So if the window is shut then the sense pin will be Vcc if it’s open then it will be 0V

    I hope that helps



  • @maddhin You need to look for "changeover reed relay" - they are cheap and allow you to reverse the logic in the door/window sketch and get a much longer battery life.

    I connect a 5.6Mohm from input pin to ground and then via the relay contacts that are OPEN when in magnetic field to VCC (3V).
    This way the input is always at ground until the door/window opens and then only a small current flows into the input and via that big resistance to ground.

    These relays are glass and can be fragile, so handle with care and make something to put them in to protect them.

    https://www.aliexpress.com/item/32831085928.html



  • @skywatch said in Which magnetic door/window switch for battery powered projects?:

    @maddhin You need to look for "changeover reed relay" - they are cheap and allow you to reverse the logic in the door/window sketch and get a much longer battery life.

    Awesome, thank you for this. I came across those switches but I would find it troublesome to install them if I can find ready-to-install sets for similar price.

    I found a useful answer over at stackexchange, where they recommend your and @Richard_Ske's solution as well: connect Vcc with a large resistor (3.3MOhm) and input pin and input pin/resistor with switch and grd. According to that post, the power consumption is not much higher than a NO setup.

    Would that be about right? You write "much longer battery life" for NO setup. If there is a large difference in power consumption, I would go and try to find NO switches, which exist, but are significantly more expensive (relatively speaking). It is very hard for me to judge this as my skills are limited. I would love to operate a bunch of SlimNodes with 2 x AA batteries.



  • @maddhin I am running with 2xAAA and so far so good - been 8 weeks and still at or above 3V.

    As for the relays, you could put them in any small plastic tube (ballpoint pen or similar) or even in a white plastic drinking straw, cut to length and seal the ends with silicone. Maybe add some plastic or wood (toothpicks glued together) for strength....Just a suggestion to keep costs down.....If you have access to a 3D printer then you can custom make something......



  • @skywatch awesome! Once all my parts arrive, I'll test as well! I'm planning a letterbox sensor, so usage will be minimal (1-3 events a day), hence my concern with the power consumption NO vs. NC. But if battery life (out of 2 x AA) is 2 years+, it shall be ok πŸ™‚
    I guess, I just need to build and test...
    One issue I'll be facing is that the cable between ATMEGA328P and the sensor will be 50-60cm. I read that this could cause issues with the large resistor method:(



  • @maddhin You attach the 'large resistor' on the ATmega board from ground to input pin used for interrupt. Then connect the same input pin to 3V via the reed relay switch contacts that are OPEN when the door/window/letterbox is in the untripped (closed) position. If you use the sketch on here you need to reverse the tripped/untripped (open/closed) as the basic sketch is negative triggered and this way it is positive triggered -

    I doubt that you will have issues with the cable at such short distance, but if you do just drop down to the next lowest value resistor and try again until you have the desired result. I assume you know about removal of components (or track cutting) and bootloading to get max battery life?

    I am sure you will work it out but if not post again and I will always try and help you! πŸ™‚



  • Honeywell SM35.


Log in to reply
 

Suggested Topics

  • 34
  • 7
  • 1
  • 1
  • 8
  • 3
  • 9
  • 1

141
Online

10.0k
Users

10.5k
Topics

108.7k
Posts