lunar accents logo
LED circuits

website index terms and conditions help
home design applications technology educational getting-started company products

Direct Driving LEDs from Microcontroller Pins

inquire about articleprint articlefeatured articlesupdatesrequest-article

Driving an LED directly from an output pin on the microcontroller can minimize support components, such as an external MOSFET. Due to voltage and current limitations, one must must construct the controller circuit with great care.

LED Voltage and Current

With the correct current and voltage, it would be possible to drive an LED directly from the output pin on a microcontroller. The microcontroller pin will not supply a constant current, so some type of current limiting device must also be installed in series. When calculating the voltage, do not forget about the voltage drop across this device. Since most microcontrollers operate on low voltages between 3 to 6 volts, do not expect to include more than one white or blue LED per pin, or two red LEDs, since they tend to have a much lower forward voltage drop. If the microcontroller data sheets state a 75mA sink current per pin, this does not necessarily mean it would be a good idea to drive an LED at this level. The microcontroller may contain a maximum current that applies to the package, which includes current being source or sunk from all pins combined. It is important not to exceed this value, to prevent overloading within the microcontroller.

Limiting Pin Current to LEDs

A simple and inexpensive method to limit current would be through the use of a series current limiting resistor. This method may work well for low current applications, but is not recommended when sourcing or sinking more than 20mA on a specific pin. For drive currents greater than 20mA, a current source will offer the most reliable method of current regulation. Always avoid current sharing, as a result of two parallel LEDs sourcing current from a single component. It may be tempting to connect a single resistor in series with two parallel LEDs, and then to the output pin. Such configurations can lead to uneven distribution of current between the two LEDs, so make sure that each LED has its own dedicated current source. More advanced designs may utilize one of the A to D pins on the microcontroller as a feed back loop. The firmware can compensate for changes in voltage via a pulse width modulation routine.

Microcontroller Pin Configurations

If your circuit cosists of an LED with its cathode tied to ground, a high on the output pin would turn the LED on. It is important to make sure that your pin is configured as an output, not an input. When configured as an input the LED may flicker, or remain on continuously due to an internal pull up resistor. Always check to ensure the configuration register for pin I/O is properly configured in software. Improperly configured input pins may float, but still allow the LED to operate. This can lead to frustration and senseless troubleshooting caused by faulty software.