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. coin-cell (CR2032) powered temperature sensor

coin-cell (CR2032) powered temperature sensor

Scheduled Pinned Locked Moved My Project
39 Posts 10 Posters 23.1k Views 18 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.
  • Moebius LutchingM Offline
    Moebius LutchingM Offline
    Moebius Lutching
    wrote on last edited by
    #28

    There is a TI paper about adding a big capacitor in series with the coin-cell battery to minimize the voltage drop during high-current peaks: http://www.ti.com/lit/wp/swra349/swra349.pdf, also another interesting article related to low-power and CR2032: http://www.low-powerdesign.com/121312-article-extending-battery-life.htm

    1 Reply Last reply
    1
    • F flopp

      @fleinze said:

      I just added an 100uF capacitor to one of my sensors and put an old battery in. Let's see how much more life I can get out of this battery now.

      Very interest work.
      Is it still working?

      F Offline
      F Offline
      fleinze
      wrote on last edited by
      #29

      @flopp I added the capacitor and put the old battery in. By old battery I mean the one I had replaced a week earlier for a new one. Sensor running smooth since, so great success!

      F 1 Reply Last reply
      2
      • F fleinze

        @flopp I added the capacitor and put the old battery in. By old battery I mean the one I had replaced a week earlier for a new one. Sensor running smooth since, so great success!

        F Offline
        F Offline
        flopp
        wrote on last edited by
        #30

        @fleinze
        :thumbsup:

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mihai.aldea
          wrote on last edited by
          #31

          The DS18B20+ is not a great sensor for the battery powered nodes. It has a huge conversion time comparing to others.
          9-bit resolution | 93.75 ms | 0.5°C
          10-bit resolution | 187.5 ms | 0.25°C
          11-bit resolution | 375 ms | 0.125°C
          12-bit resolution | 750 ms | 0.0625°C
          The last column is the sensor's precision. So unless you're OK with a 0.5°C steps, the simple usage of DS18B20+ will kill your battery a lot faster.
          Don't use DHT22, that one is very slow too. BME280 does have a barometric pressure sensor but it's not very fast either.
          The best sensor for battery powered nodes is the the Si7021 which is rather old, but is the fastest.

          1 Reply Last reply
          1
          • F Offline
            F Offline
            fleinze
            wrote on last edited by
            #32

            I put the arduino to sleep during the conversion time, so this is not a big issue. But I agree that the DS18B20 is not the best, but it is widely available. For newer nodes I try to use the Si7021 where possible.

            M T 2 Replies Last reply
            0
            • F fleinze

              I put the arduino to sleep during the conversion time, so this is not a big issue. But I agree that the DS18B20 is not the best, but it is widely available. For newer nodes I try to use the Si7021 where possible.

              M Offline
              M Offline
              mihai.aldea
              wrote on last edited by
              #33

              @fleinze said:

              I put the arduino to sleep during the conversion time, so this is not a big issue. But I agree that the DS18B20 is not the best, but it is widely available. For newer nodes I try to use the Si7021 where possible.

              It goes without saying that the nodes are in sleep mode between reports. However, the conversion time has a great impact in the cycle math. I won't say that pulling the readings 10 times faster will give you 10 times more time on battery but if you'll get 5 times more time then it's something. Not to mention that the Si7021 works down to 1.9V unlike the DS18B20+ which works down to only 3.0V.

              1 Reply Last reply
              0
              • F fleinze

                I put the arduino to sleep during the conversion time, so this is not a big issue. But I agree that the DS18B20 is not the best, but it is widely available. For newer nodes I try to use the Si7021 where possible.

                T Offline
                T Offline
                tango156157
                wrote on last edited by
                #34

                @fleinze Great work with the CR2032 coin cell temp. sensor. I am trying to do a similar exercise with Si7021 sensors but getting into issues while coding. The examples from other posts around Si7021 adapted for latest MySensor lib seem to get stuck in my IDE giving lot of errors. I have tried getting all the required Header files but still get stuck due to some random error. Is it possible for you to share your code based on CR2032 temp node running on Si7021? Thanks....

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mihai.aldea
                  wrote on last edited by
                  #35

                  @tango156157, I sometimes get similar errors while compiling the sketches. Mostly because I am still using the MySensors 1.5 library for my legacy network, 2.1.0b for the RFM69 network (working RSSI report) and 2.1.1 for the LoRa network.
                  Mostly when dealing with MySensors 1.5 and/or older sensors libraries, I find the newer Arduino version to pop all sort of errors. But then I fire up one of the older Arduino IDE versions I have, 1.6.5, 1.6.9 and so on. Eventually one of them compiles the sketch without errors while the newer version don't work. This is far from being a solid solution for these errors, but it gets the job done.
                  You should try that too, especially if you're using older libraries for your sensors.
                  You can find them here: https://www.arduino.cc/en/Main/OldSoftwareReleases#previous

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    fleinze
                    wrote on last edited by
                    #36

                    Hi,

                    this is my code working with 2.1 version. The code is not tidied up, please excuse.

                    /*
                       MySensors-Node for DS18B20 Temperature-Sensors.
                       Mysensors.Library-Version 1.6
                    */
                    
                    #define MY_RADIO_NRF24
                    
                    #define MY_TRANSPORT_UPLINK_CHECK_DISABLED
                    
                    //#define MY_DEBUG
                    
                    
                    #include <MySensors.h>
                    #include <SPI.h>
                    #include <Wire.h>
                    #include <SI7021.h>
                    
                    #define BATT_SENSOR
                    //#define VCCGND_PINS
                    
                    #ifdef VCCGND_PINS
                    const uint8_t GND = A2;
                    const uint8_t VCC = A3;
                    #endif
                    
                    #ifdef BATT_SENSOR
                    #define REPORT_VOLTAGE
                    #endif
                    
                    const unsigned long SLEEP_TIME = 300000; // Sleep time between reads (in milliseconds)
                    
                    const uint8_t TEMP_TIME = 12; //at least every nth time battery is reported
                    const uint8_t HUM_TIME = 12;
                    const uint8_t BATT_TIME = 12; //when also BATT-LEVEL is reportet
                    const float BATT_100 = 3; //3.3V for CR2032, 3V for 2xAA
                    const float BATT_0 = 2.2;
                    
                    SI7021 sensor;
                    
                    float lastTemperature, lastHum;
                    uint8_t lastTempSent = 0;//, lastHumSent = 0;
                    uint8_t numSensors = 0;
                    boolean receivedConfig = false;
                    boolean metric = true;
                    // Initialize temperature message
                    MyMessage msgTemp(0, V_TEMP);
                    MyMessage msgHum(0, V_HUM);
                    #ifdef REPORT_VOLTAGE
                    MyMessage msgBatt(1, V_VOLTAGE);
                    #endif
                    #ifdef BATT_SENSOR
                    uint8_t battReport = BATT_TIME - 1; //First report at startup
                    long oldvalue = 0;
                    #endif
                    
                    
                    void setup()
                    {
                    
                      #ifdef VCCGND_PINS
                      pinMode(VCC, OUTPUT);
                      digitalWrite(VCC, HIGH);
                      pinMode(GND, OUTPUT);
                      digitalWrite(GND, LOW);
                      #endif
                      
                      if (!sensor.begin()) {
                        Serial.println("No Sensor found!");
                        while (true);
                      }
                      
                    
                    }
                    
                    void presentation() {
                    
                      // Send the sketch version information to the gateway and Controller
                      sendSketchInfo("TempHumSi7021", "0.1a");
                    
                      // Present all sensors to controller
                      present(0, S_HUM);
                      //present(1, S_HUM);
                    #ifdef REPORT_VOLTAGE
                      present(1, S_MULTIMETER);
                    #endif
                    }
                    
                    
                    void loop()
                    {
                      //delay(2000);//for sensor to start up
                      boolean tempsent = false;
                    
                      // Fetch temperatures from Dallas sensors
                      si7021_thc temphum = sensor.getTempAndRH();
                    
                      // Read temperatures and send them to controller
                      // Fetch and round temperature to one decimal
                      float temperature = (float)(temphum.celsiusHundredths) / 100.0;
                      float humidity = (float)(temphum.humidityPercent);
                      // Only send data if temperature has changed and no error
                      if ((lastTemperature != temperature) || lastHum != humidity || (++lastTempSent >= TEMP_TIME)) {
                        // Send in the new temperature
                        send(msgTemp.set(temperature, 1));
                        send(msgHum.set(humidity, 1));
                        lastHum = humidity;
                        lastTemperature = temperature;
                        lastTempSent = 0;
                        tempsent = true;
                      }
                    
                    
                    #ifdef BATT_SENSOR
                      if (++battReport >= BATT_TIME && tempsent) {
                    
                        //gw.sleep(10);
                        long value = readVcc();
                    
                    
                        if (value != oldvalue) {
                          int percent = (( (float)(value) / 1000 ) - BATT_0) / (BATT_100 - BATT_0) * 100;
                          percent = (percent > 100) ? 100 : percent;
                          percent = (percent < 0) ? 0 : percent;
                          sendBatteryLevel(percent);
                    #ifdef REPORT_VOLTAGE
                          send(msgBatt.set((float)(value) / 1000, 2));
                    #endif
                        }
                        oldvalue = value;
                        battReport = 0;
                      }
                    #endif
                      sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
                      //delay(2000);//for sensor to start up
                    }
                    
                    long readVcc() {
                      // Read 1.1V reference against AVcc
                      // set the reference to Vcc and the measurement to the internal 1.1V reference
                    #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
                    
                      delay(2); // Wait for Vref to settle
                      ADCSRA |= _BV(ADSC); // Start conversion
                      while (bit_is_set(ADCSRA, ADSC)); // measuring
                    
                      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
                      uint8_t high = ADCH; // unlocks both
                    
                      long result = (high << 8) | low;
                    
                      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
                      return result; // Vcc in millivolts
                    }```
                    T 1 Reply Last reply
                    0
                    • F fleinze

                      Hi,

                      this is my code working with 2.1 version. The code is not tidied up, please excuse.

                      /*
                         MySensors-Node for DS18B20 Temperature-Sensors.
                         Mysensors.Library-Version 1.6
                      */
                      
                      #define MY_RADIO_NRF24
                      
                      #define MY_TRANSPORT_UPLINK_CHECK_DISABLED
                      
                      //#define MY_DEBUG
                      
                      
                      #include <MySensors.h>
                      #include <SPI.h>
                      #include <Wire.h>
                      #include <SI7021.h>
                      
                      #define BATT_SENSOR
                      //#define VCCGND_PINS
                      
                      #ifdef VCCGND_PINS
                      const uint8_t GND = A2;
                      const uint8_t VCC = A3;
                      #endif
                      
                      #ifdef BATT_SENSOR
                      #define REPORT_VOLTAGE
                      #endif
                      
                      const unsigned long SLEEP_TIME = 300000; // Sleep time between reads (in milliseconds)
                      
                      const uint8_t TEMP_TIME = 12; //at least every nth time battery is reported
                      const uint8_t HUM_TIME = 12;
                      const uint8_t BATT_TIME = 12; //when also BATT-LEVEL is reportet
                      const float BATT_100 = 3; //3.3V for CR2032, 3V for 2xAA
                      const float BATT_0 = 2.2;
                      
                      SI7021 sensor;
                      
                      float lastTemperature, lastHum;
                      uint8_t lastTempSent = 0;//, lastHumSent = 0;
                      uint8_t numSensors = 0;
                      boolean receivedConfig = false;
                      boolean metric = true;
                      // Initialize temperature message
                      MyMessage msgTemp(0, V_TEMP);
                      MyMessage msgHum(0, V_HUM);
                      #ifdef REPORT_VOLTAGE
                      MyMessage msgBatt(1, V_VOLTAGE);
                      #endif
                      #ifdef BATT_SENSOR
                      uint8_t battReport = BATT_TIME - 1; //First report at startup
                      long oldvalue = 0;
                      #endif
                      
                      
                      void setup()
                      {
                      
                        #ifdef VCCGND_PINS
                        pinMode(VCC, OUTPUT);
                        digitalWrite(VCC, HIGH);
                        pinMode(GND, OUTPUT);
                        digitalWrite(GND, LOW);
                        #endif
                        
                        if (!sensor.begin()) {
                          Serial.println("No Sensor found!");
                          while (true);
                        }
                        
                      
                      }
                      
                      void presentation() {
                      
                        // Send the sketch version information to the gateway and Controller
                        sendSketchInfo("TempHumSi7021", "0.1a");
                      
                        // Present all sensors to controller
                        present(0, S_HUM);
                        //present(1, S_HUM);
                      #ifdef REPORT_VOLTAGE
                        present(1, S_MULTIMETER);
                      #endif
                      }
                      
                      
                      void loop()
                      {
                        //delay(2000);//for sensor to start up
                        boolean tempsent = false;
                      
                        // Fetch temperatures from Dallas sensors
                        si7021_thc temphum = sensor.getTempAndRH();
                      
                        // Read temperatures and send them to controller
                        // Fetch and round temperature to one decimal
                        float temperature = (float)(temphum.celsiusHundredths) / 100.0;
                        float humidity = (float)(temphum.humidityPercent);
                        // Only send data if temperature has changed and no error
                        if ((lastTemperature != temperature) || lastHum != humidity || (++lastTempSent >= TEMP_TIME)) {
                          // Send in the new temperature
                          send(msgTemp.set(temperature, 1));
                          send(msgHum.set(humidity, 1));
                          lastHum = humidity;
                          lastTemperature = temperature;
                          lastTempSent = 0;
                          tempsent = true;
                        }
                      
                      
                      #ifdef BATT_SENSOR
                        if (++battReport >= BATT_TIME && tempsent) {
                      
                          //gw.sleep(10);
                          long value = readVcc();
                      
                      
                          if (value != oldvalue) {
                            int percent = (( (float)(value) / 1000 ) - BATT_0) / (BATT_100 - BATT_0) * 100;
                            percent = (percent > 100) ? 100 : percent;
                            percent = (percent < 0) ? 0 : percent;
                            sendBatteryLevel(percent);
                      #ifdef REPORT_VOLTAGE
                            send(msgBatt.set((float)(value) / 1000, 2));
                      #endif
                          }
                          oldvalue = value;
                          battReport = 0;
                        }
                      #endif
                        sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
                        //delay(2000);//for sensor to start up
                      }
                      
                      long readVcc() {
                        // Read 1.1V reference against AVcc
                        // set the reference to Vcc and the measurement to the internal 1.1V reference
                      #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
                      
                        delay(2); // Wait for Vref to settle
                        ADCSRA |= _BV(ADSC); // Start conversion
                        while (bit_is_set(ADCSRA, ADSC)); // measuring
                      
                        uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
                        uint8_t high = ADCH; // unlocks both
                      
                        long result = (high << 8) | low;
                      
                        result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
                        return result; // Vcc in millivolts
                      }```
                      T Offline
                      T Offline
                      tango156157
                      wrote on last edited by
                      #37

                      @fleinze thanks for sharing your code for Si7021 sensor. I tried compiling but getting below error. Not sure if I am using incorrect header file for Si7021 sensor. I am using MySensors ver 2.1.0 for compiling. Any view? Thanks

                      C:\Users\abc\AppData\Local\Temp\arduino_modified_sketch_641038\sketch_may14a.ino: In function 'void loop()':
                      
                      sketch_may14a:91: error: 'si7021_thc' was not declared in this scope
                      
                         si7021_thc temphum = sensor.getTempAndRH();
                      
                         ^
                      
                      sketch_may14a:91: error: expected ';' before 'temphum'
                      
                         si7021_thc temphum = sensor.getTempAndRH();
                      
                                    ^
                      
                      sketch_may14a:95: error: 'temphum' was not declared in this scope
                      
                         float temperature = (float)(temphum.celsiusHundredths) / 100.0;
                      
                                                     ^
                      
                      Multiple libraries were found for "SI7021.h"
                       Used: C:\Users\abc\Documents\Arduino\libraries\SI7021
                       Not used: C:\Program Files (x86)\Arduino\libraries\SI7021
                      exit status 1
                      'si7021_thc' was not declared in this scope
                      
                      Insert Code Here
                      
                      F 1 Reply Last reply
                      0
                      • T tango156157

                        @fleinze thanks for sharing your code for Si7021 sensor. I tried compiling but getting below error. Not sure if I am using incorrect header file for Si7021 sensor. I am using MySensors ver 2.1.0 for compiling. Any view? Thanks

                        C:\Users\abc\AppData\Local\Temp\arduino_modified_sketch_641038\sketch_may14a.ino: In function 'void loop()':
                        
                        sketch_may14a:91: error: 'si7021_thc' was not declared in this scope
                        
                           si7021_thc temphum = sensor.getTempAndRH();
                        
                           ^
                        
                        sketch_may14a:91: error: expected ';' before 'temphum'
                        
                           si7021_thc temphum = sensor.getTempAndRH();
                        
                                      ^
                        
                        sketch_may14a:95: error: 'temphum' was not declared in this scope
                        
                           float temperature = (float)(temphum.celsiusHundredths) / 100.0;
                        
                                                       ^
                        
                        Multiple libraries were found for "SI7021.h"
                         Used: C:\Users\abc\Documents\Arduino\libraries\SI7021
                         Not used: C:\Program Files (x86)\Arduino\libraries\SI7021
                        exit status 1
                        'si7021_thc' was not declared in this scope
                        
                        Insert Code Here
                        
                        F Offline
                        F Offline
                        flopp
                        wrote on last edited by
                        #38

                        @tango156157
                        Look you have more than one library for si7021.
                        Move one library and then try again.
                        If that doesn't help.

                        Move back the first library and move the second one, try again and see if that helped

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          Edoardo Vogna
                          wrote on last edited by
                          #39

                          Hello fleinze,
                          What about this project? Your sensors still working?
                          I'm trying to build the same but I have some problem to change the efuse value:
                          "I changed the efuse value to 0x07 (BOD off)"

                          I' dont know how to edit the boards.txt file and how to install it in the arduino pro mini.

                          Could you explain the procedure step by step or link me a good complete tutorial ?

                          Thank you very much

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


                          14

                          Online

                          11.7k

                          Users

                          11.2k

                          Topics

                          113.1k

                          Posts


                          Copyright 2025 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