Two motion sensors on one Arduino. How?



  • 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


  • Hardware Contributor

    Hi.

    Yes you can use multiple interrupts. two ways:



  • 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 πŸ’ƒ


  • Hardware Contributor

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


  • Admin

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



  • Cool. There is even a noob solution. For now πŸ™‚



  • 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);
    }
    
    


  • Nobody? 😞


Log in to reply
 

Suggested Topics

  • 87
  • 2
  • 6
  • 7
  • 7
  • 8

1
Online

11.4k
Users

11.1k
Topics

112.7k
Posts