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.
  • ? 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
                              • YveauxY Yveaux

                                @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...

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

                                @Yveaux I know about that fluctuation, but for my use in a scene controller I would be happy just to know the battery is low. I have it running with a multi-button, were I have click, duble-click and click and hold, I only check battery at one click, because of its fluctuation, but if you use it more than 4 times e a short period that fluctuation is noted, and that is why a added to the 10% increase a 10% decrease gap on battery sent information. Thanks

                                1 Reply Last reply
                                0
                                • Nca78N Nca78

                                  @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 Offline
                                  andredtsA Offline
                                  andredts
                                  wrote on last edited by
                                  #83

                                  @Nca78 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 ;-):

                                  @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).

                                  Hi, I do read the battery first thing after wake up, my problem was when a had various click too close together. It`s good now that I only send battery values that a 10% higher or lower than my last stored value. I will take a look on the 1Mhz bootloader. Thanks

                                  gohanG 1 Reply Last reply
                                  0
                                  • andredtsA andredts

                                    @Nca78 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 ;-):

                                    @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).

                                    Hi, I do read the battery first thing after wake up, my problem was when a had various click too close together. It`s good now that I only send battery values that a 10% higher or lower than my last stored value. I will take a look on the 1Mhz bootloader. Thanks

                                    gohanG Offline
                                    gohanG Offline
                                    gohan
                                    Mod
                                    wrote on last edited by
                                    #84

                                    @andredts you could make an average of the last 3-4 reads before sending the battery value

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

                                      is it normal that just swapping a pro mini I am getting a voltage reading difference of 0.12V from same node?

                                      mfalkviddM 1 Reply Last reply
                                      0
                                      • gohanG gohan

                                        is it normal that just swapping a pro mini I am getting a voltage reading difference of 0.12V from same node?

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

                                        @gohan the internal reference is specified to be 1.0 to 1.2 V (see "29.5 System and Reset Characteristics" in the datasheet)

                                        So the voltage will vary between different chips.

                                        1 Reply Last reply
                                        1
                                        • gohanG Offline
                                          gohanG Offline
                                          gohan
                                          Mod
                                          wrote on last edited by
                                          #87

                                          Btw, what is the maximum voltage that you can read with this vcc library?

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


                                          6

                                          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