Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Motion and lux meters combined in a single device

Motion and lux meters combined in a single device

Scheduled Pinned Locked Moved Hardware
23 Posts 9 Posters 14.6k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ferpandoF Offline
    ferpandoF Offline
    ferpando
    Hero Member
    wrote on last edited by
    #4

    Thank you @hek and @blacey
    It works pretty well.
    It updates light level every 30 seconds and also when movement is detected.
    Also the dome helps average the light level of the room making it more consistent.

    1 Reply Last reply
    0
    • rvendrameR Offline
      rvendrameR Offline
      rvendrame
      Hero Member
      wrote on last edited by
      #5

      @ferpando, do you run this sensor on battery? Any idea about for how long the battery will last?

      Home Assistant / Vera Plus UI7
      ESP8266 GW + mySensors 2.3.2
      Alexa / Google Home

      1 Reply Last reply
      0
      • ferpandoF Offline
        ferpandoF Offline
        ferpando
        Hero Member
        wrote on last edited by
        #6

        @rvendrame
        Not at the moment. It is designed to be on a wall socket.
        If you plan to use it on battery, probably would be a good idea to by pass both voltage regulators on the devices and run on 3.3V.
        Also consider increasing the time between light reads.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mikemayers
          wrote on last edited by mikemayers
          #7

          @ferpando

          very nice setup. What pins are the Lux sensor wired to the Arduino? In the sketch, only pin A0 is defined but on wiring diagram A4 & A5 is used.

          ferpandoF 1 Reply Last reply
          0
          • M mikemayers

            @ferpando

            very nice setup. What pins are the Lux sensor wired to the Arduino? In the sketch, only pin A0 is defined but on wiring diagram A4 & A5 is used.

            ferpandoF Offline
            ferpandoF Offline
            ferpando
            Hero Member
            wrote on last edited by
            #8

            @mikemayers
            You need to connect the arduino to pins 4 and 5 for the digital BH1750.
            I don't know why the sketch references pin 0. Must be something left behind from the analog version.

            M 1 Reply Last reply
            0
            • ferpandoF ferpando

              @mikemayers
              You need to connect the arduino to pins 4 and 5 for the digital BH1750.
              I don't know why the sketch references pin 0. Must be something left behind from the analog version.

              M Offline
              M Offline
              mikemayers
              wrote on last edited by
              #9

              @ferpando got it!

              1 Reply Last reply
              0
              • F Offline
                F Offline
                floris
                wrote on last edited by
                #10

                Thanks! just what i was looking for!
                Floris

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mikemayers
                  wrote on last edited by
                  #11

                  is it posible to add an LED indicator to tells there's motion. If so what has to be done?

                  AWIA 1 Reply Last reply
                  0
                  • M mikemayers

                    is it posible to add an LED indicator to tells there's motion. If so what has to be done?

                    AWIA Offline
                    AWIA Offline
                    AWI
                    Hero Member
                    wrote on last edited by
                    #12

                    @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..

                    M 1 Reply Last reply
                    0
                    • AWIA AWI

                      @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..

                      M Offline
                      M Offline
                      mikemayers
                      wrote on last edited by
                      #13

                      @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?

                      AWIA 1 Reply Last reply
                      0
                      • M mikemayers

                        @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?

                        AWIA Offline
                        AWIA Offline
                        AWI
                        Hero Member
                        wrote on last edited by
                        #14

                        @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   
                        }
                        
                        jeylitesJ 1 Reply Last reply
                        0
                        • AWIA AWI

                          @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   
                          }
                          
                          jeylitesJ Offline
                          jeylitesJ Offline
                          jeylites
                          wrote on last edited by
                          #15

                          @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);
                                
                          
                            
                            }
                            
                             }
                          
                          M 1 Reply Last reply
                          0
                          • jeylitesJ jeylites

                            @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);
                                  
                            
                              
                              }
                              
                               }
                            
                            M Offline
                            M Offline
                            mikemayers
                            wrote on last edited by mikemayers
                            #16

                            @jeylites

                            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!

                            jeylitesJ AWIA 2 Replies Last reply
                            0
                            • M mikemayers

                              @jeylites

                              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!

                              jeylitesJ Offline
                              jeylitesJ Offline
                              jeylites
                              wrote on last edited by
                              #17

                              @mikemayers

                              I get what you're saying and I've no clue on how to do that. :(

                              1 Reply Last reply
                              0
                              • M mikemayers

                                @jeylites

                                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!

                                AWIA Offline
                                AWIA Offline
                                AWI
                                Hero Member
                                wrote on last edited by
                                #18

                                @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.

                                M 1 Reply Last reply
                                0
                                • AWIA AWI

                                  @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.

                                  M Offline
                                  M Offline
                                  mikemayers
                                  wrote on last edited by
                                  #19

                                  @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.

                                  AWIA 1 Reply Last reply
                                  0
                                  • M mikemayers

                                    @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.

                                    AWIA Offline
                                    AWIA Offline
                                    AWI
                                    Hero Member
                                    wrote on last edited by
                                    #20

                                    @mikemayers can you post your sketch?

                                    M 1 Reply Last reply
                                    0
                                    • AWIA AWI

                                      @mikemayers can you post your sketch?

                                      M Offline
                                      M Offline
                                      mikemayers
                                      wrote on last edited by mikemayers
                                      #21

                                      @AWI
                                      @jeylites

                                      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); 
                                        
                                        
                                        }
                                        
                                         }
                                      
                                      1 Reply Last reply
                                      0
                                      • korttomaK Offline
                                        korttomaK Offline
                                        korttoma
                                        Hero Member
                                        wrote on last edited by korttoma
                                        #22

                                        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);   
                                        
                                        }
                                        
                                        • Tomas
                                        1 Reply Last reply
                                        0
                                        • jeylitesJ Offline
                                          jeylitesJ Offline
                                          jeylites
                                          wrote on last edited by jeylites
                                          #23

                                          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); 
                                            
                                            
                                                }
                                           }
                                          
                                          
                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          16

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular