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. My 2AA battery sensor

My 2AA battery sensor

Scheduled Pinned Locked Moved My Project
90 Posts 27 Posters 106.7k Views 36 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.
  • P Offline
    P Offline
    Patrick Mcgillan
    wrote on last edited by
    #29

    Good info here. Thought comes to mind about using a small solar cell off a defectivet walkway light to add a little charge back in to the system, when there is any kind of light around.

    1 Reply Last reply
    0
    • m26872M Offline
      m26872M Offline
      m26872
      Hardware Contributor
      wrote on last edited by
      #30

      Just an update on my battery levels. My VeraLite Datamine-plugin won't longer plot for me. I suspect I'm out of VeraLite memory to handle all the data. This is it. (Look above for last graphs.)
      Node 16: BatteryLevel 51
      Node 101: Dead 03 Feb
      Node 110; BatteryLevel 57
      Node 105: BatteryLevel 80
      Node 106: BatteryLevel 53
      As I hoped, the decrease rate for 105 and 106 is now less than 5% per month and 6-month target is already passed by half.
      The revenge of the Chinese step-up ?!

      1 Reply Last reply
      0
      • m26872M Offline
        m26872M Offline
        m26872
        Hardware Contributor
        wrote on last edited by
        #31

        Someone else noticed that one of the two batteries drained by the step-up always has negative(!) charge? Due to the AC-load? Could it be possible to extend battery life by adding some kind of capacitor?

        1 Reply Last reply
        0
        • m26872M Offline
          m26872M Offline
          m26872
          Hardware Contributor
          wrote on last edited by
          #32

          Node 105 and 106 down just 1% since last post (22 days ago). Not bad. Relatively stable readings and low activity, but it doesn't matter since we're all expected the sleep mode consumption to be the worst.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #33

            @EasyIoT: Thank you for your nice descriptions of the low power sensors.
            I have some questions regarding the temperature sensor:
            Did you use a "Low power modified" Arduino for that as well?
            How are you able to power the sensor via the step-up only when needed? Do you power the step-up via an digital pin or something?

            @m26872: Also thanks for your design. I am thinking of building something similar. So you got now about 5% battery drop per month using the china stepup with desoldered LED?

            m26872M 1 Reply Last reply
            0
            • ? A Former User

              @EasyIoT: Thank you for your nice descriptions of the low power sensors.
              I have some questions regarding the temperature sensor:
              Did you use a "Low power modified" Arduino for that as well?
              How are you able to power the sensor via the step-up only when needed? Do you power the step-up via an digital pin or something?

              @m26872: Also thanks for your design. I am thinking of building something similar. So you got now about 5% battery drop per month using the china stepup with desoldered LED?

              m26872M Offline
              m26872M Offline
              m26872
              Hardware Contributor
              wrote on last edited by m26872
              #34

              @daenny said:

              So you got now about 5% battery drop per month using the china stepup with desoldered LED?

              Today I read Node 105: 78% and Node 106: 51%. That's only 2% in the last 38 days.

              nod105_20150331.PNG

              Edit: Perhaps using the "%" here is a little careless, but I think everyone knows that we're talking battery level.

              EasyIoTE funky81F 2 Replies Last reply
              0
              • m26872M m26872

                @daenny said:

                So you got now about 5% battery drop per month using the china stepup with desoldered LED?

                Today I read Node 105: 78% and Node 106: 51%. That's only 2% in the last 38 days.

                nod105_20150331.PNG

                Edit: Perhaps using the "%" here is a little careless, but I think everyone knows that we're talking battery level.

                EasyIoTE Offline
                EasyIoTE Offline
                EasyIoT
                wrote on last edited by
                #35

                @daenny yes, I'm using DO pin and MOSFET connected to step up regulator. But this is complicated solution. I'ts better to use different temperature sensor which can operate down to 1.8V. Right now I'm testing custom board with NRF24L and HTU21D (it's not cheap, but it can work down to 1,8V). Results are pretty good. Temperature and humidity sensor can operate more than 5 years on 2 AA batteries. For example door window sensor and water leak sensor can work more than 10 years on 2 AA batteries. It's seems that for those sensors AA batteries are overkill.

                --
                EasyIoT framework http://iot-playground.com

                1 Reply Last reply
                0
                • m26872M m26872

                  @daenny said:

                  So you got now about 5% battery drop per month using the china stepup with desoldered LED?

                  Today I read Node 105: 78% and Node 106: 51%. That's only 2% in the last 38 days.

                  nod105_20150331.PNG

                  Edit: Perhaps using the "%" here is a little careless, but I think everyone knows that we're talking battery level.

                  funky81F Offline
                  funky81F Offline
                  funky81
                  wrote on last edited by funky81
                  #36

                  @m26872 I still dont get it. Why I cant get the same efficient power like you.
                  I already follow all of your requirement in the first thread - difference only I use breadboard.
                  The minimum consumption (sleep) that I've got still 2.4mA, compare to you, it still huge differences. I dont know what's wrong with my setup.

                  My sketch wake up every 10s (consumption up to 3.5mA), while sleep the lowest is 2.4mA.

                  #include <avr/sleep.h>    // Sleep Modes
                  #include <MySensor.h>
                  #include <SPI.h>
                  
                  MySensor gw;
                  #define BATTERY_SENSE_PIN 
                  #define SLEEP_IN_MS 86400000 // 1 day
                  #define PROD false
                  
                  int oldBatLevel;
                  
                  void setup()
                  {
                    gw.begin(NULL,1);
                    gw.sendSketchInfo("Basic-Sketch-MySensor", "1.0");
                  
                  
                    pinMode(2,INPUT);
                    digitalWrite (2, LOW);
                  
                    pinMode(3,INPUT);
                    digitalWrite (3, LOW);
                  
                    pinMode(4,OUTPUT);
                    digitalWrite (4, LOW);
                  
                    pinMode(5,INPUT);
                    digitalWrite (5, LOW);
                  
                    pinMode(6,INPUT);
                    digitalWrite (6, LOW);
                  
                    pinMode(7,INPUT);
                    digitalWrite (7, LOW);
                  
                    pinMode(8,INPUT);
                    digitalWrite (8, LOW);
                    
                    oldBatLevel = -1; 
                  
                    sendValue();
                    Serial.println("Startup Finished");
                    TurnOnLed();
                  }
                  
                  void TurnOnLed(){
                  
                      digitalWrite(4,HIGH);
                   gw.sleep(1000);
                          digitalWrite(4,LOW);
                    
                    gw.sleep(100);
                  }
                  
                  void loop ()
                  {  
                    sendValue();
                    gw.sleep(1000*10);
                  }  // end of loop
                  
                  void sendValue()
                  {
                    gw.powerUp(); 
                  
                    int batLevel = getBatteryLevel();
                    if (!PROD){
                      gw.sendBatteryLevel(batLevel);  
                      TurnOnLed();
                    }
                    else{
                      if (oldBatLevel != batLevel)
                      {
                        gw.sendBatteryLevel(batLevel);   
                        oldBatLevel = batLevel;
                        TurnOnLed();
                      }
                    }
                  
                    gw.powerDown(); 
                  }
                  
                  // Battery measure
                  int getBatteryLevel ()
                  {
                    int results = (readVcc() - 2000)  / 10;  
                  
                    if (results > 100)
                      results = 100;
                    if (results < 0)
                      results = 0;
                    return results;
                  } // end of getBandgap
                  
                  // when ADC completed, take an interrupt
                  EMPTY_INTERRUPT (ADC_vect);
                  
                  long readVcc() {
                    long result;
                    // Read 1.1V reference against AVcc
                    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
                    delay(2); // Wait for Vref to settle
                    noInterrupts ();
                    // start the conversion
                    ADCSRA |= _BV (ADSC) | _BV (ADIE);
                    set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
                    interrupts ();
                    sleep_mode ();
                    // reading should be done, but better make sure
                    // maybe the timer interrupt fired
                    while (bit_is_set(ADCSRA,ADSC));
                    result = ADCL;
                    result |= ADCH<<8;
                    result = 1126400L / result; // Back-calculate AVcc in mV
                  
                    return result;
                  }```
                  m26872M 1 Reply Last reply
                  0
                  • funky81F funky81

                    @m26872 I still dont get it. Why I cant get the same efficient power like you.
                    I already follow all of your requirement in the first thread - difference only I use breadboard.
                    The minimum consumption (sleep) that I've got still 2.4mA, compare to you, it still huge differences. I dont know what's wrong with my setup.

                    My sketch wake up every 10s (consumption up to 3.5mA), while sleep the lowest is 2.4mA.

                    #include <avr/sleep.h>    // Sleep Modes
                    #include <MySensor.h>
                    #include <SPI.h>
                    
                    MySensor gw;
                    #define BATTERY_SENSE_PIN 
                    #define SLEEP_IN_MS 86400000 // 1 day
                    #define PROD false
                    
                    int oldBatLevel;
                    
                    void setup()
                    {
                      gw.begin(NULL,1);
                      gw.sendSketchInfo("Basic-Sketch-MySensor", "1.0");
                    
                    
                      pinMode(2,INPUT);
                      digitalWrite (2, LOW);
                    
                      pinMode(3,INPUT);
                      digitalWrite (3, LOW);
                    
                      pinMode(4,OUTPUT);
                      digitalWrite (4, LOW);
                    
                      pinMode(5,INPUT);
                      digitalWrite (5, LOW);
                    
                      pinMode(6,INPUT);
                      digitalWrite (6, LOW);
                    
                      pinMode(7,INPUT);
                      digitalWrite (7, LOW);
                    
                      pinMode(8,INPUT);
                      digitalWrite (8, LOW);
                      
                      oldBatLevel = -1; 
                    
                      sendValue();
                      Serial.println("Startup Finished");
                      TurnOnLed();
                    }
                    
                    void TurnOnLed(){
                    
                        digitalWrite(4,HIGH);
                     gw.sleep(1000);
                            digitalWrite(4,LOW);
                      
                      gw.sleep(100);
                    }
                    
                    void loop ()
                    {  
                      sendValue();
                      gw.sleep(1000*10);
                    }  // end of loop
                    
                    void sendValue()
                    {
                      gw.powerUp(); 
                    
                      int batLevel = getBatteryLevel();
                      if (!PROD){
                        gw.sendBatteryLevel(batLevel);  
                        TurnOnLed();
                      }
                      else{
                        if (oldBatLevel != batLevel)
                        {
                          gw.sendBatteryLevel(batLevel);   
                          oldBatLevel = batLevel;
                          TurnOnLed();
                        }
                      }
                    
                      gw.powerDown(); 
                    }
                    
                    // Battery measure
                    int getBatteryLevel ()
                    {
                      int results = (readVcc() - 2000)  / 10;  
                    
                      if (results > 100)
                        results = 100;
                      if (results < 0)
                        results = 0;
                      return results;
                    } // end of getBandgap
                    
                    // when ADC completed, take an interrupt
                    EMPTY_INTERRUPT (ADC_vect);
                    
                    long readVcc() {
                      long result;
                      // Read 1.1V reference against AVcc
                      ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
                      delay(2); // Wait for Vref to settle
                      noInterrupts ();
                      // start the conversion
                      ADCSRA |= _BV (ADSC) | _BV (ADIE);
                      set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
                      interrupts ();
                      sleep_mode ();
                      // reading should be done, but better make sure
                      // maybe the timer interrupt fired
                      while (bit_is_set(ADCSRA,ADSC));
                      result = ADCL;
                      result |= ADCH<<8;
                      result = 1126400L / result; // Back-calculate AVcc in mV
                    
                      return result;
                    }```
                    m26872M Offline
                    m26872M Offline
                    m26872
                    Hardware Contributor
                    wrote on last edited by
                    #37

                    @funky81 said:

                    @m26872 I still dont get it. Why I cant get the same efficient power like you....

                    I see that your sketch uses the internal battery monitoring method. That isn't possible when using the design as in this threads subject, with a step-up regulator that makes Vbat different from Vcc. Are you sure you're not confusing my design with EaysIoTs ?

                    Anyhow, I can't explain the sleep mode consumption, it seems like something isn't sleeping like it should.

                    Here's my sketch for Node 105/106:

                    // Egen kombo-nod för DHT22, BMP180 och batterimonitering.
                    // 20141019
                    // DHT-22 Working voltage: DC 3.3-5.5V (so connect after step-up regulator). http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf
                    // BMP180 (compatible with BMP085) working voltage 1.8-3.6V. Different boards with different power and pullups. Datasheet for ic only: http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 
                    #include <SPI.h>
                    #include <MySensor.h>  
                    #include <DHT.h>
                    #include <Wire.h>
                    #include <Adafruit_BMP085.h> // N.b. The new library includes the function readSealevelPressure() 
                    
                    #define NODE_ID 106  // Manually asign Node Id  <<<<<<<<<<<<<<<<<<<  ENTER THIS !!!!
                    #define ONE_WIRE_BUS 3 // Pin where dallase sensor bus is connected. <<<<<<<<<<<<<<<  DON'T FORGET 4k7 PULL-UP !!! >>>>>>>>>>>>>>>>
                    #define VBAT_PER_BITS 0.003363075  // Calculated volts per bit from the used battery montoring voltage divider.   Internal_ref=1.1V, res=10bit=2^10-1=1023, Eg for 3V (2AA): Vin/Vb=R1/(R1+R2)=470e3/(1e6+470e3),  Vlim=Vb/Vin*1.1=3.44V, Volts per bit = Vlim/1023= 0.003363075
                    #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
                    #define VMAX 3.3  //  " " " high level. Vmin<Vmax<=3.44
                    #define CHILD_ID_HUM 0
                    #define CHILD_ID_TEMP 1
                    #define BARO_CHILD 2
                    //#define TEMP_CHILD 3  // Commented since don't need the Bmp tempsensor
                    #define HUMIDITY_SENSOR_DIGITAL_PIN 3  // <<<<<<<<<<<<<<<<<<<<<<<<  Use 4k7 Pull-up. MySensors webpage doesn't use, datasheet does. Adafruit does https://learn.adafruit.com/dht/using-a-dhtxx-sensor
                    
                    unsigned long SLEEP_TIME = 15*60000; //  sleep time between reads (in milliseconds)
                    unsigned long preSleepTime = 5*60000; //  sleep time for extra pre hum-reading for simple avaraging filter
                    Adafruit_BMP085 bmp = Adafruit_BMP085();      // Digital Pressure Sensor 
                    MySensor gw;
                    DHT dht;
                    float lastTemp;
                    float lastHum;
                    float lastPressure = -1;
                    //float lastBmpTemp = -1; // Commented since don't need the Bmp tempsensor
                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                    //MyMessage tempMsg(TEMP_CHILD, V_TEMP); // Commented since don't need the Bmp tempsensor
                    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
                    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                    int oldBatteryPcnt = 0;
                    
                    void setup()  
                    { 
                      analogReference(INTERNAL);    // use the 1.1 V internal reference for battery level measuring
                      delay(500); // Allow time for radio if power used as reset <<<<<<<<<<<<<< Experimented with good result 
                      gw.begin(NULL,NODE_ID); // Startup and initialize MySensors library. Set callback for incoming messages. 
                      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                    
                      gw.sendSketchInfo("EgHumBarTemBatv2", "2.0 20141110");   // Send the Sketch Version Information to the Gateway
                      
                      if (!bmp.begin()) {
                    	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
                    	while (1) {  }
                      }
                    
                      gw.present(CHILD_ID_HUM, S_HUM);   // Register all sensors to gw (they will be created as child devices)
                      gw.present(CHILD_ID_TEMP, S_TEMP);
                      gw.present(BARO_CHILD, S_BARO);
                    //  gw.present(TEMP_CHILD, S_TEMP); // Commented since don't need the Bmp tempsensor
                      
                    }
                    
                    void loop()      
                    {  
                      delay(dht.getMinimumSamplingPeriod());
                      
                      float humidity_1 = dht.getHumidity();
                      if (isnan(humidity_1)) {
                    	  Serial.println("Failed reading humidity_1 from DHT");
                      } 
                    //  else {
                    //      Serial.print("Hum1: ");
                    //      Serial.println(humidity_1);
                    //  }  
                      
                      gw.sleep(preSleepTime); //sleep shortly until the "real" processing happens
                      
                      delay(dht.getMinimumSamplingPeriod());
                    
                      float humidity_2 = dht.getHumidity();
                      if (isnan(humidity_2)) {
                    	  Serial.println("Failed reading humidity_2 from DHT");
                      } 
                    //  else {
                    //      Serial.print("Hum2: ");
                    //      Serial.println(humidity_2);
                    //  }
                      if ( isnan(humidity_1) && isnan(humidity_2) ) {
                    	Serial.println("Failed reading humidity_1 and humidity_2 from DHT");
                      }
                      else if ( isnan(humidity_2) && !isnan(humidity_1) ) { // && abs(humidity_1-lastHum)>2. ) {  // Ev hysteres
                    	gw.send(msgHum.set(humidity_1, 1));
                    	lastHum = humidity_1;
                    //    Serial.println("Humidity_1 sent to gw.");
                      } 
                      else if ( isnan(humidity_1) && !isnan(humidity_2) ) { // && abs(humidity_2-lastHum)>2. ) {
                    	gw.send(msgHum.set(humidity_2, 1));
                    	lastHum = humidity_2;
                    //    Serial.println("Humidity_2 sent to gw.");
                      }  
                      else {
                    //    Serial.println("Else mean calc");
                    	float humidity_m = (humidity_1+humidity_2)/2. ;  // Averageing the two.
                    //    if ( abs(humidity_m-lastHum) > 2. ) {  
                    	  gw.send(msgHum.set(humidity_m, 1));
                    	  lastHum = humidity_m;
                    //      Serial.println("The mean humidity_m sent to gw.");
                    //    }
                      }
                    
                      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));  // Always send temperature
                    //      Serial.print("Sent temp: ");
                    //      Serial.println(temperature);
                      }
                    
                      float pressure = bmp.readPressure()/100;
                    //  float pressureS = bmp.readSealevelPressure(75.)/100;
                    //  Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" Pa");
                    //  Serial.print("SeaLevelPressure = "); Serial.print(pressureS); Serial.println(" Pa");
                      if (pressure != lastPressure) {
                    	gw.send(pressureMsg.set(pressure, 0));
                    	lastPressure = pressure;
                    //    Serial.print("Sent pressure: ");
                    //    Serial.println(pressure);
                      }
                    //  float bmpTemperature = bmp.readTemperature(); // Commented since don't need the Bmp tempsensor
                    ////  Serial.print("Temperature = "); Serial.print(bmpTemperature); Serial.println(" *C");
                    //  if (bmpTemperature != lastBmpTemp) {
                    //    gw.send(tempMsg.set(bmpTemperature,1));
                    //    lastBmpTemp = bmpTemperature;
                    //  }
                    
                      int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
                    //  Serial.println(sensorValue);
                      float Vbat  = sensorValue * VBAT_PER_BITS;
                    //  Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" V");
                     //int batteryPcnt = sensorValue / 10;
                      int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
                    //  Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
                      if (oldBatteryPcnt != batteryPcnt) {
                    	gw.sendBatteryLevel(batteryPcnt);
                    	oldBatteryPcnt = batteryPcnt;
                      }
                    
                      gw.sleep(SLEEP_TIME); //sleep a bit
                    }
                    
                    funky81F 1 Reply Last reply
                    0
                    • m26872M m26872

                      @funky81 said:

                      @m26872 I still dont get it. Why I cant get the same efficient power like you....

                      I see that your sketch uses the internal battery monitoring method. That isn't possible when using the design as in this threads subject, with a step-up regulator that makes Vbat different from Vcc. Are you sure you're not confusing my design with EaysIoTs ?

                      Anyhow, I can't explain the sleep mode consumption, it seems like something isn't sleeping like it should.

                      Here's my sketch for Node 105/106:

                      // Egen kombo-nod för DHT22, BMP180 och batterimonitering.
                      // 20141019
                      // DHT-22 Working voltage: DC 3.3-5.5V (so connect after step-up regulator). http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf
                      // BMP180 (compatible with BMP085) working voltage 1.8-3.6V. Different boards with different power and pullups. Datasheet for ic only: http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 
                      #include <SPI.h>
                      #include <MySensor.h>  
                      #include <DHT.h>
                      #include <Wire.h>
                      #include <Adafruit_BMP085.h> // N.b. The new library includes the function readSealevelPressure() 
                      
                      #define NODE_ID 106  // Manually asign Node Id  <<<<<<<<<<<<<<<<<<<  ENTER THIS !!!!
                      #define ONE_WIRE_BUS 3 // Pin where dallase sensor bus is connected. <<<<<<<<<<<<<<<  DON'T FORGET 4k7 PULL-UP !!! >>>>>>>>>>>>>>>>
                      #define VBAT_PER_BITS 0.003363075  // Calculated volts per bit from the used battery montoring voltage divider.   Internal_ref=1.1V, res=10bit=2^10-1=1023, Eg for 3V (2AA): Vin/Vb=R1/(R1+R2)=470e3/(1e6+470e3),  Vlim=Vb/Vin*1.1=3.44V, Volts per bit = Vlim/1023= 0.003363075
                      #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
                      #define VMAX 3.3  //  " " " high level. Vmin<Vmax<=3.44
                      #define CHILD_ID_HUM 0
                      #define CHILD_ID_TEMP 1
                      #define BARO_CHILD 2
                      //#define TEMP_CHILD 3  // Commented since don't need the Bmp tempsensor
                      #define HUMIDITY_SENSOR_DIGITAL_PIN 3  // <<<<<<<<<<<<<<<<<<<<<<<<  Use 4k7 Pull-up. MySensors webpage doesn't use, datasheet does. Adafruit does https://learn.adafruit.com/dht/using-a-dhtxx-sensor
                      
                      unsigned long SLEEP_TIME = 15*60000; //  sleep time between reads (in milliseconds)
                      unsigned long preSleepTime = 5*60000; //  sleep time for extra pre hum-reading for simple avaraging filter
                      Adafruit_BMP085 bmp = Adafruit_BMP085();      // Digital Pressure Sensor 
                      MySensor gw;
                      DHT dht;
                      float lastTemp;
                      float lastHum;
                      float lastPressure = -1;
                      //float lastBmpTemp = -1; // Commented since don't need the Bmp tempsensor
                      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                      //MyMessage tempMsg(TEMP_CHILD, V_TEMP); // Commented since don't need the Bmp tempsensor
                      MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
                      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                      int oldBatteryPcnt = 0;
                      
                      void setup()  
                      { 
                        analogReference(INTERNAL);    // use the 1.1 V internal reference for battery level measuring
                        delay(500); // Allow time for radio if power used as reset <<<<<<<<<<<<<< Experimented with good result 
                        gw.begin(NULL,NODE_ID); // Startup and initialize MySensors library. Set callback for incoming messages. 
                        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                      
                        gw.sendSketchInfo("EgHumBarTemBatv2", "2.0 20141110");   // Send the Sketch Version Information to the Gateway
                        
                        if (!bmp.begin()) {
                      	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
                      	while (1) {  }
                        }
                      
                        gw.present(CHILD_ID_HUM, S_HUM);   // Register all sensors to gw (they will be created as child devices)
                        gw.present(CHILD_ID_TEMP, S_TEMP);
                        gw.present(BARO_CHILD, S_BARO);
                      //  gw.present(TEMP_CHILD, S_TEMP); // Commented since don't need the Bmp tempsensor
                        
                      }
                      
                      void loop()      
                      {  
                        delay(dht.getMinimumSamplingPeriod());
                        
                        float humidity_1 = dht.getHumidity();
                        if (isnan(humidity_1)) {
                      	  Serial.println("Failed reading humidity_1 from DHT");
                        } 
                      //  else {
                      //      Serial.print("Hum1: ");
                      //      Serial.println(humidity_1);
                      //  }  
                        
                        gw.sleep(preSleepTime); //sleep shortly until the "real" processing happens
                        
                        delay(dht.getMinimumSamplingPeriod());
                      
                        float humidity_2 = dht.getHumidity();
                        if (isnan(humidity_2)) {
                      	  Serial.println("Failed reading humidity_2 from DHT");
                        } 
                      //  else {
                      //      Serial.print("Hum2: ");
                      //      Serial.println(humidity_2);
                      //  }
                        if ( isnan(humidity_1) && isnan(humidity_2) ) {
                      	Serial.println("Failed reading humidity_1 and humidity_2 from DHT");
                        }
                        else if ( isnan(humidity_2) && !isnan(humidity_1) ) { // && abs(humidity_1-lastHum)>2. ) {  // Ev hysteres
                      	gw.send(msgHum.set(humidity_1, 1));
                      	lastHum = humidity_1;
                      //    Serial.println("Humidity_1 sent to gw.");
                        } 
                        else if ( isnan(humidity_1) && !isnan(humidity_2) ) { // && abs(humidity_2-lastHum)>2. ) {
                      	gw.send(msgHum.set(humidity_2, 1));
                      	lastHum = humidity_2;
                      //    Serial.println("Humidity_2 sent to gw.");
                        }  
                        else {
                      //    Serial.println("Else mean calc");
                      	float humidity_m = (humidity_1+humidity_2)/2. ;  // Averageing the two.
                      //    if ( abs(humidity_m-lastHum) > 2. ) {  
                      	  gw.send(msgHum.set(humidity_m, 1));
                      	  lastHum = humidity_m;
                      //      Serial.println("The mean humidity_m sent to gw.");
                      //    }
                        }
                      
                        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));  // Always send temperature
                      //      Serial.print("Sent temp: ");
                      //      Serial.println(temperature);
                        }
                      
                        float pressure = bmp.readPressure()/100;
                      //  float pressureS = bmp.readSealevelPressure(75.)/100;
                      //  Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" Pa");
                      //  Serial.print("SeaLevelPressure = "); Serial.print(pressureS); Serial.println(" Pa");
                        if (pressure != lastPressure) {
                      	gw.send(pressureMsg.set(pressure, 0));
                      	lastPressure = pressure;
                      //    Serial.print("Sent pressure: ");
                      //    Serial.println(pressure);
                        }
                      //  float bmpTemperature = bmp.readTemperature(); // Commented since don't need the Bmp tempsensor
                      ////  Serial.print("Temperature = "); Serial.print(bmpTemperature); Serial.println(" *C");
                      //  if (bmpTemperature != lastBmpTemp) {
                      //    gw.send(tempMsg.set(bmpTemperature,1));
                      //    lastBmpTemp = bmpTemperature;
                      //  }
                      
                        int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
                      //  Serial.println(sensorValue);
                        float Vbat  = sensorValue * VBAT_PER_BITS;
                      //  Serial.print("Battery Voltage: "); Serial.print(Vbat); Serial.println(" V");
                       //int batteryPcnt = sensorValue / 10;
                        int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
                      //  Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
                        if (oldBatteryPcnt != batteryPcnt) {
                      	gw.sendBatteryLevel(batteryPcnt);
                      	oldBatteryPcnt = batteryPcnt;
                        }
                      
                        gw.sleep(SLEEP_TIME); //sleep a bit
                      }
                      
                      funky81F Offline
                      funky81F Offline
                      funky81
                      wrote on last edited by
                      #38

                      @m26872 in my previous sketch, yes, i'm trying to use EasyIOT's (Thanks @EasyIoT :+1: )
                      anyway, i'll flash with yours. I'll let know the result

                      1 Reply Last reply
                      0
                      • m26872M Offline
                        m26872M Offline
                        m26872
                        Hardware Contributor
                        wrote on last edited by
                        #39

                        I declare the 6 months criteria easily passed. And the chinese step up regulator to be good value for money. Next target; 12 months.
                        Nod105106_maj09.png

                        m26872M 1 Reply Last reply
                        1
                        • sundberg84S Offline
                          sundberg84S Offline
                          sundberg84
                          Hardware Contributor
                          wrote on last edited by sundberg84
                          #40

                          Hi!
                          This is also what im trying to do... have the same components/material as you and added the resistors for battery measurement. I dont get this long life (sleeps 15min, activated and sends).

                          Can you post some sort of schematics or more detailed pictures so i can see your connections?
                          Would be great!
                          Here is my own try for a schematics:
                          http://forum.mysensors.org/uploads/upload-5ed3f6ed-2d8c-4e6e-83bf-407973550c49.jpg

                          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

                          m26872M 1 Reply Last reply
                          0
                          • SweebeeS Offline
                            SweebeeS Offline
                            Sweebee
                            wrote on last edited by
                            #41

                            A tip for much better batterylife: burn a new bootloader for 1mhz. Now you can attach the arduino and nrf directly to the batteries and you can measure the battery with the Internal voltage meter of the 328p. If you use a dht you attach the step-up conv. And only attach the dht to it.

                            m26872M 1 Reply Last reply
                            0
                            • sundberg84S sundberg84

                              Hi!
                              This is also what im trying to do... have the same components/material as you and added the resistors for battery measurement. I dont get this long life (sleeps 15min, activated and sends).

                              Can you post some sort of schematics or more detailed pictures so i can see your connections?
                              Would be great!
                              Here is my own try for a schematics:
                              http://forum.mysensors.org/uploads/upload-5ed3f6ed-2d8c-4e6e-83bf-407973550c49.jpg

                              m26872M Offline
                              m26872M Offline
                              m26872
                              Hardware Contributor
                              wrote on last edited by
                              #42

                              @sundberg84
                              I've looked at your lovely drawing before and I don't see anything wrong with it except from that 0.1uF capacitor should be in parallell just with the 470k resistor, but it shouldn't matter regarding battery life time. What would be more interesting is to see your sketch. Or do you use the same as I do?

                              A schematic and a few better pictures is on my to do list, but will probably come sooner now since you asked for it.

                              1 Reply Last reply
                              0
                              • sundberg84S Offline
                                sundberg84S Offline
                                sundberg84
                                Hardware Contributor
                                wrote on last edited by sundberg84
                                #43

                                @m26872
                                Pretty much the same, i have stolen majority of your code:
                                Ive a array to get an average battery value each hour:

                                #include <SPI.h>
                                #include <MySensor.h>  
                                #include <DHT.h>  
                                
                                //ställ in varje gång!=========================
                                #define SketchName "Sovrum Uppe"
                                #define SketchVer "1.0"
                                #define NodeID 2
                                #define VBAT_PER_BITS 0.003363075  // Calculated volts per bit from the used battery montoring voltage divider.   Internal_ref=1.1V, res=10bit=2^10-1=1023, Eg for 3V (2AA): Vin/Vb=R1/(R1+R2)=470e3/(1e6+470e3),  Vlim=Vb/Vin*1.1=3.44V, Volts per bit = Vlim/1023= 0.003363075
                                #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
                                #define VMAX 3.3  //  " " " high level. Vmin<Vmax<=3.44
                                #define CHILD_ID_HUM 0
                                #define CHILD_ID_TEMP 1
                                #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                                int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                unsigned long SLEEP_TIME = 15*60000;
                                //unsigned long SLEEP_TIME = 5000; //debug
                                //Ställ även in gw.begin(,,,)
                                //ställ in varje gång!=========================
                                
                                float lastTemp;
                                float lastHum;
                                boolean metric = true; 
                                int batteryPcnt = 0;
                                int batLoop = 0;
                                int batArray[3];
                                
                                MySensor gw;
                                DHT dht;
                                
                                MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                
                                void setup()  
                                { 
                                // use the 1.1 V internal reference
                                  analogReference(INTERNAL);
                                  delay(500); // Allow time for radio if power used as reset <<<<<<<<<<<<<< Experimented with good result 
                                   
                                  gw.begin(NULL, NodeID, false);
                                //incomingMessageCallback - Callback function for incoming messages from other nodes or controller and request responses. Default is NULL.
                                //nodeId - The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller.
                                //repeaterMode - Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false
                                  
                                  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                
                                  // Send the Sketch Version Information to the Gateway
                                  gw.sendSketchInfo(SketchName, SketchVer);
                                
                                  // 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);
                                  
                                  metric = gw.getConfig().isMetric;
                                }
                                
                                void loop()      
                                {  
                                  int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
                                delay(1000);
                                  delay(dht.getMinimumSamplingPeriod());
                                
                                 
                                  float temperature = dht.getTemperature();
                                  Serial.print("Temp: "); Serial.print(temperature); Serial.println(" C");
                                  
                                 if (temperature > 0) {
                                   gw.send(msgTemp.set(temperature, 1));
                                  }
                                 
                                delay(1000);
                                 
                                  float humidity = dht.getHumidity();
                                  Serial.print("Hum: "); Serial.print(humidity); Serial.println(" %");
                                   
                                   if (humidity > 0) {
                                    gw.send(msgHum.set(humidity, 1));
                                }
                                
                                delay(1000);
                                   
                                   float Vbat  = sensorValue * VBAT_PER_BITS;
                                   int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
                                 Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
                                   batArray[batLoop] = batteryPcnt;
                                  
                                   if (batLoop > 2) {
                                     
                                     batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
                                     batteryPcnt = batteryPcnt / 4;
                                    Serial.print("Battery percent (Avg (4):) "); Serial.print(batteryPcnt); Serial.println(" %");
                                
                                       gw.sendBatteryLevel(batteryPcnt);
                                       batLoop = 0;   
                                     }
                                     else 
                                     {
                                     batLoop = batLoop + 1;
                                     }
                                   
                                  gw.sleep(SLEEP_TIME); //sleep a bit
                                }
                                

                                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

                                m26872M 1 Reply Last reply
                                0
                                • SweebeeS Sweebee

                                  A tip for much better batterylife: burn a new bootloader for 1mhz. Now you can attach the arduino and nrf directly to the batteries and you can measure the battery with the Internal voltage meter of the 328p. If you use a dht you attach the step-up conv. And only attach the dht to it.

                                  m26872M Offline
                                  m26872M Offline
                                  m26872
                                  Hardware Contributor
                                  wrote on last edited by
                                  #44

                                  @Sweebee
                                  It's already been discussed earlier in this thread (see EasyIoTs posts above), it's nevertheless a very good tip. I also have some test nodes running, but I consider it to be the next step from the "basic" design which was this threads concept. If I'll post something with this low-power-tweaked design it'll therefore be in a new thread. I should probably write something about this as an update in the first post...

                                  1 Reply Last reply
                                  0
                                  • sundberg84S sundberg84

                                    @m26872
                                    Pretty much the same, i have stolen majority of your code:
                                    Ive a array to get an average battery value each hour:

                                    #include <SPI.h>
                                    #include <MySensor.h>  
                                    #include <DHT.h>  
                                    
                                    //ställ in varje gång!=========================
                                    #define SketchName "Sovrum Uppe"
                                    #define SketchVer "1.0"
                                    #define NodeID 2
                                    #define VBAT_PER_BITS 0.003363075  // Calculated volts per bit from the used battery montoring voltage divider.   Internal_ref=1.1V, res=10bit=2^10-1=1023, Eg for 3V (2AA): Vin/Vb=R1/(R1+R2)=470e3/(1e6+470e3),  Vlim=Vb/Vin*1.1=3.44V, Volts per bit = Vlim/1023= 0.003363075
                                    #define VMIN 1.9  // Battery monitor lower level. Vmin_radio=1.9V
                                    #define VMAX 3.3  //  " " " high level. Vmin<Vmax<=3.44
                                    #define CHILD_ID_HUM 0
                                    #define CHILD_ID_TEMP 1
                                    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
                                    int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                    unsigned long SLEEP_TIME = 15*60000;
                                    //unsigned long SLEEP_TIME = 5000; //debug
                                    //Ställ även in gw.begin(,,,)
                                    //ställ in varje gång!=========================
                                    
                                    float lastTemp;
                                    float lastHum;
                                    boolean metric = true; 
                                    int batteryPcnt = 0;
                                    int batLoop = 0;
                                    int batArray[3];
                                    
                                    MySensor gw;
                                    DHT dht;
                                    
                                    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
                                    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
                                    
                                    void setup()  
                                    { 
                                    // use the 1.1 V internal reference
                                      analogReference(INTERNAL);
                                      delay(500); // Allow time for radio if power used as reset <<<<<<<<<<<<<< Experimented with good result 
                                       
                                      gw.begin(NULL, NodeID, false);
                                    //incomingMessageCallback - Callback function for incoming messages from other nodes or controller and request responses. Default is NULL.
                                    //nodeId - The unique id (1-254) for this sensor. Default is AUTO(255) which means sensor tries to fetch an id from controller.
                                    //repeaterMode - Activate repeater mode. This node will forward messages to other nodes in the radio network. Make sure to call process() regularly. Default in false
                                      
                                      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
                                    
                                      // Send the Sketch Version Information to the Gateway
                                      gw.sendSketchInfo(SketchName, SketchVer);
                                    
                                      // 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);
                                      
                                      metric = gw.getConfig().isMetric;
                                    }
                                    
                                    void loop()      
                                    {  
                                      int sensorValue = analogRead(BATTERY_SENSE_PIN);    // Battery monitoring reading
                                    delay(1000);
                                      delay(dht.getMinimumSamplingPeriod());
                                    
                                     
                                      float temperature = dht.getTemperature();
                                      Serial.print("Temp: "); Serial.print(temperature); Serial.println(" C");
                                      
                                     if (temperature > 0) {
                                       gw.send(msgTemp.set(temperature, 1));
                                      }
                                     
                                    delay(1000);
                                     
                                      float humidity = dht.getHumidity();
                                      Serial.print("Hum: "); Serial.print(humidity); Serial.println(" %");
                                       
                                       if (humidity > 0) {
                                        gw.send(msgHum.set(humidity, 1));
                                    }
                                    
                                    delay(1000);
                                       
                                       float Vbat  = sensorValue * VBAT_PER_BITS;
                                       int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);   
                                     Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");  
                                       batArray[batLoop] = batteryPcnt;
                                      
                                       if (batLoop > 2) {
                                         
                                         batteryPcnt = (batArray[0] + batArray[1] + batArray[2] + batArray[3]);
                                         batteryPcnt = batteryPcnt / 4;
                                        Serial.print("Battery percent (Avg (4):) "); Serial.print(batteryPcnt); Serial.println(" %");
                                    
                                           gw.sendBatteryLevel(batteryPcnt);
                                           batLoop = 0;   
                                         }
                                         else 
                                         {
                                         batLoop = batLoop + 1;
                                         }
                                       
                                      gw.sleep(SLEEP_TIME); //sleep a bit
                                    }
                                    
                                    m26872M Offline
                                    m26872M Offline
                                    m26872
                                    Hardware Contributor
                                    wrote on last edited by
                                    #45

                                    @sundberg84
                                    I'm no code expert, and the only thing I can think of is that your "delay(1000)" will keep the power hungry radio awake. If you need delays (apart from debug) I'd prefer sleep instead. What's your battery life time look like?

                                    1 Reply Last reply
                                    0
                                    • m26872M Offline
                                      m26872M Offline
                                      m26872
                                      Hardware Contributor
                                      wrote on last edited by m26872
                                      #46

                                      UPDATE
                                      I've updated the first post with

                                      • A wiring layout.
                                      • Added a text about the low-power option
                                      • A few minor details.
                                      1 Reply Last reply
                                      2
                                      • sundberg84S Offline
                                        sundberg84S Offline
                                        sundberg84
                                        Hardware Contributor
                                        wrote on last edited by
                                        #47

                                        Great layout/way to show your project - really nice!

                                        Its exactly as I do it so im getting a bit jealus here... . One node is down after a week.
                                        It might be the hardware or me not so good soldering so i short something out.

                                        I will try some more nodes now you have comfirmed I do it the right way and that should work.

                                        @m26872
                                        Thank you!

                                        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

                                        m26872M 1 Reply Last reply
                                        0
                                        • sundberg84S sundberg84

                                          Great layout/way to show your project - really nice!

                                          Its exactly as I do it so im getting a bit jealus here... . One node is down after a week.
                                          It might be the hardware or me not so good soldering so i short something out.

                                          I will try some more nodes now you have comfirmed I do it the right way and that should work.

                                          @m26872
                                          Thank you!

                                          m26872M Offline
                                          m26872M Offline
                                          m26872
                                          Hardware Contributor
                                          wrote on last edited by
                                          #48

                                          @sundberg84
                                          Thx, good you liked it.
                                          With such fast battery drain it should be easier to trace the current draw. First you'll need to measure the current. Second option is of course the good old switch-and-replace troubleshooting method.
                                          I've read about hardware and quality issues, but let's hope it isn't...

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


                                          19

                                          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