Monthly Archives: February 2013

Calculating correct resistor value to protect Arduino pin

Ohms Law

Once of the important things to do when you play around with electronics is to make sure that you are safe-guarding your electronic components from over current.

The most common way to do that is by adding a resistor in series. You can calculate the value of the resistor needed for safe operation by using Ohm’s law.

But, when I was getting started with electronics and Arduino, I always found it difficult to understand how a particular value of resistor is recommended in tutorials, even though you will be getting a different value when you try to apply Ohm’s law yourself.

It took me quite sometime to understand the logic behind it and I thought of explaining it here, so that it is helpful for people who are also just getting started.

Protecting Arduino Pin from over current

Let’s consider the simple Blink example in Arduino. This is most probably the first program you might have tried when you are getting started with Arduino.

If you look at the circuit, you will find that you are asked to connect a 220 Ohm resistor in series to protect the Arduino pin and the LED. But it is not mentioned how or why this value is chosen.

Now let’s try to calculate the value ourself. You need to be familiar with Ohm’s law, if you are not, then read this excellent tutorial by Evil Mad Scientist, which explains the whole concept very clearly.

If you have read the above tutorial, you will now know that a typical red LED has a voltage drop of 1.8V and a current of about 25mA. The Arduino Pin has an output voltage of 5V.

Let’s use these values in our calculation.

V = (power source) – (voltage drop) = 5V – 1.8V = 3.2 V
I = 25 mA

We need to find R.

R = V/I

Substituting the values, you will get

R = 3.2/0.025 = 128 Ohms.

We need to use 128 Ohm resistor, but the tutorial asks us to use 220 Ohm, which is almost double.

Practical easiness over theoretical correctness

It took me quite sometime to figure out why 220 Ohm is recommended over 128 Ohm.

It is an apt example of choosing practical easiness over theoretical correctness. Engineers being practical people always prefer practical solutions over theoretical ones 😉

If you try to buy resistors from a local hobby shop, you will find that the resistors are available in the following values.

{ 100, 220, 470, 1000, 2200, 4700, 10000 }

These are the standard values and are easier to find rather than other values.

If you look at the values, you will find that 100 Ohm is less than 128 Ohm (that we calculated) and is quite risky. The next higher easily available value is 220 Ohm.

When you substitute R=220 in the equation I=V/R

I = V/R
I = 3.2/220 ~= 14mA

You will get the value of the current to be around 14mA. LED’s operate between 10-25mA. Also, since LED’s are non-linear devices, the difference in the current from 14mA to 25mA doesn’t necessary mean a proportional difference in the brightness. In most cases, you may not even be able to tell the difference.

So, choosing 220 Ohm instead of 128 Ohm is purely because of practical easiness. If you have bought a getting started kit with Arduino or a pack of assorted set of resistors, you are more likely to find a 220 Ohm rather than 128 Ohm.

As, I mentioned before, the Blink example is most probably the first circuit that people are going to try and if you ask them to use a non-common resistor, then most probably they are not going to find it and might stop right there itself, instead of going forward. And that’s the reason why they have recommended 220 Ohm.

Arduino, being a platform for beginners, it is perfectly fine that they tried to simplify things for you. But once you start to grasp things, you might have to dig deeper to understand why a particular circuit or sketch is build in a certain way.

Happy hacking 🙂