Battery percentage on door contact sensor erratic (sent on interrupt)
-
@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.
-
@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.
@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 .
-
@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 .
@greymarvel AA batteries should have much lower internal resistance, so I guess that voltage reading should be stable. Good luck finding the problem :)
-
-
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
-
You may also consider some Easy Pcb you can find on openhardware.io that would make a much cleaner solution for your node
-
You may also consider some Easy Pcb you can find on openhardware.io that would make a much cleaner solution for your node
@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:TSLhowever 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?
-
@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:TSLhowever 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?
@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.
-
@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 .
-
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));
