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
-
Temperature Sensor Configuration
General Discussion • 22 Jan 2015, 00:08 • rdevine 22 Jan 2015, 15:30 -
💬 MDMSNode "Power"
OpenHardware.io • 22 Mar 2017, 20:15 • openhardware.io 5 Oct 2017, 16:07 -
💬 The Logger Machine - Short and long term serial logging
OpenHardware.io • 24 Nov 2017, 21:01 • openhardware.io 18 Dec 2018, 08:58 -
All in one board with apple phone charger brick wrap.
Hardware • 13 Jan 2015, 16:58 • destos 18 Apr 2015, 14:53 -
💬 MDMSNode "Lighting"
OpenHardware.io • 7 Sept 2016, 19:43 • openhardware.io 30 Mar 2019, 11:22 -
💬 MDMSNode "Lighting X3" (based on ESP8266)
OpenHardware.io • 4 Jun 2020, 12:20 • openhardware.io 20 Jul 2020, 16:03 -
Problem with connecting several temperature sensors
Troubleshooting • 23 Dec 2014, 13:31 • Mouridsen 28 Dec 2014, 20:51