Problem with analog read

I have attached a diagram showing how I am using an Electron with a NEO-M8N connected.

The Electron is powered by an external power supply providing 12vdc/2A via Vin. The NEO GPS module is powered off the 3.3 pin and I am monitoring the supply voltage via A0 through a voltage divider. The sketch writes a value to Blynk app with this code

Blynk.virtualWrite(V5, map(analogRead(batPin), 0, 4095, 0, 14)) ;

and prints a value to serial monitor with this

Serial.println(map(analogRead(batPin), 0, 4095, 0, 100));

When the USB is connected to read serial prints I see 100 on the serial print out and 14 on the value widget of Blynk. When the USB is disconnected and the device is only powered by the external power supply, the value of A0 bounces all over the place in the value widget on the app. It seems to act up when the LiPo calls for a charge. I can see the current change on the power supply from roughly 200mA to 360mA when this happens.Why would the reading on A0 change even though the external power supply is providing a constant voltage? I am not sure what I am missing here. Any help is appreciated.
Thanks

What kind of power supply?

Depending on the quality of the power supply, you may be getting some ripple. Can you scope its output?

@BulldogLowell Thanks for the reply. Its nothing great, Lavolta DC Power Supply BPS-305.

Unfortunately I do not have an scope.

Thanks

The power supply will try to to supply a constant voltage but when there are sudden current demands such as 3G or charging the voltage will drop and then recover.Depending on just how ropey the regulation and smoothing is inside your power supply that could be a culprit. When the USB is connected it is providing an extra stable supply so no sudden demands are made on your 12V supply so it stays steady. I would suggest however that perhaps your LiPo is flat as it should be handling the peaks demands made by the 3G module for you. You could stick an electrolytic across the 12V to help out.

On another note it is highly unlikely the Lavolta power supply is capable of delivering the power it claims to be rated at, looking at pictures from an Amazon review I simply don’t think its big enough, a branded 30V 5A Lab power supply is a big and expensive beast.

@Viscacha thanks for your reply. This project will eventually be mounted in a vehicle and therfore not be exposed to AC ripple caused by using an AC/DC power supply.

I still see the current change on the power supply even when the USB cable is plugged in, when the LiPo charge LED comes on. So, LED charge light OFF, 20mA. LED charge light ON, 28mA. However with the USB cable attached, the widget value stays constant at 14.0V even during the charge/no charge status of the LiPo.

So what is even more bizzare to me is that I am monitoring 12V power on A0 yet when I plug in the USB I now read 14V on the value widget. Even if I read a float by using

float voltage = map(analogRead(batPin), 0, 4095, 0, 140);
Blynk.virtualWrite(V5, voltage/10);  

The results are the same. I guess I am not seeing the forest for the trees.

I am not opposed to this idea. What value capacitor should I use? I have no idea how to calculate that. Would I also need a linear voltage regulator to feed the capacitor filtered signal through?[quote=“Viscacha, post:4, topic:37122”]
On another note it is highly unlikely the Lavolta power supply is capable of delivering the power it claims to be rated at, looking at pictures from an Amazon review I simply don’t think its big enough, a branded 30V 5A Lab power supply is a big and expensive beast.
[/quote]

I agree with both points but I am only consuming less then 300mA. I wouldnt think that would be insurmountable even for this cheap suplly.

Thank you

The electron has some pretty peaky current demands (2A) according to its datasheet, they may well be too short to be reflected on your PSU display or multimeter.

There is a suggested value for a cap to use when there is no LiPo in the datasheet, could do worse than to simply use something close to that, or whatever is in your rummage box. I wouldn’t think you’d need a regulator for your test setup but I would give serious thought to having some step down or separation between your cars 12V and the electron.

Noted

Thanks for the suggestion

Noted as well. Thank you again for your time and suggestions