LowPowerLab Forum

Hardware support => Moteino => Topic started by: gianmarko on November 20, 2014, 01:45:22 PM

Title: magnetic switch on int
Post by: gianmarko on November 20, 2014, 01:45:22 PM
this is a somewhat silly question but my electronics knowledge is minimal

i have built a network of moteinos to check when the doors of the house get open. i used magnetic switches, connected to a int digital pin similar to how the PIR sensors are connected. i am using a pull-up resistors to raise the logic level to 1 when the switch opens, when the door opens

this however is of course using some current, that depletes the 9v battery much faster than with the PIR sensor.

is there a smarter way to connect a magnetic switch so that when closed it doesnt drain as much current? at the moment  current drain from the battery is around 1mA, so battery lasts 3-4 weeks at the most. im using cheap 9v batteries, duracell are very expensive. in the motion sensors battery lasts months.
Title: Re: magnetic switch on int
Post by: Felix on November 20, 2014, 02:42:17 PM
What kind of magnetic switches are you using? Are they reed switches?
For my GarageMote controller I used hall effect sensors that can be powered from a digital pin before taking a reading, hence reducing the power to 0 when not in use. The reading is almost instant and only a reading a second is needed for things like doors, so the overall power is very close to 0.
With a reed switch you could use a hardware interrupt (D3 which is available, D2 is used by the Moteino RFM radio), and when the switch is closed the signal goes HIGH and triggers the interrupt which wakes the Moteino and transmits the package, much like the MotionMote works. That's assuming there is a reed switch that can do that. I like the hall sensors since they are so small and work with very small magnets where they can hover over the magnet position every time.
Title: Re: magnetic switch on int
Post by: TomWS on November 20, 2014, 08:34:41 PM
Depending on how fast you need to know when a door is open, sleeping is a good way to save power.  You can use pinChangeInt to wake up your device with low power integrated pullup. If nothings going on, go to sleep after you've armed pinChangeInt and then, on wakeup, check the status, and report using the RFM69 radio.  I'd use something lower voltage than 9V battery, but even this should last months if its coded right.

For this case, I'd consider CR20xx battery.  3V so you'd have to run at 8Mhz, but not shouldn't be a problem for this use case.

Tom

Title: Re: magnetic switch on int
Post by: gianmarko on November 21, 2014, 03:41:20 AM
i am using switches like this
http://p.globalsources.com/IMAGES/PDT/B1070078691/Magnetic-Switch.jpg

so when the door is closed, the magnet is close to the switch and switch is closed. i have connected the switch between ground and D3, and i bring power to the D3 with a 10k resistor. when the door opens the switch also opens and D3 goes to 1, moteino wakes up and sends a packet.

it works, but i suspect the design is extremely dumb and the 10k resistor is depleting the batery  :o

i am sure there are much better ways of doing this. unfortunately spare time to experiment  is very scarce nowadays
Title: Re: magnetic switch on int
Post by: Felix on November 21, 2014, 09:24:47 AM
3.3v / 10,000ohm = 0.00033mA or 330uA. Not very ideal but not bad at all.
Are you sleeping the Moteino? Are you sleeping the radio?
Title: Re: magnetic switch on int
Post by: gianmarko on November 21, 2014, 04:33:53 PM
yes, im basically using a modified version of the motion sensor code, so everything should be at sleep till D3 goes up.

will recheck a few things,  perhaps this will work even with a 56k pull-up resistor, that should decrease current even more

and will give a try to hall sensors.

thanks for the help, will keep you posted on progress

i have also another project ongoing, will open another thread when i have more material available


Quote from: Felix on November 21, 2014, 09:24:47 AM
3.3v / 10,000ohm = 0.00033mA or 330uA. Not very ideal but not bad at all.
Are you sleeping the Moteino? Are you sleeping the radio?
Title: Re: magnetic switch on int
Post by: gianmarko on November 23, 2014, 05:45:04 AM
installed a 100k resistor, current went down a lot, 40 mcroamps
still a lot more than a sleeping moteino, but will be ok for the mo, while i source some hall sensors to experiment

thanks for the support



