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. My Project
  3. 3 in 1 incl battery monitor

3 in 1 incl battery monitor

Scheduled Pinned Locked Moved My Project
60 Posts 11 Posters 30.0k Views 12 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.
  • sundberg84S Offline
    sundberg84S Offline
    sundberg84
    Hardware Contributor
    wrote on last edited by
    #12

    What does your serial or error log tell you when you upload the sketch you have? And which sketch/code do you use at this point?

    Controller: Proxmox VM - Home Assistant
    MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
    MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
    RFLink GW - Arduino Mega + RFLink Shield, 433mhz

    1 Reply Last reply
    0
    • the cosmic gateT the cosmic gate

      I'am not getting this clear / working :(
      Could somebody help me to complete this 3in1 incl battery monitoring sketch working? Thnx

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

      @the-cosmic-gate

      I changed your original sketch a little. It now includes a conditional send for the "tripped" values and groups the conditional sends for all values.

      I was not able to test as I'm using a different library for the DHT.

      Have fun..

      #include <SPI.h>
      #include <MySensor.h>  
      #include <DHT.h>  
      
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      
      #define CHILD_ID_HUM 0
      #define CHILD_ID_TEMP 1
      #define CHILD_ID_MOT 2   // Id of the sensor child
      
      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
      #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)
      
      unsigned long SLEEP_TIME = 30000UL; // Sleep time between reads (in milliseconds)
      int oldBatteryPcnt = 0;
      
      MySensor gw;
      DHT dht;
      float lastTemp = 0 ;
      float lastHum = 0 ;
      boolean lastTripped = false ;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
      
      void setup()  
      { 
         // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
         analogReference(INTERNAL1V1);
      #else
         analogReference(INTERNAL);
      #endif
        gw.begin();
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN. DHT22); 
      
        // Send the Sketch Version Information to the Gateway
        gw.sendSketchInfo("Humidity/Motion", "1.0");
      
      
       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.present(CHILD_ID_HUM, S_HUM);
        gw.present(CHILD_ID_TEMP, S_TEMP);
        gw.present(CHILD_ID_MOT, S_MOTION);
         
        metric = gw.getConfig().isMetric;
      }
      
      void loop()      
      
      {  
        // get the battery Voltage
         int sensorValue = analogRead(BATTERY_SENSE_PIN);
         #ifdef DEBUG
         Serial.println(sensorValue);
         #endif
         
         // 1M, 470K divider across battery and using internal ADC ref of 1.1V
         // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
         // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
         // 3.44/1023 = Volts per bit = 0.003363075
         float batteryV  = sensorValue * 0.003363075;
         int batteryPcnt = sensorValue / 10;
      
         #ifdef DEBUG
         Serial.print("Battery Voltage: ");
         Serial.print(batteryV);
         Serial.println(" V");
      
         Serial.print("Battery percent: ");
         Serial.print(batteryPcnt);
         Serial.println(" %");
         #endif
      
         if (oldBatteryPcnt != batteryPcnt) {
           // Power up radio after sleep
           gw.sendBatteryLevel(batteryPcnt);
           oldBatteryPcnt = batteryPcnt;
         }
           
           
        // Read digital motion value
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
        
        if (tripped != lastTripped ) {      
        	Serial.println(tripped);
        	gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw 
        }
        delay(dht.getMinimumSamplingPeriod());
      
        float temperature = dht.getTemperature();
        float humidity = dht.getHumidity();
        
        if (isnan(temperature)) {
            Serial.println("Failed reading temperature from DHT");
        } else if (temperature != lastTemp) {
          lastTemp = temperature;
          if (!metric) {
            temperature = dht.toFahrenheit(temperature);
          }
          gw.send(msgTemp.set(temperature, 1));
          Serial.print("T: ");
          Serial.println(temperature);
        }
        
        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);
        }
      
         if (oldBatteryPcnt != batteryPcnt) {
           // Power up radio after sleep
           gw.sendBatteryLevel(batteryPcnt);
           oldBatteryPcnt = batteryPcnt;
         }
        
       
        // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
      }
      
      1 Reply Last reply
      0
      • the cosmic gateT Offline
        the cosmic gateT Offline
        the cosmic gate
        wrote on last edited by
        #14

        Thnx a lot @AWI
        there was 1 verification error,

        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN. DHT22); 
        

        changed it, to :

        #include <SPI.h>
        #include <MySensor.h>  
        #include <DHT.h>  
        
        int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define CHILD_ID_MOT 2   // Id of the sensor child
        
        #define HUMIDITY_SENSOR_DIGITAL_PIN 4
        #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)
        
        unsigned long SLEEP_TIME = 30000UL; // Sleep time between reads (in milliseconds)
        int oldBatteryPcnt = 0;
        
        MySensor gw;
        DHT dht;
        float lastTemp = 0 ;
        float lastHum = 0 ;
        boolean lastTripped = false ;
        boolean metric = true; 
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
        
        void setup()  
        { 
           // use the 1.1 V internal reference
        #if defined(__AVR_ATmega2560__)
           analogReference(INTERNAL1V1);
        #else
           analogReference(INTERNAL);
        #endif
          gw.begin();
          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
        
          // Send the Sketch Version Information to the Gateway
          gw.sendSketchInfo("Humidity/Motion", "1.0");
        
        
         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.present(CHILD_ID_HUM, S_HUM);
          gw.present(CHILD_ID_TEMP, S_TEMP);
          gw.present(CHILD_ID_MOT, S_MOTION);
           
          metric = gw.getConfig().isMetric;
        }
        
        void loop()      
        
        {  
          // get the battery Voltage
           int sensorValue = analogRead(BATTERY_SENSE_PIN);
           #ifdef DEBUG
           Serial.println(sensorValue);
           #endif
           
           // 1M, 470K divider across battery and using internal ADC ref of 1.1V
           // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
           // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
           // 3.44/1023 = Volts per bit = 0.003363075
           float batteryV  = sensorValue * 0.003363075;
           int batteryPcnt = sensorValue / 10;
        
           #ifdef DEBUG
           Serial.print("Battery Voltage: ");
           Serial.print(batteryV);
           Serial.println(" V");
        
           Serial.print("Battery percent: ");
           Serial.print(batteryPcnt);
           Serial.println(" %");
           #endif
        
           if (oldBatteryPcnt != batteryPcnt) {
             // Power up radio after sleep
             gw.sendBatteryLevel(batteryPcnt);
             oldBatteryPcnt = batteryPcnt;
           }
             
             
          // Read digital motion value
          boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
          
          if (tripped != lastTripped ) {      
            Serial.println(tripped);
            gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw 
          }
          delay(dht.getMinimumSamplingPeriod());
        
          float temperature = dht.getTemperature();
          float humidity = dht.getHumidity();
          
          if (isnan(temperature)) {
              Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
            if (!metric) {
              temperature = dht.toFahrenheit(temperature);
            }
            gw.send(msgTemp.set(temperature, 1));
            Serial.print("T: ");
            Serial.println(temperature);
          }
          
          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);
          }
        
           if (oldBatteryPcnt != batteryPcnt) {
             // Power up radio after sleep
             gw.sendBatteryLevel(batteryPcnt);
             oldBatteryPcnt = batteryPcnt;
           }
          
         
          // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
          gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
        }
        

        uploading now

        There's more than meets the eye

        1 Reply Last reply
        0
        • the cosmic gateT Offline
          the cosmic gateT Offline
          the cosmic gate
          wrote on last edited by
          #15

          working nice for 2 day's now !
          Thnx a lot @AWI !!!

          There's more than meets the eye

          1 Reply Last reply
          0
          • the cosmic gateT Offline
            the cosmic gateT Offline
            the cosmic gate
            wrote on last edited by
            #16

            Something strange: when I look in the IDE console the battery % is displayed. But using Domoticz there's no battery % display / selectable ? What's wrong , or do I forget something ?

            There's more than meets the eye

            1 Reply Last reply
            0
            • icebobI Offline
              icebobI Offline
              icebob
              wrote on last edited by
              #17

              In Domoticz you can see the battery level in Setup->Devices.
              domi_batt_level.png
              If you would like to see on a chart, you have to send the battery level or voltage to the controller as a sensor value too. After it, you can see as this:
              domi_batt_chart.png

              T 1 Reply Last reply
              0
              • icebobI icebob

                In Domoticz you can see the battery level in Setup->Devices.
                domi_batt_level.png
                If you would like to see on a chart, you have to send the battery level or voltage to the controller as a sensor value too. After it, you can see as this:
                domi_batt_chart.png

                T Offline
                T Offline
                Tronix
                wrote on last edited by
                #18

                @icebob

                Hi, I'm a newbee just started with MySensors. I built the first temp/hum sensor, and I'm trying to plot the battery level in a graph too. In this discussion you mention that I need to send the battery level to the controller as sensor value. Can you please share with me the code which I should use? Thanks a lot.

                Marco

                1 Reply Last reply
                0
                • icebobI Offline
                  icebobI Offline
                  icebob
                  wrote on last edited by
                  #19

                  Yes, I can.

                  This is the definition of message for battery level:

                  // Battery sensor (A0)
                  #define CHILD_ID_BATTERY 199
                  #define BATTERY_SENSOR_ANALOG_PIN 0
                  MyMessage msgBattery(CHILD_ID_BATTERY, V_VOLTAGE);
                  

                  And this is the sender function:

                  // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                  // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                  // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                  // 3.44/1023 = Volts per bit = 0.003363075
                  #define VBAT_PER_BITS 0.003363075
                  #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
                  #define VMAX 3.00  // Vmin<Vmax<=3.44
                  #define VCC_CORRECTION (3.4 / 3.33)
                  int lastBatteryLevel;
                  
                  bool sendBatteryLevel(bool force = false) {
                    int value = analogRead(BATTERY_SENSOR_ANALOG_PIN);
                  
                    float batVoltage  = value * VBAT_PER_BITS / VCC_CORRECTION;
                    int batLevel = static_cast<int>(((batVoltage-VMIN)/(VMAX-VMIN))*100.);
                    if (batLevel != lastBatteryLevel || force) {
                      gw.sendBatteryLevel(batLevel);
                      gw.send(msgBattery.set(batVoltage, 2));
                      
                      lastBatteryLevel = batLevel;
                    }
                    return true;
                  }```
                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Tronix
                    wrote on last edited by
                    #20

                    Great, thanks for your quick response. Implementing now. Looks good.

                    1 Reply Last reply
                    0
                    • the cosmic gateT Offline
                      the cosmic gateT Offline
                      the cosmic gate
                      wrote on last edited by
                      #21

                      Running the sketch for 1 Monty (+-), and the AA batteries are dead empty ?
                      I did all the "possible" mods on the arduino ( cut the LED an V ) , what can i do to make this sketch run langer on this 2AA batteries ?
                      Something in the sketch , some fine tuning or something else ?
                      When read the arduino hardware tweaking topics on different forums they dat that running for 1 year ( and more) is possible but how ;-)?

                      There's more than meets the eye

                      1 Reply Last reply
                      0
                      • carlierdC Offline
                        carlierdC Offline
                        carlierd
                        wrote on last edited by
                        #22

                        Hello,

                        Did you measured the current of your circuit ?
                        What motion sensor are you using ? This component may consume a lot of current. Did you check this post ?

                        If you wake-up the arduino every 30 seconds for measurement it's a problem. Every 5 minutes is the minimum I think. I have connected the Vcc pin of the DHT sensors and the Vcc of the LDR to a digital pin of the arduino and when a measurement is done I set the PIN to the HIGH state.

                        First measurement of my sensor gives an IDLE current consumption close to 5uA which is really correct according to elements connected to the arduino (RFM69HW, DHT22 and LDR).

                        David.

                        the cosmic gateT 1 Reply Last reply
                        0
                        • bjacobseB Offline
                          bjacobseB Offline
                          bjacobse
                          wrote on last edited by
                          #23

                          Yes as Carlierd writes, it's important that the Arduino are controlling the voltage to the external components, like DHT.
                          I might have overlooked, but which component are you using for motion sensing? maybe this component is also power-hungry

                          1 Reply Last reply
                          0
                          • icebobI Offline
                            icebobI Offline
                            icebob
                            wrote on last edited by
                            #24

                            @the-cosmic-gate Now I measured my dev circuit (Arduino Nano from China (cutted power led and desoldered regulator) + DHT22 + PIR + Battery measure resistor divider) and in gw.sleep (with 1 interrupt for PIR) the power comsumption is ~90uA.
                            DSC_9591_rs.jpg
                            It wakes up every minutes, measuring and sending (~100ms and 5 - 20mA).
                            So 100ms with 20mA and 59900ms with 0.09mA. The average current is 120uA and with 2 AA battery it is about 2 years.
                            ardu_batt.png

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              ericvdb
                              wrote on last edited by
                              #25

                              @icebob,
                              whats that app you are using to do the battery calculations?

                              1 Reply Last reply
                              0
                              • carlierdC Offline
                                carlierdC Offline
                                carlierd
                                wrote on last edited by
                                #26

                                @icebob
                                100ms for measurement and transmission seems very small ! I am at approximately 1500ms.
                                Give me your secret now !! ;)

                                1 Reply Last reply
                                0
                                • icebobI Offline
                                  icebobI Offline
                                  icebob
                                  wrote on last edited by
                                  #27

                                  @ericvdb http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en545243. It's specified for PIC, but I select SLEEP mode in every cycle, so I can use for any uC.

                                  @carlierd: I have no extra secret. If I measure 3-4 sensor and every values is changed, the loop time is 100ms. Best case is 10-20ms (if every sensors is unchanged). I'm not using delay in the loop.

                                  1 Reply Last reply
                                  0
                                  • carlierdC Offline
                                    carlierdC Offline
                                    carlierd
                                    wrote on last edited by
                                    #28

                                    @icebob: It's true that as I used signing feature, transmission is longer ! and in order to increase a little bit more I send every measure even if they not changed. I will probably upgrade my sketch to add a one-hour message at minimum and do not transfer mesure without change !

                                    1 Reply Last reply
                                    0
                                    • carlierdC carlierd

                                      Hello,

                                      Did you measured the current of your circuit ?
                                      What motion sensor are you using ? This component may consume a lot of current. Did you check this post ?

                                      If you wake-up the arduino every 30 seconds for measurement it's a problem. Every 5 minutes is the minimum I think. I have connected the Vcc pin of the DHT sensors and the Vcc of the LDR to a digital pin of the arduino and when a measurement is done I set the PIN to the HIGH state.

                                      First measurement of my sensor gives an IDLE current consumption close to 5uA which is really correct according to elements connected to the arduino (RFM69HW, DHT22 and LDR).

                                      David.

                                      the cosmic gateT Offline
                                      the cosmic gateT Offline
                                      the cosmic gate
                                      wrote on last edited by the cosmic gate
                                      #29

                                      @carlierd said:

                                      Hello,

                                      Did you measured the current of your circuit ?
                                      What motion sensor are you using ? This component may consume a lot of current. Did you check this post ?

                                      If you wake-up the arduino every 30 seconds for measurement it's a problem. Every 5 minutes is the minimum I think. I have connected the Vcc pin of the DHT sensors and the Vcc of the LDR to a digital pin of the arduino and when a measurement is done I set the PIN to the HIGH state.

                                      First measurement of my sensor gives an IDLE current consumption close to 5uA which is really correct according to elements connected to the arduino (RFM69HW, DHT22 and LDR).

                                      David.

                                      Hello David,
                                      I tried to meassure , but didn't have the right stuff to do this good enough.
                                      The parts i use for this "project": DHT-22 (connected to D4), HC-SR501 (connected to D3)and connected to the 3.3V pin post , the VVC is connected to the VVC of the arduino pro mini 8 Mhz /3.3 V .
                                      And use the sketch as above:

                                      #include <SPI.h>
                                      #include <MySensor.h>  
                                      #include <DHT.h>  
                                      
                                      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                      
                                      #define CHILD_ID_HUM 0
                                      #define CHILD_ID_TEMP 1
                                      #define CHILD_ID_MOT 2   // Id of the sensor child
                                      
                                      #define HUMIDITY_SENSOR_DIGITAL_PIN 4
                                      #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)
                                      
                                      unsigned long SLEEP_TIME = 30000UL; // Sleep time between reads (in milliseconds)
                                      int oldBatteryPcnt = 0;
                                      
                                      MySensor gw;
                                      DHT dht;
                                      float lastTemp = 0 ;
                                      float lastHum = 0 ;
                                      boolean lastTripped = false ;
                                      boolean metric = true; 
                                      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                      MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
                                      
                                      void setup()  
                                      { 
                                         // use the 1.1 V internal reference
                                      #if defined(__AVR_ATmega2560__)
                                         analogReference(INTERNAL1V1);
                                      #else
                                         analogReference(INTERNAL);
                                      #endif
                                        gw.begin();
                                        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                      
                                        // Send the Sketch Version Information to the Gateway
                                        gw.sendSketchInfo("Humidity/Motion", "1.0");
                                      
                                      
                                       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.present(CHILD_ID_HUM, S_HUM);
                                        gw.present(CHILD_ID_TEMP, S_TEMP);
                                        gw.present(CHILD_ID_MOT, S_MOTION);
                                         
                                        metric = gw.getConfig().isMetric;
                                      }
                                      
                                      void loop()      
                                      
                                      {  
                                        // get the battery Voltage
                                         int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                         #ifdef DEBUG
                                         Serial.println(sensorValue);
                                         #endif
                                         
                                         // 1M, 470K divider across battery and using internal ADC ref of 1.1V
                                         // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                                         // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
                                         // 3.44/1023 = Volts per bit = 0.003363075
                                         float batteryV  = sensorValue * 0.003363075;
                                         int batteryPcnt = sensorValue / 10;
                                      
                                         #ifdef DEBUG
                                         Serial.print("Battery Voltage: ");
                                         Serial.print(batteryV);
                                         Serial.println(" V");
                                      
                                         Serial.print("Battery percent: ");
                                         Serial.print(batteryPcnt);
                                         Serial.println(" %");
                                         #endif
                                      
                                         if (oldBatteryPcnt != batteryPcnt) {
                                           // Power up radio after sleep
                                           gw.sendBatteryLevel(batteryPcnt);
                                           oldBatteryPcnt = batteryPcnt;
                                         }
                                           
                                           
                                        // Read digital motion value
                                        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; 
                                        
                                        if (tripped != lastTripped ) {      
                                          Serial.println(tripped);
                                          gw.send(msgMot.set(tripped?"1":"0"));  // Send tripped value to gw 
                                        }
                                        delay(dht.getMinimumSamplingPeriod());
                                      
                                        float temperature = dht.getTemperature();
                                        float humidity = dht.getHumidity();
                                        
                                        if (isnan(temperature)) {
                                            Serial.println("Failed reading temperature from DHT");
                                        } else if (temperature != lastTemp) {
                                          lastTemp = temperature;
                                          if (!metric) {
                                            temperature = dht.toFahrenheit(temperature);
                                          }
                                          gw.send(msgTemp.set(temperature, 1));
                                          Serial.print("T: ");
                                          Serial.println(temperature);
                                        }
                                        
                                        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);
                                        }
                                      
                                         if (oldBatteryPcnt != batteryPcnt) {
                                           // Power up radio after sleep
                                           gw.sendBatteryLevel(batteryPcnt);
                                           oldBatteryPcnt = batteryPcnt;
                                         }
                                        
                                       
                                        // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
                                        gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
                                      }
                                      

                                      So how do you connect the DHT / SR501 to the digital pin, and what's the sketch you're using ?

                                      There's more than meets the eye

                                      1 Reply Last reply
                                      0
                                      • carlierdC Offline
                                        carlierdC Offline
                                        carlierd
                                        wrote on last edited by
                                        #30

                                        Hello,

                                        You need to power the motion sensor all time as you want to detect any mouvement and not only every 2 minutes.

                                        Caution, in your sketch, the battery level is sent at the beginning and at the end.

                                        Did you tweak the motion sensor ?? Not tested yet but it seems that modification could (must ?) be done to reduce power consumption (LINK).

                                        Why do you wake-up the arduino every 30 seconds ? For temperature, every 5 or 15 minutes is enough.

                                        the cosmic gateT 1 Reply Last reply
                                        0
                                        • carlierdC Offline
                                          carlierdC Offline
                                          carlierd
                                          wrote on last edited by
                                          #31

                                          @icebob: is you motion sensor often triggered ? I mean, is the sensor placed somewhere where there is a lot of mouvement ? I tried to do such sensor some months ago but my sensors was very often triggered on finally the time is sleep was small and my battery decreased very quickly !

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


                                          9

                                          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