2.4 Applications and Exercises - mcgill-robotics/auv-embedded-2026 GitHub Wiki
LED and Resistor Circuit
- Description: In this exercise, you'll connect an LED with a resistor to limit current. This is a fundamental circuit that helps prevent damage to the LED by controlling the amount of current flowing through it.
- Formula: Use the formula $R = \frac{V_{supply} - V_{forward}}{I_{LED}}$ to calculate the resistor value.
- Objective: Determine the appropriate resistor value and build the circuit on a breadboard or in a simulation tool like LTspice or Altium Designer.
- Materials: LED, resistor, breadboard, power supply (or equivalent components in a simulation tool).
Diagram
Answer
-
Given Values:
- $V_{supply}$: Supply voltage (e.g., 5V)
- $V_{forward}$: Forward voltage of the LED (e.g., 2V)
- $I_{LED}$: Desired current through the LED (e.g., 20mA)
-
Calculation:
- $R = \frac{5V - 2V}{20mA} = \frac{3V}{0.02A} = 150\Omega$
-
Result:
- Use a 150Ω resistor in series with the LED to limit the current to 20mA.
Simple LED Driver Circuit
- Problem: We need to drive an LED with a higher current or voltage than what a microcontroller can supply directly. How can we achieve this?
- Solution: Use a transistor as a switch to control the LED. A transistor can handle higher current and voltage, making it suitable for driving an LED.
Explanation
-
Choosing the Transistor:
- BJT (Bipolar Junction Transistor): A common choice when the control signal is lower and you need amplification.
- MOSFET (Metal-Oxide-Semiconductor Field-Effect Transistor): Often preferred for switching applications due to its high efficiency and low on-resistance.
For simplicity, we’ll use an NPN BJT in this exercise, but a logic-level MOSFET could also be used.
-
Circuit Design:
- Connect the LED in series with the collector of the NPN BJT.
- The emitter is connected to ground.
- The base is connected to a GPIO pin of the microcontroller through a current-limiting resistor.
Diagram
Explanation
- When the GPIO pin outputs a HIGH signal, it provides enough base current to turn on the transistor, allowing current to flow from the collector to the emitter, thus lighting up the LED.
- This setup allows the microcontroller to control an LED that requires more current than the microcontroller can directly supply.
Capacitor Decoupling
-
Problem: When digital circuits switch on and off rapidly, they can cause fluctuations in the power supply voltage. These fluctuations can lead to noise and instability in the circuit.
-
Solution: Use decoupling capacitors, also known as bypass capacitors, to stabilize the power supply by filtering out the noise.
Explanation
-
How It Works:
- A decoupling capacitor is placed close to the power pins of an integrated circuit (IC).
- The capacitor provides a local reservoir of charge that the IC can draw from when needed, thereby smoothing out voltage spikes.
-
Choosing the Capacitor:
- Typically, a small ceramic capacitor (e.g., 0.1µF) is placed between the power supply pin and ground.
- In some cases, a larger electrolytic capacitor (e.g., 10µF) might also be used to filter out lower-frequency noise.
Diagram
Explanation
- The capacitor acts as a local energy reserve, responding to rapid changes in current demand by the IC, thus keeping the voltage steady.
- This is particularly important in circuits with sensitive analog components or high-speed digital logic.