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


                          12

                          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