Repeater and motion
-
The sketch works only it is sending the motion every second. I only want the sensor to send if there is motion. Who can help me with the code?
#include <MySensor.h> #include <SPI.h> #define DIGITAL_INPUT_SENSOR 3 // 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) #define CHILD_ID 1 // Id of the sensor child MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { // The third argument enables repeater mode. gw.begin(NULL, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor/Repeater", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // By calling process() you route messages in the background gw.process(); // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw } -
Is your sensor giving you a HIGH reading all the time?
-
The sketch works only it is sending the motion every second. I only want the sensor to send if there is motion. Who can help me with the code?
#include <MySensor.h> #include <SPI.h> #define DIGITAL_INPUT_SENSOR 3 // 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) #define CHILD_ID 1 // Id of the sensor child MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { // The third argument enables repeater mode. gw.begin(NULL, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor/Repeater", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // By calling process() you route messages in the background gw.process(); // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw }Your sketch has the motion sensor sending its status every time through the loop, add a qualifier to only send when the status changes:
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; if (tripped != lastTrippedState) { Serial.println(tripped? "tripped" : "not tripped"); gw.send(msg.set(tripped?"1":"0"));// Send tripped value to gw// lastTrippedState = tripped }
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