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.
  • F Offline
    F Offline
    fleinze
    wrote on last edited by
    #1

    Hi!

    I would like to share my experience with coin-cell (CR2032) powered temperature sensors:

    DSC_0970.jpg

    DSC_0971.jpg

    The reason for my use of a CR2032 coin cell is that I am really bad at building cases. So I wanted a sensor that will fit into a kinder-surprise egg.

    To maximize battery life I did some modifications to the pro micro clones:

    • I removed all the leds
    • and also the 3.3v-regulator
    • I used a digital pin for the voltage divider so I can turn the divider off
    • I changed the efuse value to 0x07 (BOD off)

    For easier connections I use digital pins to provide the DS18B20 temperature sensor with VCC and GND. I also got rid of the 4k7 resistor by using a modified version of the onewire.h library which uses the internal pullup instead.

    Temperature is transmitted every 5 minutes and battery level every hour.

    For the battery level I used software bounderies: 3.3V is 100%, 2.6V is 0%.

    If anyone is interested, here is the code. It is based on the old example sketch.

    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected
    #define ONE_WIRE_GND 5
    #define ONE_WIRE_VCC 3
    #define BATT_IN_PIN A0
    #define BATT_VCC_PIN 6
    #define MAX_ATTACHED_DS18B20 16
    
    #define SLEEP_TIME 300000  // Sleep time between reads (in milliseconds)
    #define BATT_TIME 12  //when also BATT-LEVEL is reported
    
    #define BATT_100 3.3
    #define BATT_0 2.6
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    MySensor gw;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    uint8_t numSensors = 0;
    boolean receivedConfig = false;
    boolean metric = true;
    // Initialize temperature message
    MyMessage msg(0, V_TEMP);
    uint8_t battReport = 0;
    int oldvalue = 0;
    
    void setup()
    {
      // Startup OneWire
    #ifdef ONE_WIRE_VCC
      pinMode(ONE_WIRE_VCC, OUTPUT);
      digitalWrite(ONE_WIRE_VCC, HIGH);
    #endif
    #ifdef ONE_WIRE_GND
      pinMode(ONE_WIRE_GND, OUTPUT);
      digitalWrite(ONE_WIRE_GND, LOW);
    #endif
    
      analogReference(INTERNAL);
      pinMode(BATT_IN_PIN, INPUT);
      pinMode(BATT_VCC_PIN, OUTPUT);
      digitalWrite(BATT_VCC_PIN, LOW);
    
      sensors.begin();
    
      // Startup and initialize MySensors library. Set callback for incoming messages.
      gw.begin();
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Temperature Sensor", "1.0");
    
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      sensors.setWaitForConversion(false);//saves a few mAs per read :-) to debug
    
      // Present all sensors to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);
      }
    }
    
    
    void loop()
    {
      // Process incoming messages (like config from server)
      //gw.process();
    
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      gw.sleep(750);//wait for conversion in sleep mode
    
      // Read temperatures and send them to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature, 1));
          lastTemperature[i] = temperature;
        }
      }
      if (++battReport == BATT_TIME) {
        digitalWrite(BATT_VCC_PIN, HIGH);
        delay(1);
        int value = analogRead(BATT_IN_PIN);
        digitalWrite(BATT_VCC_PIN, LOW);
        if (value != oldvalue)
        {
          int percent = (( value * 3.36e-3) - 2.6) / (3.3 - 2.6) * 100;
          percent = (percent > 100) ? 100 : percent;
          percent = (percent < 0) ? 0 : percent;
          gw.sendBatteryLevel(percent);
        }
        oldvalue = value;
        battReport = 0;
      }
      gw.sleep(SLEEP_TIME);//wake on interrupt or after sleep-time
    }
    

    My experience so far:
    On the good side: the first sensor I built started operation on May 23 (about 3 months ago) and is still working great with the same coin cell. I first hoped for a month or two because of the small capacity of a CR2032 coin cell, so my expectation is already exceeded.

    On the bad side: Some other sensors I built later had problems. They worked well with the fresh battery but stopped working after a day or two. After this time they went into a boot loop (serial monitor reads "sensor started, id ..." over and over again) so apparently the startup of the radio somehow triggers a reboot.
    As a modification to prevent this I resoldered the input capacitor of the raw-pin (which is unused) directly to the radio.
    For most sensors this worked fine.
    But one sensor did keep rebooting. I had to change it to a 2xAA-powered sensor. I later used the same CR2032 coin cell, which powered a reboot loop for about 24 hours to power another, newly built sensor and it worked on that one.

    I don't know what the reason for this is, but it has to have something to do with the voltage drop made by the radio. Either some radios are bad and drawing a higher current or some of the pro micro clones are bad and maybe not accepting the changed efuse values.

    Has anyone had similar issues? Are there counterfeit atmega328 around which do not work up to specifications?

    1 Reply Last reply
    3
    • NeverDieN Offline
      NeverDieN Offline
      NeverDie
      Hero Member
      wrote on last edited by NeverDie
      #2

      @fleinze said:

      For easier connections I use digital pins to provide the DS18B20 temperature sensor with VCC and GND.

      Sounds like a clever idea.

      Measuring your currents would be the best way to narrow down where the problem is.

      Maybe some of your radios are using different counterfeit NRF chips, and the radio chip in your boot-looping sensor may, for example, be drawing more current during transmit, or perhaps drawing too much current during sleep or just generally,, causing voltage to drop because of internal resistance, and the pro mini to drop out. After radio drops out, voltage rises again, and pro mini reboots.

      Or, perhaps some other component in your boot-looping sensor is drawing higher current, resulting in the same cause-effect outcome after your battery drains enough.

      Or maybe your boot-loop battery is just weak to begin with as compared to your other batteries.

      Make sense?

      Eventually, I would guess most coin cell sensors are going to boot-loop, triggered by sending a packet, whenever their batteries get drained enough, because of the high internal resistance in the coin cell battery. So, just measuring battery voltage, by itself, without a peak current to drop it, isn't going to tell you how close your sensor is to cutting out.

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

        Just a quick Update on my coin-cell sensors:
        I still did not figure out why one sensor did not work because I lack of the needed measurement-equipment :(

        But I figured out something else: The voltage of a CR2032 battery has a very strong temperature-dependence. So for calculating the battery-level I probably need to calculate a temperature-normalized voltage-value.

        1 Reply Last reply
        1
        • TheoLT Offline
          TheoLT Offline
          TheoL
          Contest Winner
          wrote on last edited by
          #4

          I'm following this topics with much interest. It would be really great if it's possible to power a sensor with a CR2032 cell.

          For my two AA powered Soil Moisture sensor, I just put a transistor (BC547b I think, they came with the Arduino starter kit) between the soil moisture sensor circuit and one in the circuit for battery power measurement. As I only have basic knowledge of electronics, I'm not sure if this will save battery power. But I switch on the transistors whenever I have to read the sensors. Wait a little bit so that the sensors have enough time to give a good reading. And then I switch the transistors off. I only need two extra outputs this way and I'm using A0 and A1 as digital outputs.

          My guessing is, that I will save battery power by turning the power on the sensors on, only when I need to read them.

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

            I think you can just use a arduino-pin to power the soil sensor and the battery power measurement.
            I did this with the battery power measurement even if it only saves about 2uA, probably in the magnitude of the self-discharge rate.

            1 Reply Last reply
            0
            • TheoLT Offline
              TheoLT Offline
              TheoL
              Contest Winner
              wrote on last edited by
              #6

              @fleinze That makes actually more sense. But if I'm using a 3.3V step-up regulator I won't be able to feed the measuerment circuit from a digital pin right? Would a transistor be a good idea?

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

                That depends: Does the step-up just feed the measurement or also the arduino?
                Can you post schematics?

                As long as you stay below 20mA you can use the digital pins to power everything.

                Be aware that a step-up regulator has low efficency at low currents, so it is possible that it actually shortens battery life instead of increasing it.

                1 Reply Last reply
                0
                • TheoLT Offline
                  TheoLT Offline
                  TheoL
                  Contest Winner
                  wrote on last edited by
                  #8

                  The step-up feeds the mini pro 3.3V. I measure the battery level directly from the battery.

                  1 Reply Last reply
                  0
                  • NeverDieN Offline
                    NeverDieN Offline
                    NeverDie
                    Hero Member
                    wrote on last edited by
                    #9

                    Did you ever solve your boot-loop problem?

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

                      Kind of. I used a different Arduino and now it works.

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

                        @TheoL: The step-up regulator will most likely drain your battery very quickly. It uses a lot of current in "standby-mode" (when Arduino is powered down)!

                        You can power an Arduino and most sensors directly from battery but you need to disable BOD (brown-out-detection). To do this you need an programmer ("Arduino as ISP"-sketch is sufficient) and set the extended-fuse to 0x07. This can be done with the Arduino-IDE, but you need to edit the boards.txt file.

                        1 Reply Last reply
                        0
                        • carlekiC Offline
                          carlekiC Offline
                          carleki
                          wrote on last edited by
                          #12

                          what about your nodes after several months ?

                          F 1 Reply Last reply
                          1
                          • carlekiC carleki

                            what about your nodes after several months ?

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

                            @carmelo42 I just changed coin-cell on one of my sensors. It lasted since for 10 months, this is ok for me.

                            carlekiC 1 Reply Last reply
                            3
                            • F Offline
                              F Offline
                              fleinze
                              wrote on last edited by
                              #14

                              Measuring the voltage proofed to be worthless for this kind of battery. It is more dependent of the temperature than from anything else.

                              1 Reply Last reply
                              0
                              • F fleinze

                                @carmelo42 I just changed coin-cell on one of my sensors. It lasted since for 10 months, this is ok for me.

                                carlekiC Offline
                                carlekiC Offline
                                carleki
                                wrote on last edited by
                                #15

                                @fleinze said:

                                @carmelo42 I just changed coin-cell on one of my sensors. It lasted since for 10 months, this is ok for me.

                                10 months ? it's perfect :)

                                Can you provide the modified version of the library to avoid using 4.7k resistor for the Dallas sensor ?

                                What is for the resistor on the pic ? for the voltage mesurement ?

                                F 1 Reply Last reply
                                0
                                • carlekiC carleki

                                  @fleinze said:

                                  @carmelo42 I just changed coin-cell on one of my sensors. It lasted since for 10 months, this is ok for me.

                                  10 months ? it's perfect :)

                                  Can you provide the modified version of the library to avoid using 4.7k resistor for the Dallas sensor ?

                                  What is for the resistor on the pic ? for the voltage mesurement ?

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

                                  @carmelo42

                                  The no-resistor-library can be found here:
                                  https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

                                  The resistors (there are two but the other one is barely visible) are for voltage-measurement. In a later version I got rid of them using this resistor-less method of measurement:
                                  http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

                                  carlekiC 1 Reply Last reply
                                  1
                                  • Moebius LutchingM Offline
                                    Moebius LutchingM Offline
                                    Moebius Lutching
                                    wrote on last edited by
                                    #17

                                    Just found this post https://www.hackster.io/Talk2/temp-and-humidity-sensor-with-a-cr2032-for-over-1-year-580114 showing some details about using a CR2032 to power a sensor node. By my calculations, if the author removed the LED at all the solution would last for over 2 years!

                                    1 Reply Last reply
                                    1
                                    • F fleinze

                                      @carmelo42

                                      The no-resistor-library can be found here:
                                      https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

                                      The resistors (there are two but the other one is barely visible) are for voltage-measurement. In a later version I got rid of them using this resistor-less method of measurement:
                                      http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

                                      carlekiC Offline
                                      carlekiC Offline
                                      carleki
                                      wrote on last edited by
                                      #18

                                      @fleinze said:

                                      @carmelo42

                                      The no-resistor-library can be found here:
                                      https://wp.josh.com/2014/06/23/no-external-pull-up-needed-for-ds18b20-temp-sensor/

                                      The resistors (there are two but the other one is barely visible) are for voltage-measurement. In a later version I got rid of them using this resistor-less method of measurement:
                                      http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

                                      great :)

                                      Did you change the bootloader ? Which one did you use ?

                                      F 1 Reply Last reply
                                      0
                                      • Nca78N Offline
                                        Nca78N Offline
                                        Nca78
                                        Hardware Contributor
                                        wrote on last edited by
                                        #19

                                        Hello,

                                        there are a few improvements you can do to make your CR2032 nodes last longer:

                                        • add a capacitor of 100-200µF in parallel with your battery. Ceramic is better, but I have no problem with nodes using electrolytic capacitors. This will help when there is a peak power consumption from the radio. If you do not put one, voltage will drop quickly and that's probably what is triggering reboot loop on one of your nodes: maybe radio is less efficient and needs to resend more messages. Or maybe your BOD is not updated so it resets when voltage drops at 2.7V...
                                        • in your code, add a sleep command between message sending to give time for your cell to rest, and for the capacitor to recharge. Do it also at the beginning of presentation method and between each message sending in presentation.
                                        • use a better sensor that can accept a lower voltage, they are more expensive that DS18 but they can work down to 2V and use much less current: BMP180/280 if you want to measure only temperature (with barometer as extra), SI7021 for temp/hum, BME280 for temp/hum more expensive but better.
                                        • do not use voltage divider at all, you don't need one as you can just get Vcc from the A0 pin (with it I have some change of voltage related to temperature but not as wild as you seem to get. Maybe it's related to the DS18 measurement also ?)

                                        With these changes and a si7021 breakout board from which I removed the voltage regulator (it's not consuming much, but without it is even better), I can send every minute, flash a led and I hardly see any drop in voltage after a few weeks of running.

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

                                          @Nca78 said:

                                          add a capacitor of 100-200µF

                                          I will try this, thanks! Currently I use the 10uF capacitor which is on the arduino pro minis on the raw pin side.

                                          in your code, add a sleep command between message sending

                                          How long do you sleep? In normal operation there is only one send command per loop, I only send battery level once every hour. I try to read vcc after sending the temperature so the battery is under some load when measuring.

                                          use a better sensor that can accept a lower voltage

                                          I already built one with a Si7021 sensor. But I ran out of CR2032 so I powered it using two AA cells. I should solder it back to coin cell now I got some.

                                          you can just get Vcc from the A0 pin

                                          I don't know this method do you have a link or can you explain it?

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


                                          10

                                          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