Skip to content
  • 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. Two motion sensors on one Arduino. How?
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Two motion sensors on one Arduino. How?

Scheduled Pinned Locked Moved Hardware
8 Posts 4 Posters 2.6k Views 2 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.
  • edsteveE Offline
    edsteveE Offline
    edsteve
    wrote on last edited by
    #1

    Hey,

    pin 2 and 3 can get interrupt on Arduino. Pin 2 is used for radio already. So only one pin left.
    I am so much of a noob that i can't tell if there is a solution for that problem?
    Anybody knows how to get two motion sensors running on one Arduino?

    That would safe me money, time and space :)

    Thx
    ED

    sundberg84S 1 Reply Last reply
    0
    • scalzS Offline
      scalzS Offline
      scalz
      Hardware Contributor
      wrote on last edited by scalz
      #2

      Hi.

      Yes you can use multiple interrupts. two ways:

      • http://www.gammon.com.au/forum/?id=11091 . So you can use multiple input on one of your interrupt pin (INT0 or INT1)
      • I'm using this one to save diodes footprint on one of my board : http://gammon.com.au/forum/?id=11488&reply=6#reply6
        But it's less easy in sketch if you're noob
      1 Reply Last reply
      1
      • edsteveE Offline
        edsteveE Offline
        edsteve
        wrote on last edited by
        #3

        Thanks for your answer. Great that it is possible even-though it will take some time for me as a noob.
        But as usual: every problem has a solution. Just have to find (ask for) it :dancer:

        1 Reply Last reply
        1
        • edsteveE edsteve

          Hey,

          pin 2 and 3 can get interrupt on Arduino. Pin 2 is used for radio already. So only one pin left.
          I am so much of a noob that i can't tell if there is a solution for that problem?
          Anybody knows how to get two motion sensors running on one Arduino?

          That would safe me money, time and space :)

          Thx
          ED

          sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by
          #4

          @edsteve - Pin2 isnt used by the nrf24l01 what I know. (Atleast not prior to 2.0) You can use this pin as well for interrupt.

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          1 Reply Last reply
          0
          • tbowmoT Offline
            tbowmoT Offline
            tbowmo
            Admin
            wrote on last edited by
            #5

            @sundberg84

            We have some changes coming up, that needs the interrupt from NRF, used for queuing of packets. But the feature can be disabled, so you can use PIN2 as interrupt for other purposes. At least as it is now.

            1 Reply Last reply
            0
            • edsteveE Offline
              edsteveE Offline
              edsteve
              wrote on last edited by
              #6

              Cool. There is even a noob solution. For now :)

              1 Reply Last reply
              0
              • edsteveE Offline
                edsteveE Offline
                edsteve
                wrote on last edited by
                #7

                Huff. I am too nooobish in programming :(
                Can anyone tell me how to change the example code to get a second motion sensor on pin2 working with Domoticz?

                Here the example:

                // 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);
                }
                
                
                edsteveE 1 Reply Last reply
                0
                • edsteveE edsteve

                  Huff. I am too nooobish in programming :(
                  Can anyone tell me how to change the example code to get a second motion sensor on pin2 working with Domoticz?

                  Here the example:

                  // 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);
                  }
                  
                  
                  edsteveE Offline
                  edsteveE Offline
                  edsteve
                  wrote on last edited by
                  #8

                  Nobody? :disappointed:

                  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
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular