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. Battery percentage on door contact sensor erratic (sent on interrupt)

Battery percentage on door contact sensor erratic (sent on interrupt)

Scheduled Pinned Locked Moved Development
20 Posts 5 Posters 2.2k Views 4 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.
  • YveauxY Yveaux

    @greymarvel what happens if you place a sleep of e.g. 100ms just before reading the analog value?

    Or write the analog reference every time just before the analog read?

    You could also use my Vcc library as a reference: https://github.com/Yveaux/Arduino_Vcc

    G Offline
    G Offline
    GreyLinux
    wrote on last edited by
    #3

    @yveaux

    Ok so I added the analog reference into the loop and a delay(100);
    this has improved things the readings are less erratic but still not close enough .

    2328 MCO:SLP:WUP=-1
    2330 TSF:TRI:TSB
    2332 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    2336 TSF:TDI:TSL
    2338 MCO:SLP:WUP=1
    2340 TSF:TRI:TSB
    Sensor value: 876
    Battery Voltage: 2.83 V
    Battery percent: 20 %
    2447 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:20
    2457 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    2465 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    2469 TSF:TDI:TSL
    2471 MCO:SLP:WUP=-1
    2476 TSF:TRI:TSB
    2476 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    2482 TSF:TDI:TSL
    2484 MCO:SLP:WUP=1
    2486 TSF:TRI:TSB
    Sensor value: 874
    Battery Voltage: 2.82 V
    Battery percent: 19 %
    2594 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:19
    2603 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    2611 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    2617 TSF:TDI:TSL
    2619 MCO:SLP:WUP=-1
    2621 TSF:TRI:TSB
    2623 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    2627 TSF:TDI:TSL
    2629 MCO:SLP:WUP=1
    2631 TSF:TRI:TSB
    Sensor value: 854
    Battery Voltage: 2.75 V
    Battery percent: 9 %
    2738 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:9
    2748 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    2754 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    2760 TSF:TDI:TSL
    2762 MCO:SLP:WUP=-1
    2764 TSF:TRI:TSB
    2766 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    2772 TSF:TDI:TSL
    2775 MCO:SLP:WUP=1
    2777 TSF:TRI:TSB
    Sensor value: 853
    Battery Voltage: 2.75 V
    Battery percent: 8 %
    2883 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:8
    2891 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    2899 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    2906 TSF:TDI:TSL
    2908 MCO:SLP:WUP=-1
    2910 TSF:TRI:TSB
    2912 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    2916 TSF:TDI:TSL
    2918 MCO:SLP:WUP=1
    2920 TSF:TRI:TSB
    Sensor value: 852
    Battery Voltage: 2.75 V
    Battery percent: 8 %
    3026 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    3035 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    3041 TSF:TDI:TSL
    3043 MCO:SLP:WUP=-1
    3045 TSF:TRI:TSB
    3047 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    3051 TSF:TDI:TSL
    3053 MCO:SLP:WUP=1
    3055 TSF:TRI:TSB
    Sensor value: 873
    Battery Voltage: 2.82 V
    Battery percent: 19 %
    3162 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:19
    3172 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    3178 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    3184 TSF:TDI:TSL
    3186 MCO:SLP:WUP=-1
    3188 TSF:TRI:TSB
    3190 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    3196 TSF:TDI:TSL
    3196 MCO:SLP:WUP=1
    3201 TSF:TRI:TSB
    Sensor value: 885
    Battery Voltage: 2.85 V
    Battery percent: 25 %
    3307 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:25
    3315 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    3323 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    3330 TSF:TDI:TSL
    3332 MCO:SLP:WUP=-1
    3334 TSF:TRI:TSB
    3336 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    3340 TSF:TDI:TSL
    3342 MCO:SLP:WUP=1
    3344 TSF:TRI:TSB
    Sensor value: 872
    Battery Voltage: 2.81 V
    Battery percent: 18 %
    3450 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:18
    3461 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
    3467 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    3473 TSF:TDI:TSL
    3475 MCO:SLP:WUP=-1
    3477 TSF:TRI:TSB
    3479 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    3485 TSF:TDI:TSL
    3487 MCO:SLP:WUP=1
    3489 TSF:TRI:TSB
    Sensor value: 869
    Battery Voltage: 2.80 V
    Battery percent: 17 %
    3596 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:17
    3604 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
    3612 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
    3618 TSF:TDI:TSL
    3620 MCO:SLP:WUP=-1
    3622 TSF:TRI:TSB
    3624 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
    3629 TSF:TDI:TSL
    3631 MCO:SLP:WUP=1
    3633 TSF:TRI:TSB```
    YveauxY 1 Reply Last reply
    0
    • G GreyLinux

      @yveaux

      Ok so I added the analog reference into the loop and a delay(100);
      this has improved things the readings are less erratic but still not close enough .

      2328 MCO:SLP:WUP=-1
      2330 TSF:TRI:TSB
      2332 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      2336 TSF:TDI:TSL
      2338 MCO:SLP:WUP=1
      2340 TSF:TRI:TSB
      Sensor value: 876
      Battery Voltage: 2.83 V
      Battery percent: 20 %
      2447 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:20
      2457 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
      2465 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      2469 TSF:TDI:TSL
      2471 MCO:SLP:WUP=-1
      2476 TSF:TRI:TSB
      2476 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      2482 TSF:TDI:TSL
      2484 MCO:SLP:WUP=1
      2486 TSF:TRI:TSB
      Sensor value: 874
      Battery Voltage: 2.82 V
      Battery percent: 19 %
      2594 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:19
      2603 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
      2611 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      2617 TSF:TDI:TSL
      2619 MCO:SLP:WUP=-1
      2621 TSF:TRI:TSB
      2623 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      2627 TSF:TDI:TSL
      2629 MCO:SLP:WUP=1
      2631 TSF:TRI:TSB
      Sensor value: 854
      Battery Voltage: 2.75 V
      Battery percent: 9 %
      2738 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:9
      2748 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
      2754 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      2760 TSF:TDI:TSL
      2762 MCO:SLP:WUP=-1
      2764 TSF:TRI:TSB
      2766 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      2772 TSF:TDI:TSL
      2775 MCO:SLP:WUP=1
      2777 TSF:TRI:TSB
      Sensor value: 853
      Battery Voltage: 2.75 V
      Battery percent: 8 %
      2883 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:8
      2891 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
      2899 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      2906 TSF:TDI:TSL
      2908 MCO:SLP:WUP=-1
      2910 TSF:TRI:TSB
      2912 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      2916 TSF:TDI:TSL
      2918 MCO:SLP:WUP=1
      2920 TSF:TRI:TSB
      Sensor value: 852
      Battery Voltage: 2.75 V
      Battery percent: 8 %
      3026 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
      3035 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      3041 TSF:TDI:TSL
      3043 MCO:SLP:WUP=-1
      3045 TSF:TRI:TSB
      3047 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      3051 TSF:TDI:TSL
      3053 MCO:SLP:WUP=1
      3055 TSF:TRI:TSB
      Sensor value: 873
      Battery Voltage: 2.82 V
      Battery percent: 19 %
      3162 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:19
      3172 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
      3178 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      3184 TSF:TDI:TSL
      3186 MCO:SLP:WUP=-1
      3188 TSF:TRI:TSB
      3190 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      3196 TSF:TDI:TSL
      3196 MCO:SLP:WUP=1
      3201 TSF:TRI:TSB
      Sensor value: 885
      Battery Voltage: 2.85 V
      Battery percent: 25 %
      3307 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:25
      3315 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
      3323 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      3330 TSF:TDI:TSL
      3332 MCO:SLP:WUP=-1
      3334 TSF:TRI:TSB
      3336 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      3340 TSF:TDI:TSL
      3342 MCO:SLP:WUP=1
      3344 TSF:TRI:TSB
      Sensor value: 872
      Battery Voltage: 2.81 V
      Battery percent: 18 %
      3450 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:18
      3461 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
      3467 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      3473 TSF:TDI:TSL
      3475 MCO:SLP:WUP=-1
      3477 TSF:TRI:TSB
      3479 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      3485 TSF:TDI:TSL
      3487 MCO:SLP:WUP=1
      3489 TSF:TRI:TSB
      Sensor value: 869
      Battery Voltage: 2.80 V
      Battery percent: 17 %
      3596 TSF:MSG:SEND,4-4-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:17
      3604 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
      3612 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
      3618 TSF:TDI:TSL
      3620 MCO:SLP:WUP=-1
      3622 TSF:TRI:TSB
      3624 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
      3629 TSF:TDI:TSL
      3631 MCO:SLP:WUP=1
      3633 TSF:TRI:TSB```
      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #4

      @greymarvel well, the internal reference isn't very accurate, so that might be the cause of the variation.
      You could also average a number of readings and only report values going down wrt to the previous readings.

      http://yveaux.blogspot.nl

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

        I am using the vcc library and also a voltage divider to read higher voltages than 3.3v and I make the average of the last 4 readings before sending the value and it has been working very well so far.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GreyLinux
          wrote on last edited by
          #6

          @gohan @Yveaux I think this might be the option to send in the average reading .To be fair this was opening the contact every couple of seconds and in reality this would be alot longer between reads . Thanks for your help.

          1 Reply Last reply
          0
          • rozpruwaczR Offline
            rozpruwaczR Offline
            rozpruwacz
            wrote on last edited by
            #7

            @greymarvel what kind of battery are You using ? The voltage on the battery may not be constant in short periods, it depends on the load and bettery internal resistance. The higher the internal resistance the bigger are voltage swings in response to load swings. I have two identical boards, differing only in the batery holder, one is for cr2032 (higher internal resistance) and the other is for cr123 (lower internal resistance). These boards have exactyl the same circuit and software, the only difference is the battery type. And the one with cr2032 give me very unstable battery voltage readings while the other very is stable. So for sure it depends on the battery type and the current consumption at the moment of voltage probing.

            G 1 Reply Last reply
            1
            • rozpruwaczR rozpruwacz

              @greymarvel what kind of battery are You using ? The voltage on the battery may not be constant in short periods, it depends on the load and bettery internal resistance. The higher the internal resistance the bigger are voltage swings in response to load swings. I have two identical boards, differing only in the batery holder, one is for cr2032 (higher internal resistance) and the other is for cr123 (lower internal resistance). These boards have exactyl the same circuit and software, the only difference is the battery type. And the one with cr2032 give me very unstable battery voltage readings while the other very is stable. So for sure it depends on the battery type and the current consumption at the moment of voltage probing.

              G Offline
              G Offline
              GreyLinux
              wrote on last edited by GreyLinux
              #8

              @rozpruwacz I'm using 2 AA batteries . I think it might be worthwhile me using @Yveaux vcc library as a reference and see if that improves things. Also I think I might delay a little longer before the read to allow it to settle more after the contact interrupt .

              rozpruwaczR 1 Reply Last reply
              0
              • G GreyLinux

                @rozpruwacz I'm using 2 AA batteries . I think it might be worthwhile me using @Yveaux vcc library as a reference and see if that improves things. Also I think I might delay a little longer before the read to allow it to settle more after the contact interrupt .

                rozpruwaczR Offline
                rozpruwaczR Offline
                rozpruwacz
                wrote on last edited by
                #9

                @greymarvel AA batteries should have much lower internal resistance, so I guess that voltage reading should be stable. Good luck finding the problem :)

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

                  try adding a little ceramic cap on vcc or near the analog pin you are reading from.

                  G 1 Reply Last reply
                  0
                  • gohanG gohan

                    try adding a little ceramic cap on vcc or near the analog pin you are reading from.

                    G Offline
                    G Offline
                    GreyLinux
                    wrote on last edited by
                    #11

                    @gohan 0_1522146871766_IMG_20180327_113328.jpg

                    This is how it looks I know it's a little messy but a little cap between the high impedance point and A0 will help ?

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

                      are you using a voltage divider on pin A0? if so, a small 0.1uF ceramic should do. If you are using a booster is your only option. In addition you can also consider using a single LiFePO4 battery and use the vcc library to get battery voltage

                      G 1 Reply Last reply
                      0
                      • gohanG gohan

                        are you using a voltage divider on pin A0? if so, a small 0.1uF ceramic should do. If you are using a booster is your only option. In addition you can also consider using a single LiFePO4 battery and use the vcc library to get battery voltage

                        G Offline
                        G Offline
                        GreyLinux
                        wrote on last edited by
                        #13

                        @gohan yeah it's hard to see but the black wire behind all the radio wires goes to A0 from the divider. I'll put a little cap on this .

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

                          You may also consider some Easy Pcb you can find on openhardware.io that would make a much cleaner solution for your node

                          G 2 Replies Last reply
                          0
                          • gohanG gohan

                            You may also consider some Easy Pcb you can find on openhardware.io that would make a much cleaner solution for your node

                            G Offline
                            G Offline
                            GreyLinux
                            wrote on last edited by
                            #15

                            @gohan yeah I have some on order. I'm just learning with what I've got till they come and the sensors I've made won't be seen so not a problem for the moment . Thanks again .

                            1 Reply Last reply
                            0
                            • gohanG gohan

                              You may also consider some Easy Pcb you can find on openhardware.io that would make a much cleaner solution for your node

                              G Offline
                              G Offline
                              GreyLinux
                              wrote on last edited by GreyLinux
                              #16

                              @gohan well adding a cap from the impedance point to A0 has 100% stabilized my readings

                              4630 MCO:SLP:WUP=-1
                              4632 TSF:TRI:TSB
                              4634 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                              4638 TSF:TDI:TSL
                              4640 MCO:SLP:WUP=1
                              4642 TSF:TRI:TSB
                              Sensor value: 862
                              Battery Voltage: 2.78 V
                              Battery percent: 13 %
                              4751 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
                              4759 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                              4763 TSF:TDI:TSL
                              4765 MCO:SLP:WUP=-1
                              4767 TSF:TRI:TSB
                              4769 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                              4775 TSF:TDI:TSL
                              4777 MCO:SLP:WUP=1
                              4780 TSF:TRI:TSB
                              Sensor value: 863
                              Battery Voltage: 2.78 V
                              Battery percent: 13 %
                              4886 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
                              4894 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                              4898 TSF:TDI:TSL
                              4900 MCO:SLP:WUP=-1
                              4902 TSF:TRI:TSB
                              4904 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                              4911 TSF:TDI:TSL
                              4913 MCO:SLP:WUP=1
                              4915 TSF:TRI:TSB
                              Sensor value: 862
                              Battery Voltage: 2.78 V
                              Battery percent: 13 %
                              5021 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
                              5029 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                              5033 TSF:TDI:TSL
                              5036 MCO:SLP:WUP=-1
                              5038 TSF:TRI:TSB
                              5040 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                              5046 TSF:TDI:TSL
                              5048 MCO:SLP:WUP=1
                              5050 TSF:TRI:TSB
                              Sensor value: 862
                              Battery Voltage: 2.78 V
                              Battery percent: 13 %
                              5156 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
                              5165 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                              5169 TSF:TDI:TSL
                              5171 MCO:SLP:WUP=-1
                              5173 TSF:TRI:TSB
                              5175 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                              5181 TSF:TDI:TSL
                              

                              however a multi meter gives me 2.90v and the reading is 2.78v i understand it wont be 100% accurate but this far out is a little weird my other sensors are about 1 or 2 volts if that . any ideas?

                              rozpruwaczR 1 Reply Last reply
                              0
                              • G GreyLinux

                                @gohan well adding a cap from the impedance point to A0 has 100% stabilized my readings

                                4630 MCO:SLP:WUP=-1
                                4632 TSF:TRI:TSB
                                4634 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                                4638 TSF:TDI:TSL
                                4640 MCO:SLP:WUP=1
                                4642 TSF:TRI:TSB
                                Sensor value: 862
                                Battery Voltage: 2.78 V
                                Battery percent: 13 %
                                4751 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
                                4759 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                                4763 TSF:TDI:TSL
                                4765 MCO:SLP:WUP=-1
                                4767 TSF:TRI:TSB
                                4769 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                                4775 TSF:TDI:TSL
                                4777 MCO:SLP:WUP=1
                                4780 TSF:TRI:TSB
                                Sensor value: 863
                                Battery Voltage: 2.78 V
                                Battery percent: 13 %
                                4886 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
                                4894 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                                4898 TSF:TDI:TSL
                                4900 MCO:SLP:WUP=-1
                                4902 TSF:TRI:TSB
                                4904 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                                4911 TSF:TDI:TSL
                                4913 MCO:SLP:WUP=1
                                4915 TSF:TRI:TSB
                                Sensor value: 862
                                Battery Voltage: 2.78 V
                                Battery percent: 13 %
                                5021 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:0
                                5029 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                                5033 TSF:TDI:TSL
                                5036 MCO:SLP:WUP=-1
                                5038 TSF:TRI:TSB
                                5040 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                                5046 TSF:TDI:TSL
                                5048 MCO:SLP:WUP=1
                                5050 TSF:TRI:TSB
                                Sensor value: 862
                                Battery Voltage: 2.78 V
                                Battery percent: 13 %
                                5156 TSF:MSG:SEND,4-4-0-0,s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=OK:1
                                5165 MCO:SLP:MS=5,SMS=0,I1=255,M1=255,I2=255,M2=255
                                5169 TSF:TDI:TSL
                                5171 MCO:SLP:WUP=-1
                                5173 TSF:TRI:TSB
                                5175 MCO:SLP:MS=0,SMS=0,I1=1,M1=1,I2=255,M2=255
                                5181 TSF:TDI:TSL
                                

                                however a multi meter gives me 2.90v and the reading is 2.78v i understand it wont be 100% accurate but this far out is a little weird my other sensors are about 1 or 2 volts if that . any ideas?

                                rozpruwaczR Offline
                                rozpruwaczR Offline
                                rozpruwacz
                                wrote on last edited by
                                #17

                                @greymarvel check the actual values of the resistors in voltage divider how far they are from the nominal values. Resistors have some tolerance so they are not exactly 1kOhm or whatever, this makes the division ratio different than You take into account calculating voltage from ADC reading.

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

                                  also the internal reference is not 100% accurate, so you can't have a multimeter precision. There is a battery measurement code that you can add some correction to it, look into the examples

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    GreyLinux
                                    wrote on last edited by
                                    #19

                                    @rozpruwacz I've checked the values and they don't seem to be that far from expected but as you say they definitely weren't the stated resistance . I think @gohan is right I will add the correction in the sketch and try and get it reasonably close. Thanks again everyone for your help .

                                    1 Reply Last reply
                                    0
                                    • BulldogLowellB Offline
                                      BulldogLowellB Offline
                                      BulldogLowell
                                      Contest Winner
                                      wrote on last edited by
                                      #20

                                      As the analog pins share a single A2D, rapid use of it can cause the previous read to impact the next. A common workaround in this situation is to read twice on each input, ignoring the first.

                                      try that:

                                      // read analog pin
                                        (void) analogRead(BATTERY_SENSE_PIN);
                                        int sensorValue = analogRead(BATTERY_SENSE_PIN);
                                        // calculate battery voltage
                                        float vBat  = static_cast<float>(sensorValue * (V_MAX/1023));
                                      
                                      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