Digital Input Voltage

Hi guys,

I am seriously stumped on this one. Its hopefully an easy one to answer. I need to detect a voltage of around 14v from an external source using the arduino’s digital inputs.

My question is will I need a voltage divider or can I just use a resistor?

If the maximum input current is 40mA at 5v can I just use ohms lay like so:

I: 10mA (max 40),
V: (14v - 5v) = 9V (across the resistor)

R = 9/0.01 so
R = 900 Ohm??

Or is this rubbish and should I actually be using a voltage divider? If so why?

I need to get a better understanding of how to manage this type of decision and calculation. Can anyone recommend to me any sites that may help me.

Thanks in advance,


Or is this rubbish and should I actually be using a voltage divider?

yes and yes.

It is rubbish because you make the assumption:- If the maximum input current is 40mA, this is output current, the input current is very very small.

A voltage divider is the way to go. The 40 mA is irrelevent, the arduino’s input impedance is in the order of 100 mo, the current flowing into the input pin is measured in nanoamps (1000 th of a microamp. Virtually any value of single resistor will have no or next to no impact on the voltage reaching the pin.

Thanks Guys,

I have been reading up on how to calculate voltage dividers and I'm not getting anywhere. I can't understand how to calculate the first resistor in order to get the rest. People keep mentioning the load resistance and the loads maximum current. Is this even relevant with this sort of input? I can't seem to get a foothold on this. In order to calculate the values I need to know at lease one of them first. At what point do I start the calculation?

Can anyone help or even direct me to something that will help. I am checking Google but I think I'm missing something fundamental?


Usually a useful first-stop:

Ignore the load impedance of the AVR's input - for all practical purposes it is neglible.

I can't understand how to calculate the first resistor

This is because it is the ratio of the resistors that is important not their value. So for the first one you just guess, based on how much current you want to draw.

A good starting guess is 1K because that gives you 1mA per volt current which is in the right ball park. For this sort of work anything between 1K and 10K will be fine. If that first guess doesn't give you a second resistor close to one you have or can get then guess at another value.

Thanks everyone,

Grumpy_Mike's last post answered my question. I did have an understanding of how voltage deviders work I was just confused by the fact there is no definititive answer as to what value to start with. I will be ok with this now.

Thanks again!


When using a potential divider to lower a voltage, think in terms of the upper resistor dropping the bulk of the voltage, leaving the lower resistor with the desired voltage left across it.

It's the ratio of the resistors and not the absolute values that is important.

In equation terms the voltage across the lower resistor

Vl = Rl x Vin/(Ru +Rl)

Where Ru and Rl are the values upper and lower resistors

Consider your 14V example. Lets say that we want to use the upper resistor to drop 10V, leaving 4V across the lower resistor - which is an ideal voltage for a digital input.

The resistors will drop a voltage proportional to their value, so how about a 10K to drop the 10V and a 3.9K (nearest common value to 4K) to drop the remainder?

To get a more formal calculation for how this works - you have to use Ohm's Law.

Back to your 14V example. First think of the resistors added together in series to get the total resistance i.e. 14K.

Then the current flowing through each resistor is the total voltage (14V) divided by the sum of the resistors (14K) so a current of 1mA flows through each of them. Once you know this, you can multiply this current by the resistance if the lower resistor (4K) which will tell you that it will drop 4V and the 10K will drop 10V.

Common handy ratios:

To half the voltage use resistors of equal value - say 10K and 10K

To divide by 4, make the bottom resistor say 1K, and the total = 4K, so the top resistor is 3K.

To divide by 10, the sum has to add up to 10, so make the upper 9K and the lower 1K.

As others have stated - you can ignore the leakage current drawn by the input port.

However you do have to bear in mind the power dissipated in the resistor. Many small resistors will be "quarter watt" so have a maximum power handling of 250mW. They will get hot if you get close to that power rating.

If you drop 10V across 10K the power dissipated will be 10mW. If you drop 10V across 1K the power is 100mW.

Hope the above helps.


That was the best explination I have read so far and I have read a lot today. Very helpfull thanks.

Are you sure that the voltage you want to detect will always be pretty close to 14v (or zero)?

If it goes too low, an "on" will come in as an "off". If it goes too high, beyond whatever safety margin you built in, the voltage fed into your Arduino's digital input will go above 5v (or 3.3v, if you are working with a low voltage Arduino)... NOT GOOD. (And the more you protect yourself against a possible over-voltage, the more you risk an "on" looking like an "off".)

If so, voltage divider, as explained above should work fine.

If not sure, or not sure about the whole thing, an alternative "answer", in which you can be very confident, is an opto-isolator. Even if the "14v" varies quite significantly, you will still get a nice clean "on" and "off" going to the Arduino.

Opto-isolators are cheap and easy to use... and give some protection against various design mistakes which could be costly. Explained at...