Unknown battery drain



  • Hey all,
    ive created a new mysensor node base on the arduino pro mini 5v.
    Removed both led's to preserver battery voltage.
    The arduino code wakes up every 1/2 hour to read 3 values from 2x Dallas sensor and one water sensor.
    all three sensors run on 5 volt, which is controlled by a transistor and only puts 5 volt on the sensors during the reading time.
    This should create a battery proof node, but it drains a 9 Volt battery in about 3 days.
    total hardware used:
    1 x bc547b to switch the 5 volt on/off to the sensors
    1x le33 to give 3.3 volts for the NRF24L01+
    1x l7805cv to give 5 volts to the arduino
    1x NRF24L01+
    1x Funduino analog water sensor
    2x Dallas temp sensor
    2x 1 M Ohm resistors for battery level
    1x resistor for Dallas sensor

    code:

    #define MY_RADIO_NRF24
    #define MY_NODE_ID 8
    
    #define CHILD_ID_TEMPWATER 0
    #define CHILD_ID_TEMPAIR 1
    
    #define ONE_WIRE_BUS 5
    
    
    #include <MyConfig.h>
    #include <MySensors.h>
    #include <OneWire.h> 
    #include <DallasTemperature.h>
    
    
    OneWire oneWire(5); 
    DallasTemperature sensors(&oneWire);
    
    
    MyMessage msgTEMPWATER(CHILD_ID_TEMPWATER, V_TEMP);
    MyMessage msgTEMPAIR(CHILD_ID_TEMPAIR, V_TEMP);
    // Gen Vars:
    static int powerPin = 2;
    static int batteryPin = A1;
    static int batteryVoltage = 8.78;
    double currentVoltage =0;
    
    // A1 read should be 5v 1024, so the  reading should be 4.39 so 1024 / 5v is 0.0048828125 v per step
    double voltageStep = (batteryVoltage/2.0)/1023;
    int batteryPcnt =0;
    
    // WaterHeight Vars:
    static int waterHeigthPin = A0; 
    int waterHeigthVal = 0;
    int prevWaterHeightVal =0;
    
    // Temp Vars:
    float waterTemp=0;
    float outsideTemp=0;
    int tempProbes =0;
    
    //voltage
    
    #define NUM_SAMPLES 10
    
    
    void setup() {
    Serial.println(" Welcome" );
    Serial.print("Voltage Step");
    Serial.println(voltageStep,8);
    }
    
    void presentation()
    {
    // Send the sketch version information to the gateway
    Serial.println("Presentation SensorNode Vijver");
     sendSketchInfo("vijver", "0.5");
     present(CHILD_ID_TEMPAIR, S_TEMP);
      delay(500);
     present(CHILD_ID_TEMPWATER, S_TEMP);  
     
     Serial.println("## Presentation Done # ");
     delay(1000);
    }
    void measurewater() {
     waterHeigthVal = analogRead(waterHeigthPin);     // read the input pin
     Serial.print("##WaterHeight Value: ");
     Serial.println(waterHeigthVal);      
    }
    
    void taketemp(){
    
         Serial.println( "## Talking to Dallas Sensor:, discarding first reading");
         sensors.requestTemperatures(); // Send the command to get temperature readings 
         delay(750);
         waterTemp=sensors.getTempCByIndex(1);
         outsideTemp=sensors.getTempCByIndex(0);
         
         tempProbes =tempProbes +1;   
         while (((waterTemp < -20 || waterTemp > 70) || (outsideTemp < -20 || outsideTemp > 70)) && tempProbes <5) {
           Serial.print( "## Error received water:");
           Serial.print( waterTemp);
           Serial.print(" outside:");
           Serial.println(outsideTemp);
           delay(1250);
           sensors.requestTemperatures(); // Send the command to get temperature readings 
           waterTemp=sensors.getTempCByIndex(0);
           outsideTemp=sensors.getTempCByIndex(1);
           tempProbes =tempProbes +1; 
         }
         Serial.print( "## WaterTemp:");
         Serial.print( waterTemp);
         Serial.print( "C, "); 
         Serial.print( "outside: ");
         Serial.print( outsideTemp);
         Serial.print( ",Probes needed:");
         Serial.println(tempProbes);     
         tempProbes = 0; 
    }
    void batterycheck() {
     
     currentVoltage = ((analogRead(batteryPin)*voltageStep))*2;     // read the input pin
     currentVoltage = ((analogRead(batteryPin)*voltageStep))*2; 
     Serial.print("##Battery Value: ");
     Serial.print(currentVoltage);
     Serial.println("Volt");
     batteryPcnt=((currentVoltage/batteryVoltage)*100);
     
    }
    void loop() {
    // power up the sensors:
    digitalWrite(powerPin, HIGH);
    delay (1000);
     measurewater();
     taketemp();
     batterycheck();
     delay (1000);
     // send values;
      send(msgTEMPWATER.set(waterTemp,2));
        delay(500);
      send(msgTEMPAIR.set(outsideTemp,2));
         delay(1000);
      sendBatteryLevel(batteryPcnt);
    digitalWrite(powerPin, LOW);
     
     sleep((30*60000));
    }
    
    

  • Mod

    @richard-van-der-plas according to the datasheet, quiescent current for l7805cv is 4.3 to 6mA. A typical 9V battery has 550 mAh capacity so it would be drained by the l7805cv only in about 4 days.

    Then add the drain from the other components and 3 days seems quite reasonable.

    See https://www.mysensors.org/build/battery for recommendations on building battery-powered nodes.



  • Yes used that guide also, but how do i get the 9 volts down to 5 then ? should i just use the RAW input of the pro mini (havent removed that regulator)


  • Mod

    @richard-van-der-plas as the guide says: remove the regulator and give power from 2xAA (or similar) on the Vcc pin.



  • 2XAA gives 2.9 volts with rechargable batteries, that is not enough to power the 5v pro mini ?


  • Mod

    @richard-van-der-plas no that will not be enough. As the guide says, use the 3.3V version.



  • @richard-van-der-plas
    get yourself a boost converter. Something like this:

    DC-DC 0.9V -> 5V
    I remove the USB connector, disable the LED's and it increases the battery voltage to 5VDC.You need an extra cap on the 5VDC output as it will otherwise compromise the working of the nrf24L01+.

    I use 5V pro-mini's as well on batteries and my NiMH batteries last at least one month, doing a somewhat similar thing as what you have in mind.
    I have to power a pressure sensor which is used to monitor the ground-water level around my house. This sensor takes slightly less power than your water sensor.

    I do agree with @mfalkvidd a 3.3V pro-mini would be better for this as you do not have to get the 5VDC down to 3.3VDC for the nrf24L01+, but the 5V version is the next best option in my opinion.


  • Mod

    Maybe you could burn an 8Mhz bootloader and use the batteries


  • Hardware Contributor

    @gohan said in Unknown battery drain:

    Maybe you could burn an 8Mhz bootloader and use the batteries

    Yes you can burn a bootloader using internal oscillator then you can run at 8 or even 1MHz, and so at a much lower voltage and 2 AA/AAA will be enough.
    Next step is to use I2C sensors that can also run at low voltage, and you're good for years of battery life 🙂



  • Gonna try something else first, got 12 V AC running through the garden wich turns on every night for a few hours, Gonna recitfy that and convert to 5 V, than use a NimH powerbank as a in between station to power the Arduino.
    That should give me enough juice for the day, as i can skip the l7805cv



  • @richard-van-der-plas

    You'd still need the 7805 after the rectifier...



  • @boozz yeah but thats only drawing charge when the garden lights are on and charging the PowerBank, the powerbank itself runs the arduino @ 5 volt


  • Mod

    If I were you I'd go for the 3.3V arduino and a solar charger



  • @gohan thought of that to, but havent got any 3.3 laying around.
    The seem more expensive than the 5v though ;(
    the most are the atmega 168 with to little memory


  • Mod

    you can get them at 1.5€ each on aliexpress or even cheaper if you get a 10pcs bundle


  • Admin

    as others have said already, go for the 3v3 nanos, a 5V nano can be converted to 3v3, by setting the fuses (with an avr-isp programmer), so it runs on the internal 8Mhz rc oscillator.

    My Sensebender Micros (basically stripped down nano's) have been running 2.5 years now, with the same set of 2xAA batteries (have 5 running now, one of them even with an extra BMP280 for measuring barometric pressure). All of them measure temperature / humidity every minute, but only transmit when a change is detected.



  • @Richard-van-der-Plas - you can use any Arduino Mini or Mini Pro for a battery powered sensor.
    It does not matter much if you buy a 5V or a 3V3 Mini Pro version as you will better flash an internal 8MHz bootloader, remove the linear voltage regulator on these boards and the LED or LEDs as well. I use battery powered temperature sensors (with thermistors)since November 2017 and they still work fine -> I use 2xR6 batteries. Things you can do (like I did, after lots of reading on this forum):

    • important! remove the LDO (the low drop output voltage regulator) equipped on the Arduinos
    • remove the LED or LEDs
    • flash an 8MHz internal oscillator bootloader (I read in this forum that using 1MHz internal osc. may give you occasional faults, don't know if that is still valid!) - do you know how to do that?
    • internal 8MHz could be precise enough to work with your Dallas temperature sensors, I'm not sure without checking the datasheet
    • an 8MHz Arduino (ATMega328P in this case) can work down to about 2V4 according to the datasheet, while the radio works down to 1V9
    • either use 2 x R6 batteries to power both the Arduino and the radio module
    • or use 3 xR6 batteries to power the Arduino BUT (important!) get power for the radio only from two of the R6 batteries or you'll damage it
    • I bought battery powered Christmas lights from LIDL and Kaufland, they had very cheap Christmas lights with both 2 and 3 R6 batteries - so I just use the very convenient battery plastic housing equipped with an ON/OFF switch. Or just look for some R6 or AAA battery holders ...
    • make sure you connect the Ground of both the Arduino and the Radio to the "-" of the battery string
    • NiMH rechargeable batteries have a much higher self discharge rate than alkaline non rechargeable batteries, NiMH would not be a good option to me as I would have to replace them quite often, but may fit your needs:-)
    • ATMega328P can measure its internal 1V1 reference and by doing that you can calculate the battery voltage without a resistor divider that would drain a few more uA, use this library:
      https://forum.mysensors.org/topic/186/new-library-to-read-arduino-vcc-supply-level-without-resistors-for-battery-powered-sensor-nodes-that-do-not-use-a-voltage-regulator-but-connect-directly-to-the-batteries
    • you can use thermistors to measure the temperature as they are very cheap and most important - you can power the thermistor from an Arduino pin by making it an OUTPUT and set it HIGH. After reading the temperature set it back to LOW and put the Arduino to sleep. You will conserve even more power this way. Hope it helps ...
    • forgot to clarify, you are supposed to connect the "+" of the battery string to the 5V pin header on the Arduino (there are 2 such pins I think), not to the RAW pin header. 5V can be anything between 2V4 and 5V (for an 8MHz Arduino) and goes directly to the ATMega VCC pin while RAW connector goes to the input of the Linear Voltage Regulator you are supposed to remove
    • while looking to your code I can see you have many delay() lines which means your Arduino is awake for many seconds, that's just not good enough for a battery powered sensor :-), try to remove these delays as much as possible, use different sensors that do not require delays eventually as the Arduino should be mostly sleeping. Use eventually a #define DEBUG x statement (x=1 if you like to have a serial debug output or x=0 if you don't) and only output the Serial.print when needed.Here is an example for a temperature sensor with a thermistor and 2xR6 batteries (not using here the VCC library I mentioned before but something similar):
    // Enable debug prints to serial monitor
    //#define MY_DEBUG
    
    #define MY_RADIO_NRF24
    #define MY_NODE_ID 10
    #define DEBUG 0
    #define BATTERY_SENSOR 1
    
    #include <MySensors.h>
    
    #define TH1_CHILD_ID 11
    #define VOLTAGE_CHILD_ID 12
    #define TH_PIN 3
    
    int _nominal_resistor = 4700;
    int _nominal_temperature = 25;
    int _b_coefficient = 3950;
    int _series_resistor = 4877;
    int _pin = 0;
    
    float BatteryMin = 2.4;
    float BatteryMax = 3.0;
    
    MyMessage msgTemp(TH1_CHILD_ID, V_TEMP);
    MyMessage msgVoltage(VOLTAGE_CHILD_ID, V_VOLTAGE);
    
    void setup()
    {
      //Serial.begin(115200);
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("TH1_Mini_2xR6", "1.0");
      present(TH1_CHILD_ID, S_TEMP, "TH1");
      present(VOLTAGE_CHILD_ID, S_MULTIMETER, "TH1_Batt_Voltage");
    }
    
    void loop()
    {
      tempReport();
      batteryReport();
      sleep(180000);
    }
    
    // Measure VCC
    float getVcc() {
    #ifndef MY_GATEWAY_ESP8266
      // Measure Vcc against 1.1V Vref
    #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
      ADMUX = (_BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
    #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
      ADMUX = (_BV(MUX5) | _BV(MUX0));
    #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
      ADMUX = (_BV(MUX3) | _BV(MUX2));
    #else
      ADMUX = (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1));
    #endif
      // Vref settle
      wait(70);
      // Do conversion
      ADCSRA |= _BV(ADSC);
      while (bit_is_set(ADCSRA, ADSC)) {};
      // return Vcc in mV
      return (float)((1125300UL) / ADC) / 1000;
    #else
      return (float)0;
    #endif
    }
    
    // Send a battery level report to the controller
    void batteryReport() {
      // measure the board vcc
      float volt = getVcc();
      // calculate the percentage
      int percentage = ((volt - BatteryMin) / (BatteryMax - BatteryMin)) * 100;
      if (percentage > 100) percentage = 100;
      if (percentage < 0) percentage = 0;
    #if DEBUG == 1
      Serial.print(F("BATT V="));
      Serial.print(volt);
      Serial.print(F(" P="));
      Serial.println(percentage);
    #endif
    #if BATTERY_SENSOR == 1
      // report battery voltage
      send(msgVoltage.set(volt, 3));
    #endif
      // report battery level percentage
      sendBatteryLevel(percentage);
    }
    
    void tempReport()
    {
      // set TH pin in output mode
      pinMode(TH_PIN, OUTPUT);
      // set TH_PIN HIGH
      digitalWrite(TH_PIN, HIGH);
      wait(1);
      // read the voltage across the thermistor
      float adc = analogRead(_pin);
      // set TH_PIN LOW
      digitalWrite(TH_PIN, LOW);
      // calculate the temperature
      float reading = (1023 / adc)  - 1;
      reading = _series_resistor / reading;
      float temperature;
      temperature = reading / _nominal_resistor;     // (R/Ro)
      temperature = log(temperature);                  // ln(R/Ro)
      temperature /= _b_coefficient;                   // 1/B * ln(R/Ro)
      temperature += 1.0 / (_nominal_temperature + 273.15); // + (1/To)
      temperature = 1.0 / temperature;                 // Invert
      temperature -= 273.15;                         // convert to C
    #if DEBUG == 1
      Serial.print(F("THER I="));
      Serial.print(TH1_CHILD_ID);
      Serial.print(F(" V="));
      Serial.print(adc);
      Serial.print(F(" T="));
      Serial.println(temperature);
    #endif
      send(msgTemp.set(temperature, 1));
    }```


  • @tbowmo wow 2.5 years !! Which bootloader are you using for your sleeping node ? It is Sensebender or did you modify it ?


  • Admin

    @ahmedadelhosni

    It's the standard dualoptiboot, that we ship with the sensebender micro. But the bootloader is not essential in this context. What is essential, is how often you power up your radio etc. for transmitting.

    My sketch for the sensors is more or less like the standard Sensebender Micro sketch that we have on github, which wakes up the mcu once every minute, takes a measurement and compare to the value last sent to the gateway. If the deviation is greater than X then transmit the new value. Otherwise, just go to sleep for 1 more minute.

    Every half hour or so, I do a forced transmit of the measurement values. This to make sure it will report back periodically, so the controller get's some data for graphing.



  • @tbowmo Thanks for the info.

    So here I have two questions. How do you power your node/radio ? how much days did it survive till now ?


  • Mod

    @ahmedadelhosni If the node is using 10uA or less when sleeping, you should be expecting a battery life in the year range


  • Admin

    @ahmedadelhosni

    I'm powering my sensebenders (5 pcs) with 2xAA batteries, and they have been running for 2.5 years now, without changing batteries.

    I think that this is a pretty decent battery life for a sensor 🙂



  • Thanks all.

    Actually @tbowmo i was asking about bootloader because I have opened another thread reagrding a problem where my node stops working sometimes when i use 1 Mhz. So i was asking what would it be the problem ? And what booloader + power supply technique do people use.



  • @tbowmo are they alkaline or lithuim ?


  • Mod

    I use alkaline. Easy to buy and cheap.


  • Admin

    @ahmedadelhosni

    Alkaline, cheap "IKEA" batteries.. 🙂

    My units reports around 60% battery capacity left (very unscientifically measurements)

    About operating frequency. If you have a sleeping node, then you won't gain anything from using 1Mhz versus 8Mhz, on the contrary you might end up using more power, when using 1Mhz, than 8Mhz. Because the time that the MCU is awake is longer at 1Mhz, than at 8Mhz. Remember, that when the MCU is sleeping, the power usage is the same, regardless of what frequency the MCU is working at, because the oscillator is shut down.

    at 8Mhz you would complete your operation quicker, and return to sleep mode again faster, than when running at 1Mhz.


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 6
  • 2
  • 1
  • 6

55
Online

11.4k
Users

11.1k
Topics

112.6k
Posts