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