How to read the voltage on pin VIn

How can i get the voltage on pin VIn?
I am using an electron and i want to detect the voltage on Vin so i can publish it.

Fuel.getVCell gets the voltage of the small 3.7V lipo plugged into the Electron, but I need to know the voltage on Vin because I am supplying it with 5V from a solar backup battery.

The PMIC must know the voltage on VIn because it decides when to use what input for charging, however the documentation on the PMIC is incomplete, it doesnt explain how we can extract this from its registers.

I could also power the Electron off the USB and measure that voltage, but I dont see any way of reading that voltage either.

It’s not possible to read a voltage value from the bq24105.

The reason is that the bq24105 doesn’t use an ADC to read the value and decide whether to use VBUS or battery, it uses a DAC to generate a reference voltage and uses a comparator.

You can use a voltage divider and connect VIN to an unused Electron analog input. Make sure you use a voltage divider since the maximum voltage on an analog input is 3.3V, not 5V.


You can also read the input voltage and current if you add a INA219 voltage / current sensor to the mix.

1 Like

Thanks RWB and thanks for your tips on solar, I am building a river water level monitoring system for our kayaking club so we know which rivers to visit on the weekends!

Sounds cool!

Be sure to share here once you get it up and running :slight_smile:

1 Like

my challenge is the lidar sensor needs 4-6v it doesn’t work when powered from the 3.7 lipo, so i will use an external 5v supply which will also charge the electron.

I have put the lidar power supply on a mosfet to turn it off .

Currently using 4xAA re-chargeables which I will also connect to a PV.

I tried your code to check battery levels before turning on the celluar, I got myself in knots trying SEMI_AUTOMATIC mode so I’m using full AUTOMATIC, but before going back to sleep, I check battery level and if its below certain levels I tell it to sleep for longer.

My problem is I also need to monitor the voltage of the 4xAAs because that is more representative of available power.

Everything has to be extremely small and discreet because it will be glued underneath a bridge over the river, and the kids in those areas will steal it or destroy it for fun if they notice it!

The rivers are about 4 hours away so once installed, thats it! It better work!!

I would stick with a LiPo and just boost the battery voltage to 5v using one of these converters with super low standby and sleep current of only 1uA.

Just put the regulator to sleep by pulling a PIN low when it’s not needed.

1 Like

I thought of that and I have something similar at hand, I will try it, do I connect it to the 3.3V pin on the electron or wire it in to the LiPo?

The lidar draws about 0.1A.

Do I just connect the PV to VIn?

I would connect the boost regulator to the Li input pin which connects to the LiPo battery directly.

Then make sure you use a pin to put the regulator to sleep when it’s not being used and make sure your regulator is like the one I linked to that only consumes 1uA when disabled to prevent excessive battery drain.

You do connect the PV to the Vin pin.

1 Like

I dont think mine have that sleep pin, no worries I can control it with my mosfet.

That should be fine, especially if your solar charging daily.

we will be charging in the morning only because we can only look at the sun from one side of the bridge.

That should be fine if your sleeping most of the time and use a 3w or so sized solar panel.

1 Like

You can also use the PMIC().isPowerGood() function to get a general go/no-go result on if there is voltage on VIN, specifically if it’s above 3.8V.

You can easily measure the voltage on the Vin pin and publish it. I made a 10:1 voltage divider using a pair of 18k ohm 1% resistors in parallel connected between Vin and A1 and a single 1k ohm 1% resistor connected from A1 to Gnd. This works great for measuring the external voltage. Just multiply whatever value you get by 10.


Thanks I will build that, i implemented the PMIC.isPowerGood already , the voltage divider will work well.