For this lesson, we will be working with circuits that control the state of one or more LEDs. The following schematic is an LED circuit with a pushbutton, where an open button means the LED state is off and a closed button means the LED state is on.
Moving to the workspace, we see an implementation of the pushbutton LED circuit.
The constant 3.3V on GPIO pin 1 is connected to row 5 on the left side of the breadboard. Ground on GPIO pin 20 is connected to row 11 on the right side of the breadboard. These two connections make up the circuit’s electric supply.
A button, a 330Ω resistor, and a red LED are then connected together as the load of the circuit.
Let’s say the red LED has the following characteristics:
- Vf = 1.8V
- If = 0.02A
Using the forward voltage of the LED and 330Ω as the value of the resistor, let’s calculate the actual current through the circuit:
Using Ohm’s law:
Even though the LED has a forward current of 0.02A, our current limiting 330Ω resistor has brought the current in this circuit down to 0.0045A! Why is that?
The higher value resistor is recommended to avoid damaging the Raspberry Pi circuit components. The Raspberry Pi can not provide a lot of current (0.02A might be too high!) To be safe we used a larger resistor value and in return, we will get a slightly dimmer LED.
This circuit controls the state of the LED. When the pushbutton is pressed, 3.3V is applied to the circuit, a current flows, and the LED is lit.
Controlling the LED state is exactly what we will accomplish using the output pins in the rest of this lesson.