6.3 Samples LED Diodes LEDs are surely one of the most commonly used elements in electronics. LED is short for 'Light Emitting Diode'. When choosing a LED, several parameters should be looked at: diameter, which is usually 3 or 5 mm (millimeters), working current which is usually about 20mA (It can be as low as 2mA for LEDs with high efficiency - high light output), and color of course, which can be red or green though there is also orange, blue, yellow.... LEDs must be connected around the correct way, in order to emit light and the current-limiting resistor must be the correct value so that the LED is not damaged or burn out (overheated). The positive of the supply is taken to the anode, and the cathode goes to the negative or earth of the project (circuit). In order to identify each lead, the cathode is the shorter lead and the LED housing usually has a cut or "flat" on the cathode side. Diodes will emit light only if current is flowing from anode to cathode. Otherwise, its PN junction is reverse biased and current won't flow. In order to connect a LED correctly, a resistor must be added in series that will limit the amount of current through the diode, so that it does not burn out. The value of the resistor is determined by the amount of current you want to flow through the LED. This can range from 2mA to 25mA. High-efficiency LEDs can produce a very good output with a current as low as 2mA.
To determine the value of the dropper-resistor, we need to know the value of the supply voltage. From this we subtract the characteristic voltage drop of a LED. This value will range from 1.7v to 2.3v depending on the color of the LED. The answer is the value of Ur. Using this value and the current we want to flow through the LED (0.002A to 0.01A) we can work out the value of the resistor from the formula R=Ur/I. |
LEDs are connected to a microcontroller in two ways. One is to turn them on with logic zero, and other to turn them on with logic one. The first is called NEGATIVE logic and the other is called POSITIVE logic. The normal method is POSITIVE logic. The above diagram shows how they are connected for POSITIVE logic. Since POSITIVE logic provides a voltage of +5V to the diode and dropper resistor, it will emit light each time a pin of port B is provided with a logic 1 (1 = HIGH output). NEGATIVE logic requires the LED to be turned around the other way and the cathode connected to the positive supply. When a LOW output from the microcontroller is delivered to the LED and resistor, the LED will illuminate. Connecting LED diodes to PORTB microcontroller The following example initializes port B as output and sets logic one to each pin of port B to turn on all LEDs.