Rain node suddenly draw much power



  • It has been running for 1-2 weeks, last week without that I have touched/open it.
    This is how the voltage look like. Send data every 3 hour or until it get a signal from tiping bucket.
    0_1456062312248_image.png

    This is from other sensor sending data every 30 minutes
    0_1456062786023_image.png

    Both have LiPo battery.

    #include <SPI.h>
    #include <MySensor.h> 
    
    // Running this in Domoticz stable version 2.5 will not work - upgrade to beta.
    
    #define DIGITAL_INPUT_SENSOR 3 // The reed switch you attached. (Only 2 and 3 generates interrupt!)
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    
    #define CHILD_ID 1 // Id of the sensor child
    #define BATT_CHILD 2
    #define NODE_ID 24 // or AUTO to let controller assign
    #define SKETCH_NAME "Rain Gauge" // Change to a fancy name you like
    #define SKETCH_VERSION "1.8" // Your version
    
    unsigned long SLEEP_TIME = 180*60000; // Sleep time (in milliseconds).
    //unsigned long SLEEP_TIME = 20000; // use this instead for debug
    
    float hwRainVolume = 0; // Current rainvolume calculated in hardware.
    int hwPulseCounter = 0; // Pulsecount recieved from GW
    float fullCounter = 0; // Counts when to send counter
    float bucketSize = 0.5; // Bucketsize mm, needs to be 1, 0.5, 0.25, 0.2 or 0.1
    boolean pcReceived = false; // If we have recieved the pulscount from GW or not 
    boolean reedState; // Current state the reedswitch is in
    boolean oldReedState; // Old state (last state) of the reedswitch
    unsigned long lastSend =0; // Time we last tried to fetch counter.
    
    MySensor gw;
    MyMessage volumeMsg(CHILD_ID,V_RAIN);
    MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
    MyMessage battMsg(BATT_CHILD, V_VOLTAGE);
    
    //=========================
    // BATTERY VOLTAGE DIVIDER SETUP
    // 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 // Vmin (radio Min Volt)=1.9V (564v)
    #define VMAX 3.0 // Vmax = (2xAA bat)=3.0V (892v)
    int batteryPcnt = 0; // Calc value for battery %
    int batLoop = 0; // Loop to help calc average
    int batArray[3]; // Array to store value for average calc.
    int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
    //=========================
    */
    
    long result;
    float batteryPcnt;
    float batteryVolt;
    
    void setup() 
    { 
    pinMode(6,OUTPUT);
    digitalWrite(6,HIGH);
    // use the 1.1 V internal reference
    //analogReference(INTERNAL); // For battery sensing
    
    pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP); // sets the reed sensor digital pin as input
    
    reedState = digitalRead(DIGITAL_INPUT_SENSOR); // Read what state the reedswitch is in
    oldReedState = reedState; // Set startup position for reedswitch
    
    delay(500); // Allow time for radio if power used as reset
    
    //Begin (Change if you dont want static node_id! (NODE_ID to AUTO)
    gw.begin(incomingMessage, NODE_ID, false);
    
    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
    
    // Register this device as Rain sensor (will not show in Domoticz until first value arrives)
    gw.present(CHILD_ID, S_RAIN); 
    gw.present(BATT_CHILD, S_MULTIMETER);
    
    Serial.println("Startup completed");
    }
    
    void loop() 
    { 
    
    digitalWrite(6,HIGH);
    delay(100);
    
    gw.process();
    //gw.begin(incomingMessage, NODE_ID, false);
    unsigned long currentTime = millis();
    
    //See if we have the counter/pulse from Domoticz - and ask for it if we dont.
    if (!pcReceived && (currentTime - lastSend > 5000)) { 
    gw.begin(incomingMessage, NODE_ID, false);
    gw.request(CHILD_ID, V_VAR1);
    Serial.println("Request pulsecount");
    lastSend=currentTime;
    gw.process();
    return;
    }
    if (!pcReceived) {
    return;
    }
    
    //Read if the bucket tipped over
    reedState = digitalRead(DIGITAL_INPUT_SENSOR);
    boolean tipped = oldReedState != reedState; 
    
    //BUCKET TIPS!
    if (tipped==true) {
    gw.begin(incomingMessage, NODE_ID, false);
    Serial.println("The bucket has tipped over...");
    oldReedState = reedState;
    hwRainVolume = hwRainVolume + bucketSize;
    gw.send(volumeMsg.set((float)hwRainVolume,1));
    gw.wait(1000);
    fullCounter = fullCounter + bucketSize;
    
    //Count so we send the counter for every 1mm
    if(fullCounter >= 1){
    hwPulseCounter++;
    gw.send(lastCounterMsg.set(hwPulseCounter));
    gw.wait(1000);
    fullCounter = 0;
    }
    readVcc(); 
    }
    
    if (tipped==false) {
    
    //No bucket tipped over last sleep-period, check battery then...
    readVcc(); 
    }
    
    lastSend=currentTime;
    Serial.println("sleep");
    digitalWrite(6,LOW);
    delay(1000);
    gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME); 
    //The interupt can be CHANGE or FALLING depending on how you wired the hardware.
    }
    
    
    
    
    
    
    //Read if we have a incoming message.
    void incomingMessage(const MyMessage &message) {
    if (message.type==V_VAR1) {
    hwPulseCounter = message.getULong();
    hwRainVolume = hwPulseCounter;
    pcReceived = true;
    Serial.print("Received last pulse count from gw: ");
    Serial.println(hwPulseCounter); 
    }
    }
    /*
    void batM() //The battery calculations
    {
    delay(500);
    // Battery monitoring reading
    int sensorValue = analogRead(BATTERY_SENSE_PIN); 
    delay(500);
    
    // Calculate the battery in %
    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(" %"); 
    
    // Add it to array so we get an average of 3 (3x20min)
    batArray[batLoop] = batteryPcnt;
    
    if (batLoop > 1) { 
    batteryPcnt = (batArray[0] + batArray[1] + batArray[2]);
    batteryPcnt = batteryPcnt / 3;
    
    if (batteryPcnt > 100) {
    batteryPcnt=100;
    }
    
    Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
    gw.sendBatteryLevel(batteryPcnt);
    batLoop = 0;
    
    //Sends 1 per hour as a heartbeat.
    gw.send(volumeMsg.set((float)hwRainVolume,1));
    gw.send(lastCounterMsg.set(hwPulseCounter));
    }
    else 
    {
    batLoop++;
    }
    }
    */
    long readVcc() {
    Serial.println("readVcc");
    // Read 1.1V reference against AVcc
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
    delay(2); // Wait for Vref to settle
    ADCSRA |= _BV(ADSC); // Convert
    while (bit_is_set(ADCSRA,ADSC));
    result = ADCL;
    result |= ADCH<<8;
    result = 1126400L / result; // Back-calculate AVcc in mV
    //return result;
    gw.begin(incomingMessage, NODE_ID, false);
    batteryPcnt = (result - 3300) * 0.111111;
    batteryVolt = result/1000.000;
    gw.sendBatteryLevel(batteryPcnt);
    gw.send(battMsg.set(batteryVolt, 3));
    /*Serial.print("battery volt:");
    Serial.println(batteryVolt, 3);
    Serial.print("battery percent:");
    Serial.println(batteryPcnt);
    */
    }
    

  • Hardware Contributor

    Im using a reed switch with a external pullup and experience the same thing. My modified code (I t looks its what you are using) checks for a change so sometimes its high and sometimes its low. I get a feeling that it draws more power when its one of the states, and if there is not rain...

    You also use internal ref to measure bat, im using a voltage divider.

    I have bought myself a good multimeter for my upcoming birthday 🙂 and will check that theory then but will follow this thread with interest.



  • @sundberg84
    It can be more power when reed switch passes magnet but that is only for a few milliseconds. It has actual been raining more the last days.

    I don't use external pull-up maybe internal pull-up, I just copied the code 🙂


  • Hero Member

    @flopp I'm kind of confused by the code for the rain sensor. Why is it calling "gw.begin(..)" and "return" in the main loop? At first glance my expectation is that the node stays awake when the communication with the controller is lost.. I would expect that the node remembers its own state in EEPROM when needed.



  • @AWI
    Great that you noticed that, I forgot to write that I have a LDO ~5V->3.3V which I start up and shutdown with Digital pin 6.

    If I don't use gw.begin in each "session?" it seems to not be able to communicate with gateway. I power it off totally with pin 6.
    Maybe LDO is hanged in power ON? I have not done anything with it, I mean not restart, moved it etc. since 16/2 but suddenly it starts to drop quickly since 19/2, see picture above.


  • Hero Member

    @flopp Radio communication errors can have multiple causes.. relying/ waiting on a response from a controller is never a good idea (imo). The consumption of the radio is almost nothing while asleep. Using a low consumption LDO (i.e. 662k) eliminates any need for powering it down.



  • @AWI said:

    @flopp relying/ waiting on a response from a controller is never a good idea (imo).

    I don't understand please explain. If I don't get any answer from controller(Domoticz) then I will not get any data in controller, or?

    The consumption of the radio is almost nothing while asleep. Using a low consumption LDO (i.e. 662k) eliminates any need for powering it down.

    One week ago I heard about 662k for my first time, I will use that and have ordered them so I will change it as soon as they arrive


  • Hero Member

    @flopp I did not completely analyse you sketch but it seems to request data from the gateway/ controller and stays awake while waiting for it.



  • @AWI
    I think I will let this problem be for now and change the LDO to 662k and not use digital pin to power on/off



  • I already had a problem with a nrf24L01 which suddenly started to consume a lot, but works right. Try with a new one ?



  • @flylowgofast
    I measured how much the NRF draw, it was ~0,8mA.
    After change I was not able to measure the current because it was to low.
    I didn't reset he arduino during this test and change.

    I will recharge the battery and start over again.

    Thanks everyone


Log in to reply
 

Suggested Topics

  • 8
  • 2
  • 1
  • 3
  • 2
  • 29

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts