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.
  • andyunoA Offline
    andyunoA Offline
    andyuno
    wrote on last edited by
    #1

    Any help on implementing multiple sensors and readings on one Arduino would be appreciated.

    :) Any Help is Appreciated Thank You.

    H 1 Reply Last reply
    1
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #2

      You will probably have to give us some more information.

      What sensors do you want to combine?
      How far have you come combining the provided examples? Where did you stuck?

      1 Reply Last reply
      1
      • andyunoA Offline
        andyunoA Offline
        andyuno
        wrote on last edited by
        #3

        I know nothing of programming, I am comparing all the sensor sketch with each other and trying to work it out from there.
        My first one will be Motion sensor and four relay unit.

        :) Any Help is Appreciated Thank You.

        1 Reply Last reply
        0
        • andyunoA andyuno

          Any help on implementing multiple sensors and readings on one Arduino would be appreciated.

          H Offline
          H Offline
          henno
          wrote on last edited by
          #4

          @andyuno
          Im really no expert but I'll try to explain with a easy example. So for borked english.

          Say you want to combine a soil moisture sensor and a DHT22 temp sensor.
          Open both of the examples and look at the top part that are circled in red.
          include.jpg

          This is where all the librarys that are needed are listed. Simply copy/paste the ones that are needed, in my example all libraries are equal except for the one circled in blue. So make sure you get all needed libraries!
          The next step is to look at the define part, circled in green. Here you copy/paste so you get all the needed parts and you must also change the pin number where your sensor is connected on the Arduino bord. So if you soldered your soil sensor on digital pin 5, change the number from 3 to 5 in #define DIGITAL_INPUT_SOIL_SENSOR 3.
          The child ID may also needed to be changed so that there isn't a conflict.

          Keep copy/paste all the way down in the sketch. Make sure that you place the code in the right place.If its inside the void setup() in one code, paste it inside the void setup() in the target code, I marked it green below. As you can see in the attached picture below in the red rectangle, Sensor gw; is in both codes so don't copy that. You only need to copy/paste the parts that are unique!

          setup.jpg

          Just keep trying! If I can do it, I'm sure you can too!

          1 Reply Last reply
          0
          • andyunoA Offline
            andyunoA Offline
            andyuno
            wrote on last edited by
            #5

            @henno
            Thanks for the pointer I'll give that a go

            :) Any Help is Appreciated Thank You.

            1 Reply Last reply
            0
            • andyunoA Offline
              andyunoA Offline
              andyuno
              wrote on last edited by hek
              #6

              Well this is my first attempt of merging some senses the code compiled with no errors, and they recognised by Vera, but I get no readings or activations as if they're dead

                  ///#include <Sleep_n0m1.h>
                  #include <SPI.h>
                  #include <EEPROM.h>  
                  #include <RF24.h>
                  #include <Sensor.h>  
                  #include <Relay.h>   //andys Added
                  
                  #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
                  #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
                  #define CHILD_ID 7   // Id of the sensor child
                  #define RELAY_1  4  //andys Added// Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                  #define NUMBER_OF_RELAYS 1 //andys Added
                  #define RELAY_ON 0  //andys Added
                  #define RELAY_OFF 1  //andys Added
                  
                  Sensor gw;
                  //Sleep sleep;
                  
                  void setup()  
                  {  
                    EEPROM.write(EEPROM_RELAY_ID_ADDRESS, 0);
                    
                    gw.begin();
                  
                    // Send the sketch version information to the gateway and Controller
                    gw.sendSketchInfo("Motion Sensor", "1.0");
                    gw.sendSketchInfo("Relay", "1.0");  //Andy Added
                  
                    pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
                    // Register all sensors to gw (they will be created as child devices)
                    gw.sendSensorPresentation(CHILD_ID, S_MOTION);
                    for (int i=0; i<NUMBER_OF_RELAYS;i++) {   //Andy Added
                    gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);  //Andy Added
                    
                  }
                   // Fetch relay status    //Andy Added
                    for (int i=0; i<NUMBER_OF_RELAYS;i++) {    //Andy Added
                      // Make sure relays are off when starting up   //Andy Added
                      digitalWrite(RELAY_1+i, RELAY_OFF);   //Andy Added
                      // Then set relay pins in output mode   //Andy Added
                      pinMode(RELAY_1+i, OUTPUT);      //Andy Added
                        
                      // Request/wait for relay status //Andy Added
                      gw.getStatus(RELAY_1+i, V_LIGHT);   //Andy Added
                      setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
                    }  //Andy Added
                    
                    
                   }
                   
                  void loop()     
                  {     
                      if (gw.messageAvailable()) {   //Andy Added
                      message_s message = gw.getMessage();   //Andy Added
                      setRelayStatus(message);   //Andy Added
                    // Read digital motion value
                    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                          
                    Serial.println(tripped);
                    gw.sendVariable(CHILD_ID, V_TRIPPED, tripped?"1":"0");  // Send tripped value to gw 
                   
                    // Power down the radio.  Note that the radio will get powered back up
                    // on the next write() call.
                    delay(200); //delay to allow serial to fully print before sleep
                   // gw.powerDown();
                  //  sleep.pwrDownMode(); //set sleep mode
                  //  sleep.sleepInterrupt(INTERRUPT,CHANGE);
                  }
                  
                  }
                  
                  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);
                     }
                  }  
              

              I think I've overlooked something in order not for this to work

              :) Any Help is Appreciated Thank You.

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

                Remove this line:

                EEPROM.write(EEPROM_RELAY_ID_ADDRESS, 0);

                .. it should not be in the example (I've updated it on github).

                1 Reply Last reply
                0
                • andyunoA Offline
                  andyunoA Offline
                  andyuno
                  wrote on last edited by
                  #8

                  Thanks, been doing some more testing it seems as though my movement sensor interacts with the relays which wasn't my intention, and I have no control over them within Vera.

                  :) Any Help is Appreciated Thank You.

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

                    By putting 4 spaces first on each line you get code formatting here in the forum (mark section in IDE and press tab a couple of times to indent the section before copying it here).

                    I think you also can do a "Copy for forum" in the edit-menu.

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

                      Why not a default "multisensor" on the mysensors site at the example page? I see a lot of people like me who are new to arduino and looking for a multisensor sketch. For me the ultimate sensor is like the "roomnode" like a jeenode : Motion + light (LDR) + temp (ds18b20), where motion message is direct and the others once a minute or so.

                      hekH 1 Reply Last reply
                      0
                      • E egbertje

                        Why not a default "multisensor" on the mysensors site at the example page? I see a lot of people like me who are new to arduino and looking for a multisensor sketch. For me the ultimate sensor is like the "roomnode" like a jeenode : Motion + light (LDR) + temp (ds18b20), where motion message is direct and the others once a minute or so.

                        hekH Offline
                        hekH Offline
                        hek
                        Admin
                        wrote on last edited by
                        #11

                        @egbertje

                        Yes, that is a good idea. Someone up for the task?

                        BulldogLowellB 1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          egbertje
                          wrote on last edited by
                          #12

                          Im already trying, but have to learn a lot :)

                          1 Reply Last reply
                          0
                          • hekH hek

                            @egbertje

                            Yes, that is a good idea. Someone up for the task?

                            BulldogLowellB Offline
                            BulldogLowellB Offline
                            BulldogLowell
                            Contest Winner
                            wrote on last edited by
                            #13

                            @hek

                            :)

                            Perhaps we can get a list of preferred combinations and I can work on that alongside anyone else who may wish to do that too.

                            I'd like to help but also would like it 100% debugged before we publish.

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

                              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.

                              marceltrapmanM E 2 Replies 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.

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

                                @hek said:

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

                                +1 for that combo :)

                                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.

                                clippermiamiC 1 Reply Last reply
                                0
                                • andyunoA Offline
                                  andyunoA Offline
                                  andyuno
                                  wrote on last edited by
                                  #16

                                  I think this is a good basis to start. A standard set of multi-senses based on temperature, humidity, light and movement which I think would be useful in all applications

                                  :) Any Help is Appreciated Thank You.

                                  1 Reply Last reply
                                  0
                                  • marceltrapmanM marceltrapman

                                    @hek said:

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

                                    +1 for that combo :)

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

                                    @marceltrapman I'll second that :) I'm working on combining the Light-DHT but I'd really like to get the complete set going.

                                    1 Reply Last reply
                                    0
                                    • 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
                                          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.1k

                                          Posts


                                          Copyright 2025 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