Title: Re: magnetic switch on int
Post by: bgreene on November 24, 2014, 04:39:55 AM
Since you only want notification when the door opens/closes, you could probably increase battery life 100fold by using a mosfet, 1meg resistor, a diode and a small capacitor. Use the mosfet to switch the power line for the moteino, connect the gate to +ive with the 1mohm in series with the diode and to 0v with the capacitor. Connect the reed switch between 0v and the resistor/diode junction. Now power is only consumed when the switch is open. When the door/reed opens, the mosfet turns on, the moteino turns on and sends a blip and then goes to sleep. When the door closes, the mosfet stays on until the capacitor has discharged so moteino has enough time to sense the closure and send a closed signal. You might not even need the capacitor as the intrinsic gate capacitance might keep the mosfet turned on long enough. You'd need to play around with it on a breadboard. Just a suggestion
Title: Re: magnetic switch on int
Post by: gianmarko on November 24, 2014, 10:10:25 AM
thanks bgreene, i will look into that also.

just to clarify things, the purpose of these switches is to send an alarm if a door opens. several doors in the house have a moteino on them.

it doesnt matter what happens next. actually, due to some bouncing of the reed switches or something else i dont understand, the moteino sends a signal when the door opens (D3 goes UP) and also when it closes (D3 goes DOWN) and as the D3 is looking for a raising state, dont know why the int is triggered. but it doesnt matter

the purpose of these switches is to send a signal if a door is opened. received is on my bedside. a beeper will go off and a display will show where the alarm was triggered and at what time. the last 4 alarms are shown on display. so i can even follow eventual intruders as they open/close doors or trigger motion sensors.

i am not very worried if robbers enter the house when im not at home, as i am insured. but lately is becoming more common in this area (that was VERY safe until recently) that robbers enter the house when you are in.

in this case, as i have wife and childred, pretending to be asleep might not be the best option.

in italy, just a few miles south, they enter your house, kidnap wife and children, and send you to the bank to get money. in the meanwhile, if wife and/or children are pretty, they have fun with them

sometimes, to show their dissatisfaction if you dont come back with enough money, they will rape/maim/kill family members.  and eventually maim/rape/kill you.

my house is old, with old doors and locks, and i dont like iron bars  and live like in a prison.

my alarm works very well, no false alarms at all, moteino range is amazingly good, transmission very reliable, once the battery life is solved, these things are amazingly good. thanks again to Felix for the fantastic work. 

i am also installing a gsm900 board to send a text message if some alarm is triggered.

battery backup also is going to be implemented.
Title: Re: magnetic switch on int
Post by: Felix on November 24, 2014, 10:34:30 AM
The reed switched might bounce on open/close and trigger a short pulse which will trigger the int.
You could do a software debouncing sequence. Once the Moteino wakes up, wait for a second or so, you can even sleep during that period. Upon wakeup you check if the reed is still open then send the message. Same for when the door closes.
Title: Re: magnetic switch on int
Post by: bgreene on November 24, 2014, 11:20:08 AM
>> i am also installing a gsm900 board to send a text message if some alarm is triggered.
It seems the bad guys in Ireland are more sophisticated than their mafia counterparts  :( . Here the "better class" baddies use gsm blockers before hitting a house. So my gsm is located a fair distance from the house. Might be something for you to consider!
Title: Re: magnetic switch on int
Post by: gianmarko on November 25, 2014, 03:50:23 AM
aha good to know. not sure they use gsm jammers here, however the gsm module will work only when im not at home. if that happens, i have a good insurance.



Quote from: bgreene on November 24, 2014, 11:20:08 AM
>> i am also installing a gsm900 board to send a text message if some alarm is triggered.
It seems the bad guys in Ireland are more sophisticated than their mafia counterparts  :( . Here the "better class" baddies use gsm blockers before hitting a house. So my gsm is located a fair distance from the house. Might be something for you to consider!
Title: Re: magnetic switch on int
Post by: ieris on November 27, 2014, 03:58:55 AM
Quote from: Felix on November 24, 2014, 10:34:30 AM
The reed switched might bounce on open/close and trigger a short pulse which will trigger the int.
You could do a software debouncing sequence. Once the Moteino wakes up, wait for a second or so, you can even sleep during that period. Upon wakeup you check if the reed is still open then send the message. Same for when the door closes.
I have played with this in my project also - have a gas counter, but after playing decided to implemented a hardware debouncing.