You would think a resistor is a resistor is a resistor, and picking one for use with Arduino is simple.
Not necessarily – so here are a few factors to keep in mind when resisting current in an Arduino circuit:
- A resistor, well, resists current flow. Left to itself, current will flow as much as possible, eventually heating up (and even melting) wires in the process. Since many Arduino circuits are in one way or another connecting 5 volts to ground, you are asking to keep the current in the loop within reason – hence the resistor.
- For example, each pin of the Arduino can handle a maximum of 40 milliamps (abbreviated mA). However, everyone recommends no more than 20-30mA per pin to be safe (running any electrical device near its limits is just asking for premature aging and failures). If you connected a pin to ground and then wrote out on it with a digitalWrite() command, you would be sending current to ground almost completely unimpeded. Without a resistor, it would go too high, and the chip would fail (or at least the pin). So picking the right resistor to manage current is key.
- Voltage, current and resistance work together according to Ohm’s Law, which states that V (voltage) is equal to the resistance (R) multiplied by current (I – which stands for the French “intensité de courant” and named by Ohm himself). In this case, we know the voltage (5 volts) and maximum current (say, 30 milliamps, or 0.030 amps, since the scaling units have to match); using the variation of Ohm’s law to give us resistance, we get:
V = R * I, or solved for R, R = V / I
R = 5 volts / 0.030 amps
R = 167 ohms
So, as long as there is an 167 ohm resistor in line, the current cannot go higher than 30 mA, and our circuit is safe. Right?
- Yes, but remember, this value includes other items in the series circuit. So for example, if you are connecting a 32 ohm speaker to an Arduino pin, you’d want to subtract that from the minimum of 167 ohm total, meaning you now only need an extra 135 ohm resistor.
- As well, resistors also have a wattage rating. For that, we us another formula: P (power, in watts) is equal to I (current) times V (voltage). So then our original 167 ohm resistor ‘uses up’ how many watts?
P = I * V
P = 0.030 amps * 5 volts
P = 0.150 watts
or about 1/6th of a watt.
So in this case, a 1/4 watt resistor would work fine. But what if the resistor was 1/8 watt (0.125 watts)? In that case, it would be too much for the resistor, and it would likely burn up. So this calculation makes sure you don’t go wrong with picking the wattage of resistors.
- Of course, even wattage has its issues. For example, some recommend keeping some ‘head room’ with the resistor; in this example, using a 1/2 watt instead since 0.150 watts is getting in range of the limit of 0.250 watts. It’s your choice, but something to keep in mind as you build circuits. However, since 167 ohms is the lowest you can safely go in a circuit to keep the current down below 30 mA, and it is possible to use a 1/4 watt even there, there should be very few occasions you’d need to go higher, wattage wise, in a typical circuit.
- Another issue with resistors is they have ‘tolerance’ – resistors can have variations like (commonly) 5, 10, and 20% tolerance on them. What this means is that a typical resistor can vary by as much as this value and still be considered properly manufactured. So if you happened to pick a 220 ohm resistor with 20% tolerance, it could in theory be as low as
220 - 20% (or 44) = 176 ohms
Which would put it pretty close to our limit.
- Finally, not all values of resistors are available. You have to pick the ones that you have access to. For example, there is no 167 ohm resistor, but there are 150 ohm and 220 ohm ones. Which you use is up to you and your needs.
By the way, have you ever wondered why you can find a 220 ohm resistor easily, but not a 200? Called preferred numbers, or E Series, these are values picked to offer the best range between two values (in this case, between 1 and 10). So the E6 series provides 6 values between 1 and 10 that are within 20% of each other, more or less:
E6 Series: 10 15 22 33 47 68
Where 10 ohms + 20% is close to 15 ohms – 20%, 22 ohms + 20% is close to 33 ohms – 20%, and 68 ohms +20% is close to 100 ohms (the next step up) – 20% and so forth.
There’s also the E12 and E24 series, which get closer together (10% and 5%):
E12 (10%): 10 12 15 18 22 27 33 39 47 56 68 82
E24 (5%): 10 12 15 18 22 27 33 39 47 56 68 82 11 13 16 20 24 30 36 43 51 62 75 91
And of course these values repeat as they increase in value throughout a range: For example, the E6 series would be 10, 15, 22, 33, 47, 68, 100, 150, 220, 330, 470, 680, 1000, 1500, 2200, 3300, 4700, 6800, and so on, repeating as they increase.
The goal for each is to be able to cover the whole range of resistances, or get as close as possible.
So in summary here’s how to pick a resistor:
- Figure out the maximum current you want in your circuit.
- Do the math to figure out the lowest resistance.
- Subtract the resistance of other parts in series in the circuit.
- Check the charts to get the lowest ‘preferred value’ to use.
- Reduce it by the percentage tolerance and move to the next higher one if too low.
This should help you get started – at the very least, you’ll be able to make sure you aren’t risking a burned Arduino pin!