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?
-
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 }
-
@Dwalt That was what i needed. It works now
1 out of 4
Suggested Topics
-
Day 1 - Status report
Announcements ā¢ 23 Mar 2014, 22:45 ā¢ hek 24 Mar 2014, 20:12 -
Can not compile MySensors on esp8266
Troubleshooting ā¢ 24 Aug 2024, 15:35 ā¢ TheoL 29 Aug 2024, 20:47 -
Raspberry Pi 5: invalid GPIO 9
Troubleshooting ā¢ 27 Aug 2024, 13:20 ā¢ igo 27 Aug 2024, 13:20 -
Some sensors permanently fail after one/two years
Troubleshooting ā¢ 25 Jul 2024, 17:17 ā¢ Kokosnoot 25 Jul 2024, 17:17 -
Forum Search not working?
Troubleshooting ā¢ 4 Oct 2023, 23:33 ā¢ Gibber 2 Sept 2024, 20:28