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. Development
  3. implementing multiple sensors

implementing multiple sensors

Scheduled Pinned Locked Moved Development
83 Posts 28 Posters 86.9k Views 15 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.
  • BulldogLowellB Offline
    BulldogLowellB Offline
    BulldogLowell
    Contest Winner
    wrote on last edited by BulldogLowell
    #18

    What would be interesting is to make the multi-sensor sketch so that if we ran it either powered or on battery it would adjust its behaviour accordingly. Something like the AEON 4-in-1.

    When you are on battery, it is all about conserving that power source, and while on mains, it is all about consistency of data updates and possibly adding other functionality.

    Plus, I wanted to work on that LED idea so that we can broadcast a 'message' to a grouping of sensors and activate an (RGB) LED in the sensor.

    Too much?

    marceltrapmanM 1 Reply Last reply
    0
    • BulldogLowellB BulldogLowell

      What would be interesting is to make the multi-sensor sketch so that if we ran it either powered or on battery it would adjust its behaviour accordingly. Something like the AEON 4-in-1.

      When you are on battery, it is all about conserving that power source, and while on mains, it is all about consistency of data updates and possibly adding other functionality.

      Plus, I wanted to work on that LED idea so that we can broadcast a 'message' to a grouping of sensors and activate an (RGB) LED in the sensor.

      Too much?

      marceltrapmanM Offline
      marceltrapmanM Offline
      marceltrapman
      Mod
      wrote on last edited by
      #19

      @BulldogLowell Good idea. Dunno if it is possible to recognise if it is battery powered or not.
      But this is the way to go imho.
      I think it is not a question of 'too much' but more 'is this even possible'?

      Fulltime Servoy Developer
      Parttime Moderator MySensors board

      I use Domoticz as controller for Z-Wave and MySensors (previously Indigo and OpenHAB).
      I have a FABtotum to print cases.

      1 Reply Last reply
      0
      • hekH hek

        A common multi-sensors-combination is:

        Motion + Light (LDR or Photo resistor) + DHT (Temp+Humidity)

        I would prefer if the example sleeps Arduino+radio while doing nothing.

        E Offline
        E Offline
        egbertje
        wrote on last edited by egbertje
        #20

        @hek said:

        A common multi-sensors-combination is:

        Motion + Light (LDR or Photo resistor) + DHT (Temp+Humidity)

        I would prefer if the example sleeps Arduino+radio while doing nothing.

        +1 for me !

        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #21

          You could probably have a #define or flag telling if sensor should be running on battery.

          1 Reply Last reply
          1
          • clippermiamiC Offline
            clippermiamiC Offline
            clippermiami
            Hero Member
            wrote on last edited by
            #22

            I merged the Temp/Humidity and Light sensor functions into already included sensor on Vera. Apparently the Gateway will not recognize such a change made inline. The Serial Monitor showed the Light value being reported but it was never displayed on Vera. I tried running the Inclusion function but it never showed the Light sensor in the Node.

            Knowing the way Vera works, this doesn't really surprise me all that much. I'm guessing that in order to make this work one has to ClearEEPROM on the Sensor, remove the Node from Vera, upload the revised sketch to the Sensor and go through the Inclusion again, essentially starting from scratch.

            clippermiamiC 1 Reply Last reply
            0
            • clippermiamiC clippermiami

              I merged the Temp/Humidity and Light sensor functions into already included sensor on Vera. Apparently the Gateway will not recognize such a change made inline. The Serial Monitor showed the Light value being reported but it was never displayed on Vera. I tried running the Inclusion function but it never showed the Light sensor in the Node.

              Knowing the way Vera works, this doesn't really surprise me all that much. I'm guessing that in order to make this work one has to ClearEEPROM on the Sensor, remove the Node from Vera, upload the revised sketch to the Sensor and go through the Inclusion again, essentially starting from scratch.

              clippermiamiC Offline
              clippermiamiC Offline
              clippermiami
              Hero Member
              wrote on last edited by clippermiami
              #23

              @clippermiami

              Re: This posting about merging sensors.

              I did exactly as I said in there:

              1. Removed the Node and Children from Vera. At this point I have only the MySensors Plugin visible in Vera
              2. Cleared EEPROM on the Sensor
              3. Uploaded the new sketch to the Sensor
              4. Ran Inclusion on Vera

              When inclusion ran it found 4 new devices (I assume Node, Temp, Hum, Light)

              But Vera does NOT display the new devices even after multiple restarts. The Serial Monitor on the Sensor shows that it is indeed sending data and receiving ACK OK from the Gateway. Subsequent attempts at Inclusion do not find any devices so the GW at least knows they are there.

              Looking at the SysLog there is no sensor data being reported since I started this so apparently it isn't getting through.

              I'm going to Clear EEPROM again and fallback to the Temp/Hum sensor in case there is a problem with the new sensor code.

              Well, that's interesting. After reverting to he 2 sensor node Inclusion found 3 new devices and Vera now displays them. Yet when the 3 sensor code was running the serial monitor showed transmission and ACK for all three sensors. Now I'm confused.

              [UPDATE]
              I sorted it out, i had several problems.

              1. It appears the it is necessary to RESET the Node prior to Inclusion. Vera will then find the devices and display them. Absent the Reset it looks like Vera found them but that was all.
              2. When it finally displayed the LIGHT, it was showing as an ON/OFF Switch not a level. In the Setup routine i had
                gw.sendSensorPresentation(CHILD_ID_LIGHT, S_LIGHT);
                rather than
                gw.sendSensorPresentation(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                and similarly in the sending of the data I had left off the "_LEVEL" not realizing that that told the GW how to display the device. Now I know :)

              Anyway, the three input sensor is working. In the process of making the conversion I changed the Light Level to a floating number for consistency on the display .I've also implemented a simple Keepalive; every "N" times through the loop it resends the last temperature reading. i have this set to 30 times (and I adjusted the basic data cycle from 30 seconds to 60 seconds) so the keep alive occurs every 30 minutes whether the sensor sends any data in that time or not.

              1 Reply Last reply
              1
              • E Offline
                E Offline
                egbertje
                wrote on last edited by
                #24

                Somebody has good result in a working multisensor and wants to share his code?

                NuubiN 1 Reply Last reply
                0
                • liningerL Offline
                  liningerL Offline
                  lininger
                  wrote on last edited by
                  #25

                  I have been working on one that combines a servo, temperature and light sensor. I have had it running for a while now. I have been busy lately and have not really had time to write it up and post it. I am attaching what I have, maybe it would help or give some ideas.
                  [Servo-Light-Temp-Sensors.zip](uploading 100%)

                  liningerL 1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wannabee
                    wrote on last edited by wannabee
                    #26

                    Probably not the easiest to look at since it combined a RGB diode and RFID reader. But it works very well.
                    https://github.com/wbcode/ham/blob/master/arduino/MySensorRFIDandRGB/RGBandRFID/RGBandRFID.ino

                    I should add that I don't use the Vera as a controler.

                    WB

                    1 Reply Last reply
                    0
                    • liningerL lininger

                      I have been working on one that combines a servo, temperature and light sensor. I have had it running for a while now. I have been busy lately and have not really had time to write it up and post it. I am attaching what I have, maybe it would help or give some ideas.
                      [Servo-Light-Temp-Sensors.zip](uploading 100%)

                      liningerL Offline
                      liningerL Offline
                      lininger
                      wrote on last edited by
                      #27

                      .zip did not take here are the files

                      Servo-Light-Temp-Sensors.ino Servo-Temp-Light-Sensors.jpg vera-blinds.jpg

                      1 Reply Last reply
                      2
                      • greglG Offline
                        greglG Offline
                        gregl
                        Hero Member
                        wrote on last edited by
                        #28

                        If i was a programmer... i would write a wizard app/script/webpage that would ask a user a bunch of questions..

                        1. What Arduino are they using.
                        2. what sensors/actuators they want to have on their sketch
                        3. what pins ( showing those available) are they going to connect the sensor to.
                        4. What they want to call the sketch
                        5. Relay mode?
                        6. Sampling times

                        etc etc

                        if i was a really good programmer, i would produce a schematic/frizing like above ;-)

                        Unfortunately in not a programmer..really wish i was, and am trying to get there slowly...so if you guys are cool with waiting another 5 years ill get something together...

                        1 Reply Last reply
                        0
                        • hekH Offline
                          hekH Offline
                          hek
                          Admin
                          wrote on last edited by
                          #29

                          We've actually thought about doing a sketch-generator also. It's down there on the list. And it would be a web-thing (hopefully with OTA update) :)

                          greglG 1 Reply Last reply
                          0
                          • hekH hek

                            We've actually thought about doing a sketch-generator also. It's down there on the list. And it would be a web-thing (hopefully with OTA update) :)

                            greglG Offline
                            greglG Offline
                            gregl
                            Hero Member
                            wrote on last edited by
                            #30

                            @hek Phew... cause you are a great programmer!!!

                            OTA!!.... now your showing off ;-)

                            1 Reply Last reply
                            0
                            • liningerL Offline
                              liningerL Offline
                              lininger
                              wrote on last edited by
                              #31

                              A few people have asked about the hardware I used.

                              A quick write up on what hardware I used for the blinds-light-temp-servo project.

                              My binds are 1” not the 2” that you see in the projects listed in the forums. The standard servos will not fit inside the 1” blinds, so I had to use the mini servos. My concern was that the mini servos would not have the torque necessary to operate the tilt mechanism. But for at least the 45x38 blinds I have the mini servo worked great, not sure about larger size blinds.

                              I removed the tilt wand and mechanism completely and connected the servo directly to the hex rod. I used a piece of 2” foam insulation and cut out a cavity for the servo and used it as the mounting bracket.

                              I purchased a Nano IO shield from imall.iteadstudio.com, which I plan to use when I assemble the parts into a final enclosure and mount it inside the cabinet. With the Light and Temp sensors mounted inside the window frame.

                              I use PLEG to control the blinds.

                              Parts used:

                              http://www.ebay.com/itm/291084936296?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649 – used to connect the servo to the hex rod. Note I had to cut off some of the hex rod so the servo would sit inside the head rail.

                              http://www.ebay.com/itm/SG90-Tower-Pro-mini-servo-Universal-S-type-connector-4-0-to-6-0-volts-/261184708931?pt=Model_Kit_US&hash=item3ccfd26143

                              I tried to upload a 5 second video of the binds in operation, but the file is too large.
                              Servo-Connection.jpg Test Wiring.jpg

                              1 Reply Last reply
                              0
                              • hekH Offline
                                hekH Offline
                                hek
                                Admin
                                wrote on last edited by
                                #32

                                Cool! Just upload the video to youtube and post the link here (it will be embedded automatically).

                                1 Reply Last reply
                                0
                                • liningerL Offline
                                  liningerL Offline
                                  lininger
                                  wrote on last edited by
                                  #33

                                  Two short videos

                                  1. During development
                                  2. In production

                                  http://tinypic.com/r/2dcfn9w/8
                                  http://tinypic.com/r/w05r21/8

                                  1 Reply Last reply
                                  0
                                  • HoffanH Offline
                                    HoffanH Offline
                                    Hoffan
                                    wrote on last edited by
                                    #34

                                    Can anyone see if i have missed something here in the code, It was working great before i copy/past the DHT sensor to the code; ande after that
                                    it will not really work anymore, Its 4 Binary Buttons, 1 relay And 1 DHT sensor Combo

                                            #include <Relay.h>
                                            #include <Sensor.h>
                                            #include <SPI.h>
                                            #include <EEPROM.h>  
                                            #include <RF24.h>
                                            #include <Bounce2.h>
                                            #include <DHT.h>  
                                            
                                            #define RELAY_1  7  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                                            #define NUMBER_OF_RELAYS 2 
                                            #define RELAY_ON 0
                                            #define RELAY_OFF 1
                                            
                                            #define BUTTON_PIN1  3  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN2  4  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN3  5  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN4  6  // Arduino Digital I/O pin for button/reed switch
                                            
                                            #define CHILD_ID_HUM 0
                                            #define CHILD_ID_TEMP 1
                                            #define HUMIDITY_SENSOR_DIGITAL_PIN 8
                                            
                                            Sensor gw;
                                            Bounce debouncer1 = Bounce();
                                            Bounce debouncer2 = Bounce();
                                            Bounce debouncer3 = Bounce();
                                            Bounce debouncer4 = Bounce();
                                            
                                            int oldValue1=-1;
                                            int oldValue2=-1;
                                            int oldValue3=-1;
                                            int oldValue4=-1;
                                            
                                            DHT dht;
                                            float lastTemp;
                                            float lastHum;
                                            boolean metric = true; 
                                            
                                            
                                            void setup()  
                                            {  
                                              gw.begin();
                                            
                                              pinMode(BUTTON_PIN1,INPUT);
                                              digitalWrite(BUTTON_PIN1,HIGH);
                                              pinMode(BUTTON_PIN2,INPUT);
                                              digitalWrite(BUTTON_PIN2,HIGH);
                                              pinMode(BUTTON_PIN3,INPUT);
                                              digitalWrite(BUTTON_PIN3,HIGH);
                                              pinMode(BUTTON_PIN4,INPUT);
                                              digitalWrite(BUTTON_PIN4,HIGH);
                                              
                                              dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                              
                                              
                                              // After setting up the button, setup debouncer
                                              debouncer1.attach(BUTTON_PIN1);
                                              debouncer1.interval(5);
                                              debouncer2.attach(BUTTON_PIN2);
                                              debouncer2.interval(5);
                                              debouncer3.attach(BUTTON_PIN3);
                                              debouncer3.interval(5);
                                              debouncer4.attach(BUTTON_PIN4);
                                              debouncer4.interval(5);
                                            
                                            
                                            
                                              
                                              // Register binary input sensor to gw (they will be created as child devices)
                                              // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
                                              // If S_LIGHT is used, remember to update variable type you send in below.
                                              gw.sendSensorPresentation(BUTTON_PIN1, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN2, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN3, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN4, S_DOOR);  
                                              
                                            
                                              // Send the sketch version information to the gateway and Controller
                                              gw.sendSketchInfo("4Door2Relay", "1.0");
                                              
                                               // Register all sensors to gw (they will be created as child devices)
                                              gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
                                              gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
                                              
                                              metric = gw.isMetricSystem();
                                            
                                              // Register all sensors to gw (they will be created as child devices)
                                              for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                                gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
                                              }
                                              // Fetch relay status
                                              for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                                // Make sure relays are off when starting up
                                                digitalWrite(RELAY_1+i, RELAY_OFF);
                                                // Then set relay pins in output mode
                                                pinMode(RELAY_1+i, OUTPUT);   
                                                  
                                                // Request/wait for relay status
                                                gw.getStatus(RELAY_1+i, V_LIGHT);
                                                setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
                                              }
                                              
                                            }
                                            
                                            
                                            /*
                                            *  Example on how to asynchronously check for new messages from gw
                                            */
                                            void loop() 
                                            {
                                               debouncer1.update();
                                               debouncer2.update();
                                               debouncer3.update();
                                               debouncer4.update();
                                            
                                            
                                            
                                              // Get the update value
                                              int value = debouncer1.read();
                                              if (value != oldValue1) {
                                                 // Send in the new value
                                                 gw.sendVariable(BUTTON_PIN1, V_TRIPPED, value==HIGH ? "1" : "0");  // Change to V_LIGHT if you use S_LIGHT in presentation above
                                                 oldValue1 = value;
                                                }
                                                
                                            value = debouncer2.read();
                                            
                                            if (value != oldValue2) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN2, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue2 = value;
                                            }
                                            
                                            value = debouncer3.read();
                                            
                                            if (value != oldValue3) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN3, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue3 = value;
                                            } 
                                             value = debouncer4.read();
                                            
                                            if (value != oldValue4) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN4, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue4 = value;
                                            } 
                                            
                                             delay(dht.getMinimumSamplingPeriod());
                                            
                                              float temperature = dht.getTemperature();
                                              if (isnan(temperature)) {
                                                  Serial.println("Failed reading temperature from DHT");
                                              } else if (temperature != lastTemp) {
                                                lastTemp = temperature;
                                                if (!metric) {
                                                  temperature = dht.toFahrenheit(temperature);
                                                }
                                                gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
                                                  Serial.print("T: ");
                                                  Serial.println(temperature);
                                              }
                                              
                                              float humidity = dht.getHumidity();
                                              if (isnan(humidity)) {
                                                  Serial.println("Failed reading humidity from DHT");
                                              } else if (humidity != lastHum) {
                                                  lastHum = humidity;
                                                  gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
                                                  Serial.print("H: ");
                                                  Serial.println(humidity);
                                              }
                                            
                                            
                                              if (gw.messageAvailable()) {
                                                message_s message = gw.getMessage(); 
                                                setRelayStatus(message);
                                              }
                                            }
                                            
                                            void setRelayStatus(message_s message) {
                                              if (message.header.messageType==M_SET_VARIABLE &&
                                                  message.header.type==V_LIGHT) {
                                                 int incomingRelayStatus = atoi(message.data);
                                                 // Change relay state
                                                 digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
                                                 // Write some debug info
                                                 Serial.print("Incoming change for relay on pin:");
                                                 Serial.print(message.header.childId);
                                                 Serial.print(", New status: ");
                                                 Serial.println(incomingRelayStatus);
                                               }
                                            }
                                    
                                    1 Reply Last reply
                                    0
                                    • BulldogLowellB Offline
                                      BulldogLowellB Offline
                                      BulldogLowell
                                      Contest Winner
                                      wrote on last edited by
                                      #35

                                      @Hoffan said:

                                      #include <Relay.h>
                                      #include <Sensor.h>
                                      #include <SPI.h>
                                      #include <EEPROM.h>
                                      #include <RF24.h>
                                      #include <Bounce2.h>
                                      #include <DHT.h>

                                          #define RELAY_1  7  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                                          #define NUMBER_OF_RELAYS 2 
                                          #define RELAY_ON 0
                                          #define RELAY_OFF 1
                                      
                                          #define BUTTON_PIN1  3  // Arduino Digital I/O pin for button/reed switch
                                          #define BUTTON_PIN2  4  // Arduino Digital I/O pin for button/reed switch
                                          #define BUTTON_PIN3  5  // Arduino Digital I/O pin for button/reed switch
                                          #define BUTTON_PIN4  6  // Arduino Digital I/O pin for button/reed switch
                                      
                                          #define CHILD_ID_HUM 0
                                          #define CHILD_ID_TEMP 1
                                          #define HUMIDITY_SENSOR_DIGITAL_PIN 8
                                      
                                          Sensor gw;
                                          Bounce debouncer1 = Bounce();
                                          Bounce debouncer2 = Bounce();
                                          Bounce debouncer3 = Bounce();
                                          Bounce debouncer4 = Bounce();
                                      
                                          int oldValue1=-1;
                                          int oldValue2=-1;
                                          int oldValue3=-1;
                                          int oldValue4=-1;
                                      
                                          DHT dht;
                                          float lastTemp;
                                          float lastHum;
                                          boolean metric = true; 
                                      
                                      
                                          void setup()  
                                          {  
                                            gw.begin();
                                      
                                            pinMode(BUTTON_PIN1,INPUT);
                                            digitalWrite(BUTTON_PIN1,HIGH);
                                            pinMode(BUTTON_PIN2,INPUT);
                                            digitalWrite(BUTTON_PIN2,HIGH);
                                            pinMode(BUTTON_PIN3,INPUT);
                                            digitalWrite(BUTTON_PIN3,HIGH);
                                            pinMode(BUTTON_PIN4,INPUT);
                                            digitalWrite(BUTTON_PIN4,HIGH);
                                      
                                            dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                      
                                      
                                            // After setting up the button, setup debouncer
                                            debouncer1.attach(BUTTON_PIN1);
                                            debouncer1.interval(5);
                                            debouncer2.attach(BUTTON_PIN2);
                                            debouncer2.interval(5);
                                            debouncer3.attach(BUTTON_PIN3);
                                            debouncer3.interval(5);
                                            debouncer4.attach(BUTTON_PIN4);
                                            debouncer4.interval(5);
                                      
                                      
                                      
                                      
                                            // Register binary input sensor to gw (they will be created as child devices)
                                            // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
                                            // If S_LIGHT is used, remember to update variable type you send in below.
                                            gw.sendSensorPresentation(BUTTON_PIN1, S_DOOR);  
                                            gw.sendSensorPresentation(BUTTON_PIN2, S_DOOR);  
                                            gw.sendSensorPresentation(BUTTON_PIN3, S_DOOR);  
                                            gw.sendSensorPresentation(BUTTON_PIN4, S_DOOR);  
                                      
                                      
                                            // Send the sketch version information to the gateway and Controller
                                            gw.sendSketchInfo("4Door2Relay", "1.0");
                                      
                                             // Register all sensors to gw (they will be created as child devices)
                                            gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
                                            gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
                                      
                                            metric = gw.isMetricSystem();
                                      
                                            // Register all sensors to gw (they will be created as child devices)
                                            for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                              gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
                                            }
                                            // Fetch relay status
                                            for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                              // Make sure relays are off when starting up
                                              digitalWrite(RELAY_1+i, RELAY_OFF);
                                              // Then set relay pins in output mode
                                              pinMode(RELAY_1+i, OUTPUT);   
                                      
                                              // Request/wait for relay status
                                              gw.getStatus(RELAY_1+i, V_LIGHT);
                                              setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
                                            }
                                      
                                          }
                                      
                                      
                                          /*
                                          *  Example on how to asynchronously check for new messages from gw
                                          */
                                          void loop() 
                                          {
                                             debouncer1.update();
                                             debouncer2.update();
                                             debouncer3.update();
                                             debouncer4.update();
                                      
                                      
                                      
                                            // Get the update value
                                            int value = debouncer1.read();
                                            if (value != oldValue1) {
                                               // Send in the new value
                                               gw.sendVariable(BUTTON_PIN1, V_TRIPPED, value==HIGH ? "1" : "0");  // Change to V_LIGHT if you use S_LIGHT in presentation above
                                               oldValue1 = value;
                                              }
                                      
                                          value = debouncer2.read();
                                      
                                          if (value != oldValue2) {
                                          // Send in the new value
                                          gw.sendVariable(BUTTON_PIN2, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                          oldValue2 = value;
                                          }
                                      
                                          value = debouncer3.read();
                                      
                                          if (value != oldValue3) {
                                          // Send in the new value
                                          gw.sendVariable(BUTTON_PIN3, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                          oldValue3 = value;
                                          } 
                                           value = debouncer4.read();
                                      
                                          if (value != oldValue4) {
                                          // Send in the new value
                                          gw.sendVariable(BUTTON_PIN4, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                          oldValue4 = value;
                                          } 
                                      
                                           delay(dht.getMinimumSamplingPeriod());
                                      
                                            float temperature = dht.getTemperature();
                                            if (isnan(temperature)) {
                                                Serial.println("Failed reading temperature from DHT");
                                            } else if (temperature != lastTemp) {
                                              lastTemp = temperature;
                                              if (!metric) {
                                                temperature = dht.toFahrenheit(temperature);
                                              }
                                              gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
                                                Serial.print("T: ");
                                                Serial.println(temperature);
                                            }
                                      
                                            float humidity = dht.getHumidity();
                                            if (isnan(humidity)) {
                                                Serial.println("Failed reading humidity from DHT");
                                            } else if (humidity != lastHum) {
                                                lastHum = humidity;
                                                gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
                                                Serial.print("H: ");
                                                Serial.println(humidity);
                                            }
                                      
                                      
                                            if (gw.messageAvailable()) {
                                              message_s message = gw.getMessage(); 
                                              setRelayStatus(message);
                                            }
                                          }
                                      
                                          void setRelayStatus(message_s message) {
                                            if (message.header.messageType==M_SET_VARIABLE &&
                                                message.header.type==V_LIGHT) {
                                               int incomingRelayStatus = atoi(message.data);
                                               // Change relay state
                                               digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
                                               // Write some debug info
                                               Serial.print("Incoming change for relay on pin:");
                                               Serial.print(message.header.childId);
                                               Serial.print(", New status: ");
                                               Serial.println(incomingRelayStatus);
                                             }
                                          }
                                      

                                      can you elaborate on "doesn't work" ?

                                      do you have sensors on the Vera UI?

                                      Try to debug putting Serial.print(Something) in places so you can see how the sketch progresses...

                                      HoffanH 1 Reply Last reply
                                      0
                                      • BulldogLowellB BulldogLowell

                                        @Hoffan said:

                                        #include <Relay.h>
                                        #include <Sensor.h>
                                        #include <SPI.h>
                                        #include <EEPROM.h>
                                        #include <RF24.h>
                                        #include <Bounce2.h>
                                        #include <DHT.h>

                                            #define RELAY_1  7  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                                            #define NUMBER_OF_RELAYS 2 
                                            #define RELAY_ON 0
                                            #define RELAY_OFF 1
                                        
                                            #define BUTTON_PIN1  3  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN2  4  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN3  5  // Arduino Digital I/O pin for button/reed switch
                                            #define BUTTON_PIN4  6  // Arduino Digital I/O pin for button/reed switch
                                        
                                            #define CHILD_ID_HUM 0
                                            #define CHILD_ID_TEMP 1
                                            #define HUMIDITY_SENSOR_DIGITAL_PIN 8
                                        
                                            Sensor gw;
                                            Bounce debouncer1 = Bounce();
                                            Bounce debouncer2 = Bounce();
                                            Bounce debouncer3 = Bounce();
                                            Bounce debouncer4 = Bounce();
                                        
                                            int oldValue1=-1;
                                            int oldValue2=-1;
                                            int oldValue3=-1;
                                            int oldValue4=-1;
                                        
                                            DHT dht;
                                            float lastTemp;
                                            float lastHum;
                                            boolean metric = true; 
                                        
                                        
                                            void setup()  
                                            {  
                                              gw.begin();
                                        
                                              pinMode(BUTTON_PIN1,INPUT);
                                              digitalWrite(BUTTON_PIN1,HIGH);
                                              pinMode(BUTTON_PIN2,INPUT);
                                              digitalWrite(BUTTON_PIN2,HIGH);
                                              pinMode(BUTTON_PIN3,INPUT);
                                              digitalWrite(BUTTON_PIN3,HIGH);
                                              pinMode(BUTTON_PIN4,INPUT);
                                              digitalWrite(BUTTON_PIN4,HIGH);
                                        
                                              dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                        
                                        
                                              // After setting up the button, setup debouncer
                                              debouncer1.attach(BUTTON_PIN1);
                                              debouncer1.interval(5);
                                              debouncer2.attach(BUTTON_PIN2);
                                              debouncer2.interval(5);
                                              debouncer3.attach(BUTTON_PIN3);
                                              debouncer3.interval(5);
                                              debouncer4.attach(BUTTON_PIN4);
                                              debouncer4.interval(5);
                                        
                                        
                                        
                                        
                                              // Register binary input sensor to gw (they will be created as child devices)
                                              // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
                                              // If S_LIGHT is used, remember to update variable type you send in below.
                                              gw.sendSensorPresentation(BUTTON_PIN1, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN2, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN3, S_DOOR);  
                                              gw.sendSensorPresentation(BUTTON_PIN4, S_DOOR);  
                                        
                                        
                                              // Send the sketch version information to the gateway and Controller
                                              gw.sendSketchInfo("4Door2Relay", "1.0");
                                        
                                               // Register all sensors to gw (they will be created as child devices)
                                              gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
                                              gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
                                        
                                              metric = gw.isMetricSystem();
                                        
                                              // Register all sensors to gw (they will be created as child devices)
                                              for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                                gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
                                              }
                                              // Fetch relay status
                                              for (int i=0; i<NUMBER_OF_RELAYS;i++) {
                                                // Make sure relays are off when starting up
                                                digitalWrite(RELAY_1+i, RELAY_OFF);
                                                // Then set relay pins in output mode
                                                pinMode(RELAY_1+i, OUTPUT);   
                                        
                                                // Request/wait for relay status
                                                gw.getStatus(RELAY_1+i, V_LIGHT);
                                                setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
                                              }
                                        
                                            }
                                        
                                        
                                            /*
                                            *  Example on how to asynchronously check for new messages from gw
                                            */
                                            void loop() 
                                            {
                                               debouncer1.update();
                                               debouncer2.update();
                                               debouncer3.update();
                                               debouncer4.update();
                                        
                                        
                                        
                                              // Get the update value
                                              int value = debouncer1.read();
                                              if (value != oldValue1) {
                                                 // Send in the new value
                                                 gw.sendVariable(BUTTON_PIN1, V_TRIPPED, value==HIGH ? "1" : "0");  // Change to V_LIGHT if you use S_LIGHT in presentation above
                                                 oldValue1 = value;
                                                }
                                        
                                            value = debouncer2.read();
                                        
                                            if (value != oldValue2) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN2, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue2 = value;
                                            }
                                        
                                            value = debouncer3.read();
                                        
                                            if (value != oldValue3) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN3, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue3 = value;
                                            } 
                                             value = debouncer4.read();
                                        
                                            if (value != oldValue4) {
                                            // Send in the new value
                                            gw.sendVariable(BUTTON_PIN4, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
                                            oldValue4 = value;
                                            } 
                                        
                                             delay(dht.getMinimumSamplingPeriod());
                                        
                                              float temperature = dht.getTemperature();
                                              if (isnan(temperature)) {
                                                  Serial.println("Failed reading temperature from DHT");
                                              } else if (temperature != lastTemp) {
                                                lastTemp = temperature;
                                                if (!metric) {
                                                  temperature = dht.toFahrenheit(temperature);
                                                }
                                                gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
                                                  Serial.print("T: ");
                                                  Serial.println(temperature);
                                              }
                                        
                                              float humidity = dht.getHumidity();
                                              if (isnan(humidity)) {
                                                  Serial.println("Failed reading humidity from DHT");
                                              } else if (humidity != lastHum) {
                                                  lastHum = humidity;
                                                  gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
                                                  Serial.print("H: ");
                                                  Serial.println(humidity);
                                              }
                                        
                                        
                                              if (gw.messageAvailable()) {
                                                message_s message = gw.getMessage(); 
                                                setRelayStatus(message);
                                              }
                                            }
                                        
                                            void setRelayStatus(message_s message) {
                                              if (message.header.messageType==M_SET_VARIABLE &&
                                                  message.header.type==V_LIGHT) {
                                                 int incomingRelayStatus = atoi(message.data);
                                                 // Change relay state
                                                 digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
                                                 // Write some debug info
                                                 Serial.print("Incoming change for relay on pin:");
                                                 Serial.print(message.header.childId);
                                                 Serial.print(", New status: ");
                                                 Serial.println(incomingRelayStatus);
                                               }
                                            }
                                        

                                        can you elaborate on "doesn't work" ?

                                        do you have sensors on the Vera UI?

                                        Try to debug putting Serial.print(Something) in places so you can see how the sketch progresses...

                                        HoffanH Offline
                                        HoffanH Offline
                                        Hoffan
                                        wrote on last edited by
                                        #36

                                        @BulldogLowell

                                        Yes all the sensors came up in the Vera UI, And looks like they work for some minutes
                                        But when i push å button its looks like all things stop working, and after a reboot on the Arduino its working again for a short time and so on

                                        BulldogLowellB 2 Replies Last reply
                                        0
                                        • HoffanH Hoffan

                                          @BulldogLowell

                                          Yes all the sensors came up in the Vera UI, And looks like they work for some minutes
                                          But when i push å button its looks like all things stop working, and after a reboot on the Arduino its working again for a short time and so on

                                          BulldogLowellB Offline
                                          BulldogLowellB Offline
                                          BulldogLowell
                                          Contest Winner
                                          wrote on last edited by BulldogLowell
                                          #37
                                          This post is deleted!
                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          7

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