In this article, we briefly describe how to interface LEDs and electromechanical relays to microcontrollers. Note, a detailed description on how this is done can be found in the official documentation of the microcontroller you are working with. Here, we only look at the fundamentals on how this is done.
Contents
The commonly used configuration to connect an LED to a microcontroller is illustrated in Figure 1.0 below. The LED glows when the microcontroller pin is driven LOW and OFF when the pin is set HIGH. The LEDs are connected in this manner as the current-sinking capability of microcontrollers is of the order of a few tens of milliamperes and the current-sourcing capability is of the order of microamperes. The resistor is used to limit the current through the LED.
The value of the resistance is selected as per the equation below:
R = (VCC – VLED)/I
Where VLED is the voltage across the LED and I is the current.
The typical values of VLED and I are 1.5 V and 20 mA respectively.
If the current-sourcing capability of the microcontroller is sufficient to drive the LED directly, then LED is connected to the microcontroller as shown in the figure below. The LED in this case glows when the microcontroller pin is set HIGH.
The figure below shows the typical connection diagram for interfacing an electromechanical relay to a microcontroller.
The NPN transistor is used to provide the desired current to the relay to the relay coil as the microcontroller cannot drive the relay directly. The freewheeling diode is required as the current through the inductor cannot be instantaneously reduced to zero. When the microcontroller pin is set HIGH, the transistor is switched ON. Current flows through the relay coil and the contact is closed. When the microcontroller pin is LOW, the transistor is switched OFF and the inductor current now flows through the freewheeling diode and slowly decays to zero value.
Related articles:
The world of electronics is constantly evolving, allowing designers and manufacturers to push the boundaries…
PIC microcontrollers are fabricated by Microchip Technology. PIC16C84 and PIC16F84 are the two microcontrollers in…
The ADD instruction tells the microcontroller’s CPU to add the source byte to register A…
8-bit microprocessors are limited in their speed (the number of instructions that can be executed…
The 68HC11 (also abbreviated as 6811 or HC11) is an 8-bit microcontroller that was introduced…
Mutual exclusion typically imposes some conditions on access to a given resource by two or…
View Comments