# PIC32 Tutorial – Part 6 – Adding an LED

Josef van Niekerk" rel="author">Josef van Niekerk

Lets connect an LED to pin 2, which we will program in the next part, to do some blinking. Insert the LED with it’s positive lead towards pin 2, and the negative towards ground. The negative lead is the one at the flat edge on the plastic casing of the LED. Add a 330Ω series resistor between the LEDs’ negative leg and ground.This resistor helps to limit the current through the LED, to avoid us turning it into charcoal, or damaging the pin. LEDs don’t like a lot of current, keeping to at or below about 20-30mA should keep it smiling bright.

[latexpage]

Lets connect an LED to pin 2, which we will program in the next part, to do some blinking. Insert the LED with it’s positive lead towards pin 2, and the negative towards ground. The negative lead is the one at the flat edge on the plastic casing of the LED. Add a 330Ω series resistor between the LEDs’ negative leg and ground.This resistor helps to limit the current through the LED, to avoid us turning it into charcoal, or damaging the pin. LEDs don’t like a lot of current, keeping to at or below about 20-30mA should keep it smiling bright.

When measuring the pin while it’s pulled high, I get a voltage of around 3,25V. Using Ohms law, we can easily calculate the current that will go through the LED as follows:

$$I=\frac{V}{R}=\frac{3.25V}{330\Omega}=9.25mA$$

which is well in the 15mA current per pin limit, as per the datasheet. See 29.0 Electrical Characteristics in the PIC32MX1/2 datasheet.

[responsive imageid=’117′ size1=’0′ size2=’600′ size3=’1000′]

Once your circuit looks more or less like the one in the image above, you’re ready to move to the next step, in which we will cover writing, compiling and flashing some code onto the MCU.