In this video we’ll calculate the value of the resistor we need in series with an external LED to connect it the Arduino. We then check the LED brightness and we can fine tune the resistor value to get the visual result we want.
No … that model rail layout on the picture is not mine. I wish it was. 🙂
A diode is an electrical component with the characteristic that a current can only flow in one direction … in the other direction the current is blocked. The schematic symbol is an arrow that symbolizes the direction of the current and a line that symbolizes the block.
Diodes have many uses in electrical circuits. A well known application is the ‘bridge rectifier’, where 4 diodes are used to turn an AC source into a DC current. And there’s this special kind of diode that emits light when a current flows through it, not surprisingly called a Light Emitting Diode, or LED for short.
LEDs are great to play with to hobbyists and modelers. They come in different colors and sizes and they find their way into switch panels, in user interfaces, in DIY robotics or in the trains, cars, houses, street- and traffic lights of a model railway layout. They are very easy to connect to an Arduino and to control with software. Current flows from + to – , the long wire of a LED is the plus.
It’s not a good idea to connect a LED directly to our Arduino. It behaves as a short circuit, we would most probably blow up the LED, or the output pin, or both. The proper way to connect a LED is with a resistor in series. The resistor limits the current.
The LED and resistor can be connected to the Arduino in two ways. It does not really matter which way we use, we can control in the software when the LED is on. In this diagram pin 8 must be HIGH, pin 9 must be LOW. I prefer to connect the LED and resistor to GND, then HIGH is ON … this feels more intuitive.
When a current flows through a LED, there’s a voltage drop over its terminals. This voltage drop is nearly independent on the current, but it differs per LED color.
The voltage that is left over our resistor equals 5 – Vled. For example with a red LED this will be approximately 3.2V, with a green LED 1.5V.
We can use Ohm’s law to calculate the resistor value R, once we decided how much current [ I ] we want to have. On a side note: you may wonder why is the symbol used for current I, and not A, from the unit Ampère? That’s because Ampère was a Frenchman, in his publications he used the term ‘intensité du courant’, hence the I.
How much current do we need / want? First of all, don’t exceed 20mA on any output pin or we run the risk of burning them. Luckily 20mA is more then enough for most miniature LEDs. It might even light up too bright. Some LEDs are super bright and need just 1mA or less. Usually I take 10mA as a starting point and then check if I like the brightness.
Let’s use a red LED and let’s aim at 10mA. We calculate R to be: 3.2 / 0.01 = 320 Ohm. That is not an existing value, but 330 is … so let’s start with R = 330 Ohm and see how bright the LED burns when connected to 5V.
It looks OK. We can now modify the code we made in video 2. The plan is to make it better readable and better maintainable. And we imagine the LED to represent street lights on a model railway layout … we want it to burn for 3 minutes after we pressed the button to simulate night time.
By the way … if you like to play along, you might like to acquire some of the electrical components that we are going to use in the videos to come, like:
- an Arduino Uno (and if you don’t have one already, a USB cable that fits into the Arduino)
- a breadboard
- a range of resistors in all kinds of values
- a couple of LEDs
- a breadboard
- some switches or push buttons
- ‘Dupont’ wires Male-Male, Male-Female, Female-Female
- 2 servo motors
- 2 optical sensors
- a sound sensor
- An Infrared (PIR) sensor
- a temperature & humidity sensor
- one or more relays
- Power FET module
- or maybe most of the above in one handy Arduino Starter Kit
— 0 —