Custom Interrupt routine for door sensor
-
Dear guys, i'm approaching a problem similar to the one presented in this topic: http://forum.mysensors.org/topic/271/interrupt-driven-contact-sensor/2
I have a node with a DHT11 and a magnetic reed switch to control a door movement. My node sleeps for a determined time interval with the gw.sleep method. And iìd like to wake it up when the timer runs out or when an interrupt is received ( easy to do) . My problem is that i want to perform a specific action when the interrupt is received. Something like : Node Sleeping ---> pin Interrupt ---> Custom action performed ---> other routine in the loop ----> sleep again.
In particular when the door is opened or closed, i'd like to start a routine that reads the door interrupt pin and reports its status.
Using instead the defined gw.sleep(IntPin,TypeOfInt,SleepTime) command
with CHANGE i could catch the door movement but i cannot know the status of the door. Using RISING or FALLING i can get only one of the 2 moves ( open or close) , and with LOW, when door is closed, my node stucks.My ideal routine should be something like : interrupt received -->wake up node ---> read interrupt pin ---> send to gateway the value that has been read and blink a led--> put the node back to sleep.
Can someone help me? i'm attaching the sketch i wrote that's not working well ( freezes). In this sketch the led blinking is missing ( but that's secondary)
DoorAndTempAndHumIntVer2.ino
-
this is how the BinarySwitchSleepSensor example works, I believe that's what you want from your description...
note it uses CHANGE mode for the interrupt...
-
Damn, didn't have that sketch in my folder, maybe i had an old release. Just found it in the latest release. Gonna try it soon and test if does the job that i need to be done. Thank you for your advice
-
I built a trip wire for the post box that I'm connecting. It's however based on a mercury tilt sensor so I'm really not sure whether I think it's a great idea putting it to use (at least not with a sturdy case...). However, I can share my code:
#define DIGITAL_INPUT_SENSOR 2 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)MyMessage msgTripped(CHILD_ID_TRIPPED, V_TRIPPED);
void setup()
{
gw.sendSketchInfo("Postal", "1.0");
gw.present(CHILD_ID_TRIPPED, S_MOTION);pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
}void loop()
{
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == LOW;if(tripped) {
gw.send(msgTripped.set("1")); // Send tripped value to gw
}gw.sleep(INTERRUPT,FALLING, SLEEP_TIME);
}
Suggested Topics
-
Ethernet Gateway on Arduino Yún
Development • 15 Sept 2015, 14:13 • akbooer 11 Jan 2016, 21:03 -
How to read frequency and SWP output from watermark sensor
Development • 25 May 2018, 20:48 • pierrot10 6 Feb 2019, 07:18 -
Homini Complete Room Sensor Module?
Hardware • 20 Mar 2016, 08:15 • Samuel235 18 Oct 2017, 08:24 -
Simple Temp/Light/Time setup with LCD 1.4 (no beta anymore)
My Project • 13 Aug 2014, 12:00 • John 31 Aug 2014, 21:47 -
PIR motion sensor that sends cloud notifications via wifi
Development • 25 Nov 2014, 07:52 • vekraman76 25 Nov 2014, 09:27 -
💬 NodeManager
OpenHardware.io • 23 Mar 2017, 22:45 • openhardware.io 26 May 2019, 18:10 -
💬 Anna2040 RP2040 Uno-shaped board
OpenHardware.io • 25 Nov 2022, 18:24 • openhardware.io 25 Nov 2022, 18:24