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. Announcements
  3. 💬 Motion Sensor

💬 Motion Sensor

Scheduled Pinned Locked Moved Announcements
63 Posts 30 Posters 19.7k Views 31 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.
  • xliborX Offline
    xliborX Offline
    xlibor
    wrote on last edited by xlibor
    #6

    Blue - parts to be removed
    Red - wire or tin short circuit
    0_1476112640045_IMG_20161010_120006.jpg

    1 Reply Last reply
    1
    • Fat FlyF Offline
      Fat FlyF Offline
      Fat Fly
      wrote on last edited by
      #7

      Thank you. I try.

      1 Reply Last reply
      0
      • jentiJ Offline
        jentiJ Offline
        jenti
        wrote on last edited by
        #8

        Is it possible to break both interrupt pins on a board? cus with or without a pir, the serial monitor keeps getting spammed.

        1 Reply Last reply
        0
        • Mercury69M Offline
          Mercury69M Offline
          Mercury69
          wrote on last edited by
          #9

          Hi to everyone,
          it's possible to connect more than one PIR Sensor to the same board ?
          In case if it's possible, there's a limit on that number ?

          Thank you for your help

          YveauxY 1 Reply Last reply
          0
          • Mercury69M Mercury69

            Hi to everyone,
            it's possible to connect more than one PIR Sensor to the same board ?
            In case if it's possible, there's a limit on that number ?

            Thank you for your help

            YveauxY Offline
            YveauxY Offline
            Yveaux
            Mod
            wrote on last edited by
            #10

            @Mercury69 do you want to know which pir fired, or just combine them all?

            http://yveaux.blogspot.nl

            1 Reply Last reply
            0
            • Mercury69M Offline
              Mercury69M Offline
              Mercury69
              wrote on last edited by
              #11

              @Yveaux
              Hi Yveaux, I want to know if it's possible to connect more than one PIR sensor at the same node and if there's a limit on the number.

              I mean the possibility to have only 1 node with connected more PIR sensor in order to avoid the moltiplication of the assembly composed by arduino+radio+PIR+power supply.

              I imagine (but I'm not sure) if I connect more PIR sensor to the same PIN3 on arduino node I will obtain a "network" of PIR Sensor reacting as a single element to a possible presence, without the possibility to differentiate the area interested by the alarm.

              If I can differentiate the PIN where I can connect the PIR sensor, maybe I can get information from each single area of detection controlled by the PIR sensor.

              Thank you for your attention.

              xliborX 1 Reply Last reply
              0
              • Mercury69M Mercury69

                @Yveaux
                Hi Yveaux, I want to know if it's possible to connect more than one PIR sensor at the same node and if there's a limit on the number.

                I mean the possibility to have only 1 node with connected more PIR sensor in order to avoid the moltiplication of the assembly composed by arduino+radio+PIR+power supply.

                I imagine (but I'm not sure) if I connect more PIR sensor to the same PIN3 on arduino node I will obtain a "network" of PIR Sensor reacting as a single element to a possible presence, without the possibility to differentiate the area interested by the alarm.

                If I can differentiate the PIN where I can connect the PIR sensor, maybe I can get information from each single area of detection controlled by the PIR sensor.

                Thank you for your attention.

                xliborX Offline
                xliborX Offline
                xlibor
                wrote on last edited by xlibor
                #12

                @Mercury69 PIR is based on interrupts, which wake-up processor from sleep mode, Arduinos based on ATMEGA328 have only two these pins, pin 2 and 3.

                You can use 2 PIRs with detection which was fired, if you need more than two PIRs you can connect each PIR to any digital input of arduino and common signal OR-ing from all PIRs to generate interrupt to pin 2 or 3. Then if you wake-up by interrupt you can software test all of digital inputs and resolve which PIR was fired.

                YveauxY 1 Reply Last reply
                0
                • xliborX xlibor

                  @Mercury69 PIR is based on interrupts, which wake-up processor from sleep mode, Arduinos based on ATMEGA328 have only two these pins, pin 2 and 3.

                  You can use 2 PIRs with detection which was fired, if you need more than two PIRs you can connect each PIR to any digital input of arduino and common signal OR-ing from all PIRs to generate interrupt to pin 2 or 3. Then if you wake-up by interrupt you can software test all of digital inputs and resolve which PIR was fired.

                  YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by Yveaux
                  #13

                  @xlibor said:

                  ANDed

                  Better ORed, or all your sensors have to trigger at the same time to wake up the Arduino ;-)

                  For the rest @xlibor is right: OR-ing PIR triggers into a single wake-up signal can be as simple as using a diode per PIR and a resistor:

                  alt text

                  Ref: https://learn.sparkfun.com/tutorials/diodes/diode-applications

                  http://yveaux.blogspot.nl

                  1 Reply Last reply
                  3
                  • Patrik SöderströmP Offline
                    Patrik SöderströmP Offline
                    Patrik Söderström
                    wrote on last edited by
                    #14

                    Do you have an example sketch of connecting two PIRs to one Arduino? Would really need that in my setup.

                    Random_nut1R 1 Reply Last reply
                    0
                    • Patrik SöderströmP Patrik Söderström

                      Do you have an example sketch of connecting two PIRs to one Arduino? Would really need that in my setup.

                      Random_nut1R Offline
                      Random_nut1R Offline
                      Random_nut1
                      wrote on last edited by
                      #15

                      @Patrik-Söderström said:

                      Do you have an example sketch of connecting two PIRs to one Arduino? Would really need that in my setup.

                      And so do I. Have tried to accomplish this as my first mysensors project, but coming up short... :-(

                      1 Reply Last reply
                      0
                      • ben999B Offline
                        ben999B Offline
                        ben999
                        wrote on last edited by ben999
                        #16

                        Hi all

                        I have build a node with this setup.
                        It is an Arduino Pro Mini with a SR501 and a RFL01. Arduino and sensor converted to 3.3V.
                        Motion is detected like it should, no trouble.

                        But everytime my arduino hits this :

                           // Sleep until interrupt comes in on motion sensor. Send update every two minute.
                            sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                        

                        the node returns a "high"... meaning there's motion (where there is not actually)
                        So my notification board gets a new entry every two minutes...

                        Is this normal beahaviour ? (Hope not!!! ;) )

                        GrahamG 1 Reply Last reply
                        0
                        • bgunnarbB Offline
                          bgunnarbB Offline
                          bgunnarb
                          wrote on last edited by
                          #17

                          Hi ben999
                          I don't know what your sketch looks like but in my implementation I catch the movement in a boolean variable called tripped which I use to set the message sent to the controller.

                          // Read digital motion value
                          boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                          send(msgm.set(tripped?"1":"0"));  // Send tripped value to gw
                          

                          Then I do some other stuff based on tripped being true or false.
                          Before the node goes to sleep I reset tripped. Otherwise I will get the old value back next time the node wakes up after SLEEP_TIME regardless if there is movement or not.

                          // Sleep until interrupt comes in on motion sensor but send update every minute. 
                            tripped = false;  //reset tripped
                            sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                          

                          It goes without saying that SLEEP_TIME will have to be longer than the reset time of the sensor itself. My sensor element resets in about 20 seconds, which puts a lower limit to SLEEP_TIME.

                          I have never been so busy since I retired!

                          ben999B 1 Reply Last reply
                          0
                          • ben999B ben999

                            Hi all

                            I have build a node with this setup.
                            It is an Arduino Pro Mini with a SR501 and a RFL01. Arduino and sensor converted to 3.3V.
                            Motion is detected like it should, no trouble.

                            But everytime my arduino hits this :

                               // Sleep until interrupt comes in on motion sensor. Send update every two minute.
                                sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                            

                            the node returns a "high"... meaning there's motion (where there is not actually)
                            So my notification board gets a new entry every two minutes...

                            Is this normal beahaviour ? (Hope not!!! ;) )

                            GrahamG Offline
                            GrahamG Offline
                            Graham
                            wrote on last edited by
                            #18

                            So my notification board gets a new entry every two minutes...

                            The SLEEP_TIME define tells your board to wake up every two minutes regardless of whether there is an interrupt. If you want longer, increase this value. I think you can also set it to 0 to only wake on interrupts.

                            1 Reply Last reply
                            0
                            • bgunnarbB bgunnarb

                              Hi ben999
                              I don't know what your sketch looks like but in my implementation I catch the movement in a boolean variable called tripped which I use to set the message sent to the controller.

                              // Read digital motion value
                              boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                              send(msgm.set(tripped?"1":"0"));  // Send tripped value to gw
                              

                              Then I do some other stuff based on tripped being true or false.
                              Before the node goes to sleep I reset tripped. Otherwise I will get the old value back next time the node wakes up after SLEEP_TIME regardless if there is movement or not.

                              // Sleep until interrupt comes in on motion sensor but send update every minute. 
                                tripped = false;  //reset tripped
                                sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                              

                              It goes without saying that SLEEP_TIME will have to be longer than the reset time of the sensor itself. My sensor element resets in about 20 seconds, which puts a lower limit to SLEEP_TIME.

                              ben999B Offline
                              ben999B Offline
                              ben999
                              wrote on last edited by ben999
                              #19

                              @bgunnarb
                              Thank you very much for your message
                              I added tripped = false; to my sketch but that didn't change the general behaviour : sensor still give false trigger when coming out of sleep period...

                              @Graham
                              Thank you very much for your message as well

                              I might not have described my problem precisely enough :
                              Motion sensor will be used as part of an house alarm
                              I have set up a very simple rule for now (home.rules) stating that

                              when sensor changed from CLOSED to OPEN
                                 then sendBroadcastNotification(to me)
                              

                              This works fine and node comes out of sleep when motion triggers the interrupt. All fine.

                              Trouble is when we get to the end of the sleeptime... node comes out of sleep and i get a "tripped" that sends me a notification (or later on will set the siren on!!!)

                              @Graham 's idea is pretty good: keep node asleep forever until interrupt kicks in...
                              But nodes do have temperature, humidity and battery statuses to share...

                              I tried to load the basic sketch (ignoring temp, hum and batt) but node still behaves the same... :(

                              Does it not do the same at yours ?

                              #define MY_RADIO_NRF24
                              
                              #include <MySensors.h>
                              
                              unsigned long SLEEP_TIME = 120000; 
                              #define DIGITAL_INPUT_SENSOR 3
                              #define CHILD_ID 1
                              
                              MyMessage msg(CHILD_ID, V_TRIPPED);
                              
                              void setup()
                              {
                                  pinMode(DIGITAL_INPUT_SENSOR, INPUT); 
                              }
                              
                              void presentation()
                              {
                                  sendSketchInfo("Motion Sensor", "1.0");
                                  present(CHILD_ID, S_MOTION);
                              }
                              
                              void loop()
                              {
                                  bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
                                  send(msg.set(tripped?"1":"0")); 
                                  sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                              }
                              

                              Thanks a lot for your help

                              GrahamG 1 Reply Last reply
                              0
                              • ben999B ben999

                                @bgunnarb
                                Thank you very much for your message
                                I added tripped = false; to my sketch but that didn't change the general behaviour : sensor still give false trigger when coming out of sleep period...

                                @Graham
                                Thank you very much for your message as well

                                I might not have described my problem precisely enough :
                                Motion sensor will be used as part of an house alarm
                                I have set up a very simple rule for now (home.rules) stating that

                                when sensor changed from CLOSED to OPEN
                                   then sendBroadcastNotification(to me)
                                

                                This works fine and node comes out of sleep when motion triggers the interrupt. All fine.

                                Trouble is when we get to the end of the sleeptime... node comes out of sleep and i get a "tripped" that sends me a notification (or later on will set the siren on!!!)

                                @Graham 's idea is pretty good: keep node asleep forever until interrupt kicks in...
                                But nodes do have temperature, humidity and battery statuses to share...

                                I tried to load the basic sketch (ignoring temp, hum and batt) but node still behaves the same... :(

                                Does it not do the same at yours ?

                                #define MY_RADIO_NRF24
                                
                                #include <MySensors.h>
                                
                                unsigned long SLEEP_TIME = 120000; 
                                #define DIGITAL_INPUT_SENSOR 3
                                #define CHILD_ID 1
                                
                                MyMessage msg(CHILD_ID, V_TRIPPED);
                                
                                void setup()
                                {
                                    pinMode(DIGITAL_INPUT_SENSOR, INPUT); 
                                }
                                
                                void presentation()
                                {
                                    sendSketchInfo("Motion Sensor", "1.0");
                                    present(CHILD_ID, S_MOTION);
                                }
                                
                                void loop()
                                {
                                    bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
                                    send(msg.set(tripped?"1":"0")); 
                                    sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                                }
                                

                                Thanks a lot for your help

                                GrahamG Offline
                                GrahamG Offline
                                Graham
                                wrote on last edited by
                                #20

                                @ben999 The sketch you have will report the state of the pin every 2 minutes as well as when interrupted by motion.

                                If the SR501 is still within its timeout after the last motion detected, the pin will still be high. Eventually, (the maximum length of time is about 10 minutes) the pin should go low. If it doesn't, there is a fault with the SR501.

                                The timeout can be adjusted by one of the dials (see http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-sensor-tutorial/#Time_Delay_Adjustment). I'm not sure what the shortest period is, but it is probably less than two minutes, which would send 0 in the next message.

                                You would, however, get another interrupt if more motion occurred before the two minutes are up.

                                1 Reply Last reply
                                0
                                • ben999B Offline
                                  ben999B Offline
                                  ben999
                                  wrote on last edited by
                                  #21

                                  @Graham Thank you for your reply

                                  SR501 seem to work fine on two fronts:

                                  • the arduino IDE serial monitor shows the SR501 going ON then OFF after 5s (as per dial)
                                  • same serial monitor shows that sensor gets motion when it occurs...

                                  I'll have a go with another node just to be sure

                                  Thanks again for your help (both of you :) )

                                  EfflonE 1 Reply Last reply
                                  0
                                  • Cliff KarlssonC Offline
                                    Cliff KarlssonC Offline
                                    Cliff Karlsson
                                    wrote on last edited by
                                    #22

                                    If I wanted to add two PIRs to one sensor-node would this sketch work?

                                    /**
                                     * The MySensors Arduino library handles the wireless radio link and protocol
                                     * between your home built sensors/actuators and HA controller of choice.
                                     * The sensors forms a self healing radio network with optional repeaters. Each
                                     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                     * network topology allowing messages to be routed to nodes.
                                     *
                                     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                     * Copyright (C) 2013-2015 Sensnology AB
                                     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                     *
                                     * Documentation: http://www.mysensors.org
                                     * Support Forum: http://forum.mysensors.org
                                     *
                                     * This program is free software; you can redistribute it and/or
                                     * modify it under the terms of the GNU General Public License
                                     * version 2 as published by the Free Software Foundation.
                                     *
                                     *******************************
                                     *
                                     * REVISION HISTORY
                                     * Version 1.0 - Henrik Ekblad
                                     *
                                     * DESCRIPTION
                                     * Motion Sensor example using HC-SR501
                                     * http://www.mysensors.org/build/motion
                                     *
                                     */
                                    
                                    // Enable debug prints
                                    // #define MY_DEBUG
                                    
                                    // Enable and select radio type attached
                                    #define MY_RADIO_NRF24
                                    //#define MY_RADIO_RFM69
                                    
                                    #include <MySensors.h>
                                    
                                    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
                                    #define DIGITAL_INPUT_SENSOR_1 2
                                    #define DIGITAL_INPUT_SENSOR_2 3  // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                                    #define CHILD_ID_1 1   // Id of the sensor child
                                    #define CHILD_ID_2 2   // Id of the sensor child
                                    
                                    // Initialize motion message
                                    MyMessage msg(CHILD_ID_1, V_TRIPPED);
                                    
                                    
                                    void setup()
                                    {
                                        pinMode(DIGITAL_INPUT_SENSOR_1, INPUT);      // sets the motion sensor digital pin as input
                                        pinMode(DIGITAL_INPUT_SENSOR_2, INPUT);      // sets the motion sensor digital pin as input
                                    }
                                    
                                    void presentation()
                                    {
                                        // Send the sketch version information to the gateway and Controller
                                        sendSketchInfo("Motion Sensor_Dual", "1.0");
                                    
                                        // Register all sensors to gw (they will be created as child devices)
                                        present(CHILD_ID_1, S_MOTION);
                                        present(CHILD_ID_2, S_MOTION);
                                    }
                                    
                                    void loop()
                                    {
                                        // Read digital motion value
                                        bool tripped_1 = digitalRead(DIGITAL_INPUT_SENSOR_1) == HIGH;
                                        bool tripped_2 = digitalRead(DIGITAL_INPUT_SENSOR_2) == HIGH;
                                    
                                        Serial.println(tripped_1 || tripped_2);
                                        if(tripped_1){
                                        send(msg.set(tripped_1?"1":"0"));  // Send tripped value to gw
                                        }
                                        if(tripped_2){
                                        send(msg.set(tripped_2?"1":"0"));  // Send tripped value to gw
                                        }
                                        // Sleep until interrupt comes in on motion sensor. Send update every two minute.
                                        sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR_1 || DIGITAL_INPUT_SENSOR_1), CHANGE, SLEEP_TIME);
                                    }
                                    

                                    I know PIN 2 is supposed to be connected to the radio but I read somewhere that it is not used.

                                    sellierS 1 Reply Last reply
                                    0
                                    • ben999B ben999

                                      @Graham Thank you for your reply

                                      SR501 seem to work fine on two fronts:

                                      • the arduino IDE serial monitor shows the SR501 going ON then OFF after 5s (as per dial)
                                      • same serial monitor shows that sensor gets motion when it occurs...

                                      I'll have a go with another node just to be sure

                                      Thanks again for your help (both of you :) )

                                      EfflonE Offline
                                      EfflonE Offline
                                      Efflon
                                      wrote on last edited by
                                      #23

                                      @ben999 Did you get your sensor sorted? I have the same issue with the sensor reporting tripped after going out of sleep, same goes for wait. Putting the exact same logic in a sketch without MYS and I have no issues... going crazy soon

                                      1 Reply Last reply
                                      0
                                      • miroM Offline
                                        miroM Offline
                                        miro
                                        wrote on last edited by miro
                                        #24

                                        Does anyone know why my sensor only reacts when I move my hand just in front of it. From a distance it does not work. Has tested with different HC-SR501 PIR and adjusted also and various radio but all gave the same result.

                                        /**
                                         * The MySensors Arduino library handles the wireless radio link and protocol
                                         * between your home built sensors/actuators and HA controller of choice.
                                         * The sensors forms a self healing radio network with optional repeaters. Each
                                         * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                         * network topology allowing messages to be routed to nodes.
                                         *
                                         * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                         * Copyright (C) 2013-2015 Sensnology AB
                                         * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                         *
                                         * Documentation: http://www.mysensors.org
                                         * Support Forum: http://forum.mysensors.org
                                         *
                                         * This program is free software; you can redistribute it and/or
                                         * modify it under the terms of the GNU General Public License
                                         * version 2 as published by the Free Software Foundation.
                                         *
                                         *******************************
                                         *
                                         * REVISION HISTORY
                                         * Version 1.0 - Henrik Ekblad
                                         * 
                                         * DESCRIPTION
                                         * Motion Sensor example using HC-SR501 
                                         * http://www.mysensors.org/build/motion
                                         *
                                         */
                                        
                                        // Enable debug prints
                                        // #define MY_DEBUG
                                        
                                        // Enable and select radio type attached
                                        #define MY_RADIO_NRF24
                                        //#define MY_RADIO_RFM69
                                        
                                        #include <SPI.h>
                                        #include <MySensors.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 CHILD_ID 1   // Id of the sensor child
                                        
                                        // Initialize motion message
                                        MyMessage msg(CHILD_ID, V_TRIPPED);
                                        
                                        void setup()  
                                        {  
                                          pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                                        }
                                        
                                        void presentation()  {
                                          // Send the sketch version information to the gateway and Controller
                                          sendSketchInfo("Motion Sensor", "1.0");
                                        
                                          // Register all sensors to gw (they will be created as child devices)
                                          present(CHILD_ID, S_MOTION);
                                        }
                                        
                                        void loop()     
                                        {     
                                          // Read digital motion value
                                          boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                                                
                                          Serial.println(tripped);
                                          send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
                                        
                                          // Sleep until interrupt comes in on motion sensor. Send update every two minute.
                                          sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                                        }
                                        
                                        
                                        gohanG 1 Reply Last reply
                                        0
                                        • miroM miro

                                          Does anyone know why my sensor only reacts when I move my hand just in front of it. From a distance it does not work. Has tested with different HC-SR501 PIR and adjusted also and various radio but all gave the same result.

                                          /**
                                           * The MySensors Arduino library handles the wireless radio link and protocol
                                           * between your home built sensors/actuators and HA controller of choice.
                                           * The sensors forms a self healing radio network with optional repeaters. Each
                                           * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                           * network topology allowing messages to be routed to nodes.
                                           *
                                           * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                           * Copyright (C) 2013-2015 Sensnology AB
                                           * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                           *
                                           * Documentation: http://www.mysensors.org
                                           * Support Forum: http://forum.mysensors.org
                                           *
                                           * This program is free software; you can redistribute it and/or
                                           * modify it under the terms of the GNU General Public License
                                           * version 2 as published by the Free Software Foundation.
                                           *
                                           *******************************
                                           *
                                           * REVISION HISTORY
                                           * Version 1.0 - Henrik Ekblad
                                           * 
                                           * DESCRIPTION
                                           * Motion Sensor example using HC-SR501 
                                           * http://www.mysensors.org/build/motion
                                           *
                                           */
                                          
                                          // Enable debug prints
                                          // #define MY_DEBUG
                                          
                                          // Enable and select radio type attached
                                          #define MY_RADIO_NRF24
                                          //#define MY_RADIO_RFM69
                                          
                                          #include <SPI.h>
                                          #include <MySensors.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 CHILD_ID 1   // Id of the sensor child
                                          
                                          // Initialize motion message
                                          MyMessage msg(CHILD_ID, V_TRIPPED);
                                          
                                          void setup()  
                                          {  
                                            pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                                          }
                                          
                                          void presentation()  {
                                            // Send the sketch version information to the gateway and Controller
                                            sendSketchInfo("Motion Sensor", "1.0");
                                          
                                            // Register all sensors to gw (they will be created as child devices)
                                            present(CHILD_ID, S_MOTION);
                                          }
                                          
                                          void loop()     
                                          {     
                                            // Read digital motion value
                                            boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                                                  
                                            Serial.println(tripped);
                                            send(msg.set(tripped?"1":"0"));  // Send tripped value to gw 
                                          
                                            // Sleep until interrupt comes in on motion sensor. Send update every two minute.
                                            sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
                                          }
                                          
                                          
                                          gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #25

                                          @miro
                                          have you tried to power he sensor with external 5v instead of 5v pin from arduino?

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          21

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 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