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.
-
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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login