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


        12

        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