multiple door sensors, one arduino
-
Hello every one
I would like to first thank every one for their help. I have got a lot of sensors up and running and its all working well.
What I am trying to do is have 3 door sensors running from the one arduino as they will all be in the same room, the garage. I realise that this is probably some thing but how would I go about changing the code to make this happen?
I appreciate any help.
thanks
-
Look at the http://www.mysensors.org/build/temp code. It handles multiple temp sensors but you will get the point.
-
you can try like this:
#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #define NUMBER_OF_SWITCHES 3 MySensor gw; Bounce debouncer[NUMBER_OF_SWITCHES]; int oldValue[NUMBER_OF_SWITCHES]; byte switchPin[NUMBER_OF_SWITCHES] = {4,5,6}; //<<<<<<<<<<< set your switch pins here MyMessage msg(0,V_TRIPPED); void setup() { gw.begin(); for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { pinMode(switchPin[i],INPUT_PULLUP); debouncer[i] = Bounce(); debouncer[i].attach(switchPin[i]); debouncer[i].interval(5); } for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { gw.present(i, S_DOOR); delay(250); } } // void loop() { for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { debouncer[i].update(); int value = debouncer[i].read(); if (value != oldValue[i]) { gw.send(msg.setSensor(i).set(value == HIGH? true : false), false); } oldValue[i] = value; } }
not tested, but compiles....
-
The sketch is working!
Suggested Topics
-
Welcome
Announcements • • hek