While working for the automation side of my new house, I'm currently in the process of installing several reed switches on top of external doors and windows.
Even if this could be used as a "security" infrastructure, I'm more interested, at the moment, at the "automation" side (checking the status of door and windows without the need to physically watch them) and as such, I'm going to extend the arduino-based infrastructure I've already planned and prototyped [more details here].
This is the reed-switch I've installed (1€ coin added for size reference):
and this is the related circuits:
As you can see, it comes with two circuits: one related to the "switch" funcionality; another one as a safety-measure to catch some "cuts" along the wires.
To check its status, currently, I've configured:
"contact circuit":
- one end to an Arduino GROUND_PIN;
- the other end to Digital PIN 52 (REED1_SW_Pin);
"tamper circuit":
- one end to an Arduino GROUND_PIN (same GND pin as above);
- the other end to Digital PIN 50 (REED1_AT_Pin);
Arduino setup:
pinMode(REED1_SW_Pin, INPUT_PULLUP)
pinMode(REED1_AT_Pin, INPUT_PULLUP)
Arduino code:
- the main code-block handling REED events is reported below
Even tough everything is working fine, I wonder if there are better approaches, expecially inchecking the status of door and windows without the need to physically watch them terms of POWER-CONSUMPTION. So, here are my questions:
- TAMPER-Circuit: due to its nature, it will always be a "closed" circuit, with current flowing inside, from REED1_AT_Pin to GND. Currently I'm checking its state every 1 second (
#define REED_AT_CHECKDELAY 1000
) but a frequency of once every 5 seconds, or even 10 seconds would be acceptable (for me). So I would like to have the current flowing ONLY during the "checking-timeframe". Something like:- every 5 seconds...
- power-up something, getting the current flowing along the circuit;
- check if the current flows;
- if yes => OK
- if no => set/keep the ALARM state
- power-down the "something"
Is it feasible? If yes, how? Also: is it worth the effort?
REED-switch circuit: same as above. Polling approach is still acceptable (for me) but frequency need to be relatively high (5 seconds max), in order to keep of sort of "near-real-time feedback" when opening/closing windows. Best would be 2 secs polling-interval. With such a timing, does the polling-approach make sense?
from an "electronic" point of view, what is the "to-be-preferred-scenario" for the Arduino board:
- having a small, fixed, steady current, flowing out from a PIN, for YEARS on a 24/7/365 basis or...
- having a continuosly transition from LOW->HIGH->LOW for a Digital PIN, say once every 5 seconds, again, for YEARS?
Every comment, sidenotes, hints, critics, whatever... is REALLY welcomed/appreciated.
Arduino code-block handling REED events
BTW: the full-code, where the REED switch is handled togheter with pushbuttons and relays, it's available on GitHub
[...] if (reed_sw1_state != reed_sw1_previous_state) { // a change occurred. Are we in a "boucing" window? if (millis() - last_reed_sw1_debounce > REED_DEBOUNCE) { // no. So it's a real change // Let's handle the event... Serial.print(millis()); Serial.print("[REED] - SW1 state CHANGED from ["); Serial.print(reed_sw1_previous_state); Serial.print("] to ["); Serial.print(reed_sw1_state); Serial.println("]"); reed_sw1_previous_state = reed_sw1_state; last_reed_sw1_debounce = millis(); } else { // yes. Let's ignore it } } // Let's check REED Switches anti-tamper state if (millis()-reed_at1_lastcheck > REED_AT_CHECKDELAY) { reed_at1_state = ! digitalRead(REED1_AT_Pin); if (reed_at1_state == HIGH ) { Serial.print(millis()); Serial.print("[REED] - AT1 state OK ["); Serial.print(reed_at1_state); Serial.println("]"); } else { Serial.print(millis()); Serial.print("[REED] - AT1 state ALARM - OnGoing TAMPER!!! ["); Serial.print(reed_at1_state); Serial.println("]"); } reed_at1_lastcheck = millis(); } [...]