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. Troubleshooting
  3. Humidity, temperature, motion and bunch of relays...

Humidity, temperature, motion and bunch of relays...

Scheduled Pinned Locked Moved Troubleshooting
12 Posts 5 Posters 5.4k Views 5 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.
  • Tomasz PazioT Offline
    Tomasz PazioT Offline
    Tomasz Pazio
    wrote on last edited by
    #3

    Sorry I was to fast. I have problem with second "array" or sensors, first is working on pins 14-17 so analog. Second part should work on pins 5-8 but I have no idea how to make this. All works fine now but on 4 relays, I need to add 4 more.

    DwaltD 1 Reply Last reply
    0
    • Tomasz PazioT Tomasz Pazio

      Sorry I was to fast. I have problem with second "array" or sensors, first is working on pins 14-17 so analog. Second part should work on pins 5-8 but I have no idea how to make this. All works fine now but on 4 relays, I need to add 4 more.

      DwaltD Offline
      DwaltD Offline
      Dwalt
      wrote on last edited by
      #4

      @Tomasz-Pazio I read too fast as well, did not see 'timer.setInterval(30000, getMeasure);

      You could use an Array to link the relay pins to Relay 1-8.

      Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

      1 Reply Last reply
      0
      • Tomasz PazioT Offline
        Tomasz PazioT Offline
        Tomasz Pazio
        wrote on last edited by
        #5

        @Dwalt think that I undersand the idea but no idea how to write this in code, google gives a lot of examples but hard for me to code this :(

        BulldogLowellB 1 Reply Last reply
        0
        • Tomasz PazioT Tomasz Pazio

          @Dwalt think that I undersand the idea but no idea how to write this in code, google gives a lot of examples but hard for me to code this :(

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

          @Tomasz-Pazio

          an approach with the relays would be like this bit of (untested) code:

          
          #include <MySigningNone.h>
          #include <MyTransportNRF24.h>
          #include <MyTransportRFM69.h>
          #include <MyHwATMega328.h>
          #include <MySensor.h>
          #include <SPI.h>
          
          #define NUMBER_OF_RELAYS 8
          #define RELAY_ON 1  // GPIO value to write to turn on attached relay
          #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
          
          const int relayPin[NUMBER_OF_RELAYS] = {5,6,7,8,14,15,16,17};  //<<<<<<<pin numbers
          
          MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
          
          MyHwATMega328 hw;
          
          MySensor gw(radio, hw);
          
          void setup()  
          {   
            gw.begin(incomingMessage, AUTO, true);
            gw.sendSketchInfo("multiRelay", "1.0");
            for (int i = 0; i < NUMBER_OF_RELAYS; i++) 
            {
              gw.present(i, S_LIGHT);
              pinMode(relayPin[i], OUTPUT);   
              digitalWrite(relayPin[i], LOW);
            }
          }
          
          void loop() 
          {
            gw.process();
          }
          
          void incomingMessage(const MyMessage &message) 
          {
            if (message.type == V_LIGHT) 
            {
               digitalWrite(relayPin[message.sensor], message.getBool()? RELAY_ON : RELAY_OFF);
             } 
          }
          
          1 Reply Last reply
          1
          • Tomasz PazioT Offline
            Tomasz PazioT Offline
            Tomasz Pazio
            wrote on last edited by
            #7

            @BulldogLowell works fine with this :) thanks for support.

            1 Reply Last reply
            1
            • petoulachiP Offline
              petoulachiP Offline
              petoulachi
              wrote on last edited by petoulachi
              #8

              Hey !

              I'm trying to use your code to do a Motion/temp/humidity sensor, but I dont know why the motion sensor is sending 0/1/0/1... if there is nothing moving ?!

              Here is my code :

              #include <SPI.h>
              #include <MySensor.h>  
              #include <DHT.h>  
              #include <SimpleTimer.h>
              
              #define CHILD_ID_HUM 0
              #define CHILD_ID_TEMP 1
              #define CHILD_ID_MOT 2
              #define MOTION_SENSOR_DIGITAL_PIN 3
              #define HUMIDITY_SENSOR_DIGITAL_PIN 4
              //#define INTERRUPT MOTION_SENSOR_DIGITAL_PIN-2
              
              unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
              
              MySensor gw;
              DHT dht;
              SimpleTimer timer;
              float lastTemp;
              float lastHum;
              boolean lastTripped;
              
              MyMessage msgHum(CHILD_ID_HUM, V_HUM);
              MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
              MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
              
              
              void setup()  
              { 
                gw.begin();
                dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
              
                // Send the Sketch Version Information to the Gateway
                gw.sendSketchInfo("Humidity/Motion", "1.0");
              
                pinMode(MOTION_SENSOR_DIGITAL_PIN, INPUT);
                // Register all sensors to gw (they will be created as child devices)
                gw.present(CHILD_ID_HUM, S_HUM);
                gw.present(CHILD_ID_TEMP, S_TEMP);
                gw.present(CHILD_ID_MOT, S_MOTION);
              
                timer.setInterval(30000, getMeasure);
              }
              
              void loop()      
              {  
                timer.run();
              
                boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH;    
                if (tripped != lastTripped) 
                {
                  lastTripped = tripped;
                  Serial.print("M: ");
                  Serial.println(tripped);
                  gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw
                 }
              }
              
              void getMeasure() 
              {
                delay(dht.getMinimumSamplingPeriod());
              
                float temperature = dht.getTemperature();
                if (isnan(temperature)) 
                {
                    Serial.println("Failed reading temperature from DHT");
                } 
                else if (temperature != lastTemp) 
                {
                  lastTemp = temperature;
                  gw.send(msgTemp.set(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.send(msgHum.set(humidity, 1));
                    Serial.print("H: ");
                    Serial.println(humidity);
                 }
              }
              
              
              

              Do you have any idea what could be causing that ?

              Regards !

              AWIA 1 Reply Last reply
              0
              • petoulachiP petoulachi

                Hey !

                I'm trying to use your code to do a Motion/temp/humidity sensor, but I dont know why the motion sensor is sending 0/1/0/1... if there is nothing moving ?!

                Here is my code :

                #include <SPI.h>
                #include <MySensor.h>  
                #include <DHT.h>  
                #include <SimpleTimer.h>
                
                #define CHILD_ID_HUM 0
                #define CHILD_ID_TEMP 1
                #define CHILD_ID_MOT 2
                #define MOTION_SENSOR_DIGITAL_PIN 3
                #define HUMIDITY_SENSOR_DIGITAL_PIN 4
                //#define INTERRUPT MOTION_SENSOR_DIGITAL_PIN-2
                
                unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                
                MySensor gw;
                DHT dht;
                SimpleTimer timer;
                float lastTemp;
                float lastHum;
                boolean lastTripped;
                
                MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
                
                
                void setup()  
                { 
                  gw.begin();
                  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                
                  // Send the Sketch Version Information to the Gateway
                  gw.sendSketchInfo("Humidity/Motion", "1.0");
                
                  pinMode(MOTION_SENSOR_DIGITAL_PIN, INPUT);
                  // Register all sensors to gw (they will be created as child devices)
                  gw.present(CHILD_ID_HUM, S_HUM);
                  gw.present(CHILD_ID_TEMP, S_TEMP);
                  gw.present(CHILD_ID_MOT, S_MOTION);
                
                  timer.setInterval(30000, getMeasure);
                }
                
                void loop()      
                {  
                  timer.run();
                
                  boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH;    
                  if (tripped != lastTripped) 
                  {
                    lastTripped = tripped;
                    Serial.print("M: ");
                    Serial.println(tripped);
                    gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw
                   }
                }
                
                void getMeasure() 
                {
                  delay(dht.getMinimumSamplingPeriod());
                
                  float temperature = dht.getTemperature();
                  if (isnan(temperature)) 
                  {
                      Serial.println("Failed reading temperature from DHT");
                  } 
                  else if (temperature != lastTemp) 
                  {
                    lastTemp = temperature;
                    gw.send(msgTemp.set(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.send(msgHum.set(humidity, 1));
                      Serial.print("H: ");
                      Serial.println(humidity);
                   }
                }
                
                
                

                Do you have any idea what could be causing that ?

                Regards !

                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by
                #9

                @petoulachi it looks like your input pin for the sensor is floating. You can enable the internal pull-up to check ( INPUT_PULLUP i.s.o. INPUT)

                1 Reply Last reply
                0
                • petoulachiP Offline
                  petoulachiP Offline
                  petoulachi
                  wrote on last edited by
                  #10

                  I'm sorry I'm a newbie with arduino so I don't understand what you want me to test ?

                  1 Reply Last reply
                  0
                  • petoulachiP Offline
                    petoulachiP Offline
                    petoulachi
                    wrote on last edited by
                    #11

                    If you were meaning that I have to do

                    pinMode(MOTION_SENSOR_DIGITAL_PIN, INPUT_PULLUP);
                    

                    instead of

                    pinMode(MOTION_SENSOR_DIGITAL_PIN, INPUT);
                    

                    It changes nothing !

                    1 Reply Last reply
                    0
                    • petoulachiP Offline
                      petoulachiP Offline
                      petoulachi
                      wrote on last edited by
                      #12

                      I found where was the problem, I'm really a newbee... The motion sensor was plugged to the 3.3VCC, not 5V, doing this strange behaviour !

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      10

                      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