# LED Lab

## Intro​

In this lab, we're going to build some simple push-button activated LED circuits that use a ballast resistor to limit the current.

Part of the challenge of these labs is building a breadboard circuit based on a schematic, so try to build them first without using the breadboard layout solutions.

## Requirements​

To do this lab, you'll need the following new items:

ItemApproximate Cost (USD)
(2) LEDs, any color$0.02/each (1) RGB LED (Common Cathode)$0.09/each

### Pushbuttons​

Pushbuttons are sometimes called tactile switches. For prototyping on breadboards, the 6mm x 6mm versions fit well. They usually come in a variety of colors and dimensions. These are 6mm x 6mm x 4.3mm:

4.3mm refers to the height of the button; these are available in tall heights to account for designs where the circuit board is far away from the control panel.

A pack of 100 black ones runs ~USD$7 on Amazon. Also, AliExpress has a fantastic 160pc set of 8 different colors for ~USD$5

#### Pushbutton Wiring​

These pushbuttons have two sets of legs. The top two legs are always connected to each other. Similarly, the bottom two legs are always connected. When the switch is pressed, a connection is made between the top set and the bottom set:

Having four legs instead of two makes them more stable.

## Exercise 1: Single LED Circuit​

For the first lab exercise, we're going to build a very simple, pushbutton activated, single-LED circuit with a ballast resistor:

Note that the new circuit symbol introduced above represents a pushbutton:

The power can come from the 3.3V rail on the Meadow or Netduino board. Use an LED of your choosing that has less than a 3.3Vf.

### Step 1 - Design​

This is a very simple circuit, so design is not complex. First, determine the size of resistor you need. In my circuit I used a green LED with a 2.1Vf, and a 20mA max current rating:

R = V / IR = 3.3V - 2.1V / 0.02A = 60Ω

For mine, I'd need at least 60Ω to prevent the LED from overcurrent. However, recall that resistors come in magnitudes of preferred values, with the nearest larger resistor being 68Ω, so that's a good resistor to start with.

### Step 2 - Build and Test​

Once your resistor value is chosen, build the circuit and power it.

Try various resistor values to see where the LED brightness lands. If you have extra LEDs, I recommend trying smaller and smaller resistors to see when/if the LED will burn out.

#### Troubleshooting​

In this simple circuit, the most likely failure point is getting the polarity of the LED wrong. If it doesn't work, first try reversing the LED leads.

You can also test the voltage across the LED with a multimeter:

## Exercise 2: Series LED Circuit​

For this exercise, we're going to wire up two LEDs in series that are button actuated as before and use a ballast resistor:

For my circuit, I've chosen a red and a blue LED that have a 2.1V and a 3.3V Vf, respectively. That means a total Vf of 5.4V, so I'm going to power the circuit with a 9V battery.

If you don't have a 9V battery and/or connector, you can choose two LEDs with smaller voltage drops and power from the 5V power rail on the Meadow or Netduino board.

### Step 1 - Design​

The same Ohm's law applies as before, but this time we have to take into account both LED voltage drops. Mine looks like the following:

R = V / IR = 9V - (3.3V + 2.1V) / 0.02A = 180Ω

### Step 2 - Build and Test​

Once you've calculated your necessary voltage source and resistor, build and test the circuit as before.

## Exercise 3: 7 Color RGB LED Circuit​

By putting a pushbutton in front of each color component of an RGB LED, 7 different colors can be created, depending on the combination of switch presses. Each button has two possible values, and there are three buttons, therefore there are 8 combinations (2 x 2 x 2), however, one combination is all OFF, which is no color at all.

The circuit we're going to build looks like this:

It doesn't matter which side of the LED (or button) the resistor goes on, since each LED current path has the same amount of current flowing through it at any given point. As we'll see, placing the pushbutton first makes it fit on the breadboard nicely. In fact, I was able to comfortably fit all four of the exercises in this lab on a single breadboard.

### Step 1 - Design​

The first thing we need to do is calculate the necessary resistor for each color component. The following calculation is based on the RGB LED linked above:

Given:RED: 2.0V - 2.4VGREEN/BLUE: 3.0V - 3.2VMax Current: 20mATherefore:Rr = 3.3V - 2V / 0.020A = 65ΩRgb = 3.3V - 3V / 0.020A = 15ΩPreferred Resistor Values:65Ω -> 100Ω Resistor15Ω -> 47Ω Resistor

I rounded up to the nearest preferred resistor values, which might seem high, but the LED would still be plenty bright with much higher values.

### Step 2 - Build and Test​

Once you've calculated your resistor values, assemble and test the circuit. Try the various button press combinations to create different colors. Also, put your hand or a piece of paper above the LED and look at it when all three buttons are pressed for white. Notice that light paths don't line up perfectly; and only where all three intersect is it white.

The wiring for this exercise can be a little tricky. Look at the solution below if you get stuck.