Home ยป Microcontrollers ยป Interfacing LEDs & Electromechanical Relays to Microcontrollers

Interfacing LEDs & Electromechanical Relays to Microcontrollers

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.

Interfacing LEDs with Microcontrollers

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.

Interfacing LED to a microcontroller โ€“connected as current-sinking
Figure 1.0 Interfacing LED to a microcontroller โ€“connected as current-sinking

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.

Interfacing LED to a microcontroller โ€“connected as current-sourcing
Figure 1.1 Interfacing LED to a microcontroller โ€“connected as current-sourcing

Interfacing Electromechanical Relays to Microcontrollers

The figure below shows the typical connection diagram for interfacing an electromechanical relay to a microcontroller.

Interfacing an electromechanical relay to a microcontroller
Figure 1.2 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.

Please follow us and share:

Comments

One response to “Interfacing LEDs & Electromechanical Relays to Microcontrollers”

  1. […] Interfacing LEDs & Electromechanical Relays to Microcontrollers […]

Leave a Reply

Currently trending: