The world of electronics has always been vibrant as many exciting new devices and circuits getting added to the overflowing number of devices. Many devices are getting replaced often with the advancement of technology. There are several devices which have proven themselves to be irreplaceable as they have been found quite convenient for different applications. Light emitting diode is such a device and this chapter deals with various aspects of interfacing an LED with a PIC microcontroller.
What is an LED
An LED is basically a p-n junction diode which emits light energy when adequate voltage is given. Light emitting diodes (LED) are basic display units in electronics world. It has found its way to the low power display systems recently. It is the most commonly used indicator lights in all the applications. Ever since it’s wide spread use as reliable electronic component, LEDs have been ruling the electronic arena as no other similar technology has ever replaced them.
LED bulbs are available in different colours. Earlier LEDs made use of the infra-red wavelength and such LEDs are used even these days in remote-control circuits. LED bulbs making use of the ultra violet wavelength is also available in the market.
As discussed earlier, LEDs are present in many electronic devices including lamps, digital clocks and incandescent bulbs. A very popular application of LED is a seven segment display system. The advantages of LEDs over normal incandescent lights include robustness, faster switching, lower energy consumption and small size.
There are two technical specifications that should be taken into account while interfacing an LED. There are other specs like luminous intensity, dominant wavelength, operating temperature etc. Other specifications can be ignored while designing the circuit.
- Peak forward current
- Continuous forward current
- Forward voltage
- Reverse voltage
Peak forward current
The current above maximum forward current’s limit may damage the LED. For red LED, peak forward current is 100mA. Use the datasheet to find these rating.
Continuous forward current
This is optimum current required by the LED, we use this current in our designing process.
It is the voltage required by a diode to turn it on. This voltage range is 1.8 – 2.2V for red/orange/yellow LEDs, green/blue/white LEDs have a forward voltage of around 3.4V.
This voltage indicates how much voltage you can give in reverse direction before it get blown.
Current passing through the LED should be limited to maximum forward current (IF). For this, a resistor is used. To find the value of this resistor, we use the forward voltage and forward current.
We design a circuit with 5V supply and forward current of 20mA. We use a red LED here.
R = (5 – 2)/20mA = 150 ohms
LED interfacing with PIC
Now we know how to design a circuit for LED. This circuit can be used to interface with PIC microcontroller. One of the technical specifications to be taken in account is the current which can be sourced from a microcontroller pin (maximum pin Source current = 25mA for PIC18F4550). It should be more than what we are using. Datasheet will provide this information.
In this case, it is safe to assume that 20mA of current can be sourced from the microcontroller.
Now the firmware part,
Set the port as output.
TRISBbits.TRISB0 = 0; // Set RB0 as output
Toggle the port bit and give a delay in between the operation to give a blinking effect.
PORTBbits.RB0=1; // set High
delay_ms(500); // delay of 500ms
} while(1); // infinite loop
We’ve done a basic circuit, it is sufficient to work most to the time. The current is sourcing from the microcontroller. In this case, we are driving only the LED, there is no need of concern. But as the number of modules used in application increases, the current driving may not be sufficient. To solve this, we use external current drivers.
External current driver circuits can be designed based on our requirements or we can use current driver ICs.
Current driver IC
When using LEDs in displays and other illuminating applications, we need predictable and matched luminous intensity from every LEDs. Also we need to make sure that the current should be always in the optimum ratings. In order to achieve this, we need to use constant current drivers.
There are many current driver chips available in market. One of the commonly used chips is ULN2003. It is a Darlington pair based current driver which is capable of 500mA current output. LED drivers with PWM capability are also available in the market with brightness controlling capability. CAT4101 from ONSEMI is an example for this.