Interrupt driven contact sensor
-
I've modified the sketch I use for temperature/humidity/barometer to remove the barometer and implement a magnetic door sensor. My plan is for this to be installed in/on my gun safe to monitor interior temperature and humidity and log whenever the safe is opened/closed.
Basically the contact sensor works but of course its loop-driven so it doesn't report when the door is actually opened/closed. It also reports every OTHER reporting cycle for some reason.
I have the sensor wired to Arduino Pin D3. Can someone guide me in making the contact sensor interrupt driven to report immediately?
Thanks
John
-
In your sketch you may just be sleeping on a timer. Ie:
gw.sleep(SLEEP_TIME);
With the 1.4 beta improvements, there's now provision to sleep on timer AND on interrupt. Like this:
#define DIGITAL_INPUT_SENSOR 3 // D3 is the only interrupt pin left (radio uses D2) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 unsigned long SLEEP_TIME = 30000; void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the digital pin as input } void loop() { ... gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); }
That may not all be exactly right, but it should be pretty close.
-
@Bandra Looks fairly simple, maybe its time to upgrade to 1.4
Suggested Topics
-
Welcome
Announcements • 23 Mar 2014, 08:24 • hek 2 Apr 2014, 14:39 -
Long time test done with soil sensor!
My Project • 7 Jan 2025, 09:13 • Nicklas Starkel 13 Jan 2025, 09:10 -
Nb of possible nodes in a mysensors networks with domoticz
My Project • 13 Jan 2025, 18:10 • GLAB 16 Feb 2025, 01:11 -
Wio-E5 (STM32 and SX1262)
My Project • 31 Dec 2024, 17:52 • nagelc 25 Jan 2025, 20:21 -
Interface-board-for-remote-control
My Project • 6 days ago • OldSurferDude 6 days ago -
BMP280 SPI Adafruit
My Project • 24 Aug 2016, 01:56 • Matt 23 Jan 2025, 16:25