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. Development
  3. 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 ;-)

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 ;-)

Scheduled Pinned Locked Moved Development
supplyvcc
90 Posts 20 Posters 143.3k Views 13 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.
  • RJ_MakeR Offline
    RJ_MakeR Offline
    RJ_Make
    Hero Member
    wrote on last edited by
    #62

    Thread Rival ... ;-)

    So in trying to understand and improve battery life (currently using V div on Step Reg. Vin (VBatt) in my sensors, why can't I just measure the VCC on AO without the V div as VBAT will never exceed VCC,?

    Trying to figure out what fundamental I'm missing here....

    RJ_Make

    YveauxY 1 Reply Last reply
    0
    • RJ_MakeR RJ_Make

      Thread Rival ... ;-)

      So in trying to understand and improve battery life (currently using V div on Step Reg. Vin (VBatt) in my sensors, why can't I just measure the VCC on AO without the V div as VBAT will never exceed VCC,?

      Trying to figure out what fundamental I'm missing here....

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #63

      @ServiceXp So you want to connect VCC of the ATMega to ana analog input pin to read the supply level?
      If this is your idea, then the ATMega will measure the voltage on an analog input relative to the supply voltage. If the supply voltage of the ATMega starts to drop, the relative voltage measured on the analog input will not change w.r.t. VCC.
      By using a voltage divider you bring the voltage to be measured within 0,..,1.1V range (roughly). The ATMega has an internal 1.1V voltage reference which will remain stable when VCC drops, and thus can be used to meaure the supply level using a voltage divider.

      http://yveaux.blogspot.nl

      RJ_MakeR 1 Reply Last reply
      0
      • YveauxY Yveaux

        @ServiceXp So you want to connect VCC of the ATMega to ana analog input pin to read the supply level?
        If this is your idea, then the ATMega will measure the voltage on an analog input relative to the supply voltage. If the supply voltage of the ATMega starts to drop, the relative voltage measured on the analog input will not change w.r.t. VCC.
        By using a voltage divider you bring the voltage to be measured within 0,..,1.1V range (roughly). The ATMega has an internal 1.1V voltage reference which will remain stable when VCC drops, and thus can be used to meaure the supply level using a voltage divider.

        RJ_MakeR Offline
        RJ_MakeR Offline
        RJ_Make
        Hero Member
        wrote on last edited by
        #64

        @Yveaux said:

        @ServiceXp So you want to connect VCC of the ATMega to ana analog input pin to read the supply level?
        If this is your idea, then the ATMega will measure the voltage on an analog input relative to the supply voltage. If the supply voltage of the ATMega starts to drop, the relative voltage measured on the analog input will not change w.r.t. VCC.
        By using a voltage divider you bring the voltage to be measured within 0,..,1.1V range (roughly). The ATMega has an internal 1.1V voltage reference which will remain stable when VCC drops, and thus can be used to meaure the supply level using a voltage divider.

        1. No; vBatt to AO; MCU will be powered by Step Up Reg. vOut.

        2. The MCU supply voltage will never be lower then vBatt. (in the case of 2 AA Batteries). vBatt will always be lower then MCU VCC, In all reality MCU VCC will never change in a significant way, until Step Up Reg drops out.

        3. think it's this v1.1 ref. that may be confusing me, but it just seems like this method should work with out the V div for sensors using 2 AA batteries or any <3.3v power source. ;-)

        RJ_Make

        YveauxY 1 Reply Last reply
        0
        • RJ_MakeR RJ_Make

          @Yveaux said:

          @ServiceXp So you want to connect VCC of the ATMega to ana analog input pin to read the supply level?
          If this is your idea, then the ATMega will measure the voltage on an analog input relative to the supply voltage. If the supply voltage of the ATMega starts to drop, the relative voltage measured on the analog input will not change w.r.t. VCC.
          By using a voltage divider you bring the voltage to be measured within 0,..,1.1V range (roughly). The ATMega has an internal 1.1V voltage reference which will remain stable when VCC drops, and thus can be used to meaure the supply level using a voltage divider.

          1. No; vBatt to AO; MCU will be powered by Step Up Reg. vOut.

          2. The MCU supply voltage will never be lower then vBatt. (in the case of 2 AA Batteries). vBatt will always be lower then MCU VCC, In all reality MCU VCC will never change in a significant way, until Step Up Reg drops out.

          3. think it's this v1.1 ref. that may be confusing me, but it just seems like this method should work with out the V div for sensors using 2 AA batteries or any <3.3v power source. ;-)

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #65

          @ServiceXp OK, I didn't really get your description in the previous post them.
          When VCC is stable due to to the step up converter then it should also work to just reference analog input to vcc. This way your measuring range is 0,..,vcc, which is a lot more then 0,..,1.1v

          http://yveaux.blogspot.nl

          1 Reply Last reply
          0
          • Mark SwiftM Offline
            Mark SwiftM Offline
            Mark Swift
            wrote on last edited by
            #66

            Thread revival.

            I have a sensor powered by 2 AA batteries, does this still stand as a simple way to obtain their status? It was super easy to implement!

            1 Reply Last reply
            1
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #67

              Would this library also work on a WEMOS D1, which is powered by a esp8266?

              Paai

              YveauxY 1 Reply Last reply
              0
              • ? A Former User

                Would this library also work on a WEMOS D1, which is powered by a esp8266?

                Paai

                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #68

                @Hans-Paijmans no, it's avr only

                http://yveaux.blogspot.nl

                1 Reply Last reply
                0
                • mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by mfalkvidd
                  #69

                  On esp, ESP.getVcc() can be used. More info: https://www.letscontrolit.com/forum/viewtopic.php?t=130

                  Edit: use MySensors' hwCPUVoltage() instead. See below for more information.

                  1 Reply Last reply
                  0
                  • MiKaM Offline
                    MiKaM Offline
                    MiKa
                    wrote on last edited by
                    #70

                    Hi,
                    possible to read also internal VCC for SAMD21 and NRF5 platform core?
                    MiKa

                    YveauxY mfalkviddM 2 Replies Last reply
                    0
                    • MiKaM MiKa

                      Hi,
                      possible to read also internal VCC for SAMD21 and NRF5 platform core?
                      MiKa

                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by
                      #71

                      @MiKa no, it's avr only

                      http://yveaux.blogspot.nl

                      1 Reply Last reply
                      0
                      • MiKaM MiKa

                        Hi,
                        possible to read also internal VCC for SAMD21 and NRF5 platform core?
                        MiKa

                        mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by mfalkvidd
                        #72

                        @MiKa use hwCPUVoltage(), this works for AVR, SAMD and ESP8266. ESP8266 requires defining MY_SPECIAL_DEBUG though.

                        MiKaM 1 Reply Last reply
                        1
                        • mfalkviddM mfalkvidd

                          @MiKa use hwCPUVoltage(), this works for AVR, SAMD and ESP8266. ESP8266 requires defining MY_SPECIAL_DEBUG though.

                          MiKaM Offline
                          MiKaM Offline
                          MiKa
                          wrote on last edited by
                          #73

                          @mfalkvidd said in 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 ;-):

                          @MiKa use hwCPUVoltage() this works for AVR, SAMD and ESP8266. ESP8266 requires defining MY_SPECIAL_DEBUG though.

                          Thanks ! It works on SAMD21E board :)

                          MiKaM 1 Reply Last reply
                          2
                          • MiKaM MiKa

                            @mfalkvidd said in 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 ;-):

                            @MiKa use hwCPUVoltage() this works for AVR, SAMD and ESP8266. ESP8266 requires defining MY_SPECIAL_DEBUG though.

                            Thanks ! It works on SAMD21E board :)

                            MiKaM Offline
                            MiKaM Offline
                            MiKa
                            wrote on last edited by
                            #74

                            It looks, its working also on NRF5 platform, tested with NRF51822 MCU ;) :+1:

                            https://raw.githubusercontent.com/d00616/arduino-nRF5-boards/master/51822_ITC_PolyU_HK/51822_ITC_PolyU_HK.jpg

                            1 Reply Last reply
                            2
                            • andredtsA Offline
                              andredtsA Offline
                              andredts
                              wrote on last edited by
                              #75

                              @Yveaux Hi, thanks for your work. Maybe I´m going over something that was covered before, but I need some help, I´m using this code in a door sensor with 2 aa battery, and reporting if battery changes, when the door opens or closes. My problem is that I always get diferent readings from close to open, so I´m always reporting battery level and using more power than needed. Thanks

                              YveauxY 1 Reply Last reply
                              0
                              • andredtsA andredts

                                @Yveaux Hi, thanks for your work. Maybe I´m going over something that was covered before, but I need some help, I´m using this code in a door sensor with 2 aa battery, and reporting if battery changes, when the door opens or closes. My problem is that I always get diferent readings from close to open, so I´m always reporting battery level and using more power than needed. Thanks

                                YveauxY Offline
                                YveauxY Offline
                                Yveaux
                                Mod
                                wrote on last edited by
                                #76

                                @andredts the voltage reference only has limited accuracy, therefore the reported battery voltage might vary slightly. Also the load on the battery can change, causing a variation in battery level reported. Not a lot you can do about that I'm afraid.
                                I experimented with sending all decreases in battery level wrt the previous value, and only large increases (eg 10% or more to detect change of batteries). Works quite well.

                                http://yveaux.blogspot.nl

                                andredtsA 1 Reply Last reply
                                2
                                • YveauxY Yveaux

                                  @andredts the voltage reference only has limited accuracy, therefore the reported battery voltage might vary slightly. Also the load on the battery can change, causing a variation in battery level reported. Not a lot you can do about that I'm afraid.
                                  I experimented with sending all decreases in battery level wrt the previous value, and only large increases (eg 10% or more to detect change of batteries). Works quite well.

                                  andredtsA Offline
                                  andredtsA Offline
                                  andredts
                                  wrote on last edited by
                                  #77

                                  @Yveaux Thanks, that was exactly the insight I was looking, for my door sensor with 2aa battery, your way worked great. For a scene controller with a CR2032 a had to not send also decreases greater then 10%, but hey, 10 steps is more enough.

                                  YveauxY Nca78N 2 Replies Last reply
                                  0
                                  • andredtsA andredts

                                    @Yveaux Thanks, that was exactly the insight I was looking, for my door sensor with 2aa battery, your way worked great. For a scene controller with a CR2032 a had to not send also decreases greater then 10%, but hey, 10 steps is more enough.

                                    YveauxY Offline
                                    YveauxY Offline
                                    Yveaux
                                    Mod
                                    wrote on last edited by
                                    #78

                                    @andredts cr2032 is a totally different story. The voltage level fluctuates significantly when sending messages compared to AA powered sensors.
                                    The 10% is only an example value and used for an increasing voltage level (that normally should only happen when replacing batteries). For a decreasing voltage (regular battery usage) you can just report the level and get much higher resolution. Question is if it will really be useful for cr2032 though...

                                    http://yveaux.blogspot.nl

                                    andredtsA 1 Reply Last reply
                                    0
                                    • sundberg84S Offline
                                      sundberg84S Offline
                                      sundberg84
                                      Hardware Contributor
                                      wrote on last edited by
                                      #79

                                      How about storing last 10 values and send an average every time?

                                      Controller: Proxmox VM - Home Assistant
                                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                      1 Reply Last reply
                                      0
                                      • andredtsA andredts

                                        @Yveaux Thanks, that was exactly the insight I was looking, for my door sensor with 2aa battery, your way worked great. For a scene controller with a CR2032 a had to not send also decreases greater then 10%, but hey, 10 steps is more enough.

                                        Nca78N Offline
                                        Nca78N Offline
                                        Nca78
                                        Hardware Contributor
                                        wrote on last edited by
                                        #80

                                        @andredts said in 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 ;-):

                                        @Yveaux Thanks, that was exactly the insight I was looking, for my door sensor with 2aa battery, your way worked great. For a scene controller with a CR2032 a had to not send also decreases greater then 10%, but hey, 10 steps is more enough.

                                        For having consistent measurements with a CR2032 you should measure voltage as first action after waking up from sleep.
                                        I keep the value in a variable and process it after "action" message of the node.

                                        If possible, run at 1Mhz on internal oscillator so the power consumption of the atmega stays very low (around 1mA instead of 3 at 8MHz/3V).

                                        andredtsA 1 Reply Last reply
                                        0
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #81

                                          I'd like to share my little experience with the 3.2V LiFePO4 AA batteries ad they are a very good solution since a single battery can be used and be directly measured through VCC without requiring any voltage divider or booster

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


                                          17

                                          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