Go Down

### Topic: To determine via sw if mkr1000 is powered by 5V usb or battery 3.7 V (Read 1 time)previous topic - next topic

#### squizzato

##### Dec 02, 2016, 09:20 pm
Hello!
I read 4 pages back of topics and I don't find any discussion on the point. Sorry if I miss it.

Is there any sw/lib solution already out? Or should I connect one analogue pin to Vin via resistor to avoid to damage the input of this analogue pin?

Thx

#### dy3dy3dy3

#1
##### Dec 14, 2016, 06:04 am
You should read the five volt pin of the MKR1000, not the Vin.  There is only 5 volts on the pin when a usb is plugged in.

#### squizzato

#2
##### Dec 18, 2016, 09:30 pm
ok thx dy3dy3dy3

I'll do that. Since I don't see any other help I presume noway via anylib...

#### sturla_78

#3
##### Aug 27, 2018, 12:34 am
Hello,
What is the correct way to read the 5V pin via sw?

Thanks for help

#### ballscrewbob

#4
##### Aug 27, 2018, 02:58 am
@sturla_78

Via a simple voltage divider calculated for 5 volts (google voltage divider)
You would simply need to set an upper and lower limit and when one is reached branch your sketch to another function.

EG. sudo code.

If volts = 3.5 then warning.

Check the Analog read serial example for a basis on which to work.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

#### sturla_78

#5
##### Aug 27, 2018, 10:20 am
Thanks again ballscrewbob,
May be that i have understood. I can read 5V pin divide by a voltage divider (the voltage must be minor of 3.3 for not damage mkr) for example if the final division is 2.5:

If volt > 2.2 usb connected
If volt < 2.2 battery connected

Could work this logic?

Thanks

#### ballscrewbob

#6
##### Aug 27, 2018, 02:05 pm
Yes 3.3 volts !

That was a mistake on my part glad you spotted it phew.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up