Battery level don't show up

  • Hello all,

    I encounter an issue with my battery powered sensor.
    It's based on an arduino pro mini 3,3 V, a DHT 22 and powered via a LiPo 3,7V battery.

    It runs on a Vera 3 with the 1.4 library.

    After inclusion, my vera see 1 node, 1 humidity sensor and 1 temperature sensor. The temperature and humidity are working fine, The problem is that the battery level don't show up 😞
    On th serial connection i can see my battery level.

    Here is my code:

    #include <SPI.h>
    #include <MySensor.h>
    #include <DHT.h>

    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    unsigned long SLEEP_TIME = 300000; // Sleep time between reads (in milliseconds)
    int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point

    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    int oldBatteryPcnt = 0;

    void setup()

    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("Humidity", "1.0");
    gw.sendSketchInfo("Battery Meter", "1.0");

    // 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()

    float temperature = dht.getTemperature();
    if (isnan(temperature)) {
    Serial.println("Failed reading temperature from DHT");
    } else if (temperature != lastTemp) {
    lastTemp = temperature;
    if (!metric) {
    temperature = dht.toFahrenheit(temperature);
    gw.send(msgTemp.set(temperature, 1));
    Serial.print("T: ");

    float humidity = dht.getHumidity();
    if (isnan(humidity)) {
    Serial.println("Failed reading humidity from DHT");
    } else if (humidity != lastHum) {
    lastHum = humidity;
    gw.send(msgHum.set(humidity, 1));
    Serial.print("H: ");

    // get the battery Voltage
    int sensorValue = analogRead(BATTERY_SENSE_PIN);

    // 1M, 470K divider across battery and using internal ADC ref of 1.1V
    // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
    // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
    // 3.44/1023 = Volts per bit = 0.003363075
    float batteryV = sensorValue * 0.0041;
    int batteryPcnt = sensorValue / 10;

    Serial.print("Input Value: ");

    Serial.print("Battery Voltage: ");
    Serial.println(" V");

    Serial.print("Battery percent: ");
    Serial.println(" %");

    if (oldBatteryPcnt != batteryPcnt) {
    // Power up radio after sleep
    oldBatteryPcnt = batteryPcnt;

    gw.sleep(SLEEP_TIME); //sleep a bit


  • Hero Member

    @cheesepower I've notice that sometimes it take a while for the indicator to show up in Vera.

  • My sensor runs for 2 weeks now.

    One more question : where did the battery level is supposed to be ? on the node under a variable or elsewhere ?

  • Hero Member

    Looks like this.....

    Screen Shot 12-11-14 at 02.02 PM.PNG

  • Hardware Contributor

    I assume you've done extensive resets, reloads, reboots of sensor, vera, luup, and gateway in all diffent ways?
    And a little dare to use custom device names before you get it going if you ask me.
    And yes, the battery level as a number is also visible under variables after first receive..

  • Hero Member

    @cheesepower as @m26872 suggested, you should try a power cycle your equipment.. if that doesn't work...... you have a problem. I can't see any issue in the sketch.

  • Yes i made several reset, exclusions, inclusions, vera reset and clear EPROM but nothing worked...

    I made a new sensor and it works perfectly

    Strange... I will try again when i will have more time.

    Thanks for the help 😄

Suggested Topics