Motion and lux meters combined in a single device
-
is it posible to add an LED indicator to tells there's motion. If so what has to be done?
@mikemayers You could either use the output from the motion sensor directly to operate the LED or write a few lines of code and use an Arduino pin for it. And a Led with resistor of course..
-
@mikemayers You could either use the output from the motion sensor directly to operate the LED or write a few lines of code and use an Arduino pin for it. And a Led with resistor of course..
@AWI said:
You could either use the output from the motion sensor directly to operate the LED
I didn't know you could do that. Should I include a resistor in series? For the Adruino pin, do you have a sample code?
-
@AWI said:
You could either use the output from the motion sensor directly to operate the LED
I didn't know you could do that. Should I include a resistor in series? For the Adruino pin, do you have a sample code?
@mikemayers Yes put a resistor in series with the LED (330 ohm will do). A piece of code can be as simple or complicated as you want. There are plenty of examples in Arduino tutorials. Just take care to take specific measures for power management if using battery power. You need to switch off the LED before you enter sleep mode (or be creative).
// in setup pinMode(LED_PIN,OUTPUT); // define output (LED_PIN = Arduino pin) // in loop (at the right place) if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW } -
@mikemayers Yes put a resistor in series with the LED (330 ohm will do). A piece of code can be as simple or complicated as you want. There are plenty of examples in Arduino tutorials. Just take care to take specific measures for power management if using battery power. You need to switch off the LED before you enter sleep mode (or be creative).
// in setup pinMode(LED_PIN,OUTPUT); // define output (LED_PIN = Arduino pin) // in loop (at the right place) if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW }@mikemayers this might work based on @AWI 's blink ... blink idea.
#include <MySensor.h> #include <SPI.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #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 31 // Id of the sensor child #define LED_PIN 5 MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(LED_PIN, OUTPUT); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // 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 // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(100); } } -
@mikemayers this might work based on @AWI 's blink ... blink idea.
#include <MySensor.h> #include <SPI.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #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 31 // Id of the sensor child #define LED_PIN 5 MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(LED_PIN, OUTPUT); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // 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 // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(100); } }Thank you!
It seems to be working I think..... Question: When motion is triggered there is no activity on the LED, but when the motion is turned OFF the LED blinks once. Is it suppose to do that? I was wondering if could it be the other way, blink LED when there's motion and OFF LED when there's no motion. Can that be done? What do I have to change to have it do that? Thanks again guys! -
Thank you!
It seems to be working I think..... Question: When motion is triggered there is no activity on the LED, but when the motion is turned OFF the LED blinks once. Is it suppose to do that? I was wondering if could it be the other way, blink LED when there's motion and OFF LED when there's no motion. Can that be done? What do I have to change to have it do that? Thanks again guys!I get what you're saying and I've no clue on how to do that. :(
-
Thank you!
It seems to be working I think..... Question: When motion is triggered there is no activity on the LED, but when the motion is turned OFF the LED blinks once. Is it suppose to do that? I was wondering if could it be the other way, blink LED when there's motion and OFF LED when there's no motion. Can that be done? What do I have to change to have it do that? Thanks again guys!@mikemayers put the gw.sleep(... line at the end of the loop. Everytime motion is detected or released there is an interrupt. At this time the loop starts again and you should check the status and blink the led if on or change.
-
@mikemayers put the gw.sleep(... line at the end of the loop. Everytime motion is detected or released there is an interrupt. At this time the loop starts again and you should check the status and blink the led if on or change.
@AWI I did as you say on gw and it did turn on the LED when motion is triggered, but the motion remained ON even after the set duration. I think, it's creating a continues loop.
-
@AWI I did as you say on gw and it did turn on the LED when motion is triggered, but the motion remained ON even after the set duration. I think, it's creating a continues loop.
@mikemayers can you post your sketch?
-
@mikemayers can you post your sketch?
This is what I have done....moved "gw.sleep" to the end.
#include <MySensor.h> #include <SPI.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #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 31 // Id of the sensor child #define LED_PIN 5 MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(LED_PIN, OUTPUT); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // 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 if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(100); // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); } } -
Try moving the gw.sleep outside your if statement like this:
if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(100); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); } -
With the help from @korttoma & @AWI , I put together this sketch. I've tested it and it works. Have fun!
#include <MySensor.h> #include <SPI.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #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 #define LED_PIN 5 MySensor gw; // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Motion Sensor", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(LED_PIN, OUTPUT); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_MOTION); } void loop() { // 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 { if (tripped){ // from the "Blink" example sketch :-) digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(1000); } // Sleep until interrupt comes in on motion sensor. Send update every two minute. gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME); } }