# Electronics

## LEDs

The forward current of a LED depends on its color. The regular cheap 3-10 mm
LED diodes range from $1,8−2,2V$ (red, orange, yellow, etc) to $3,2−3,8V$
(white, green, warm white, etc). They have a typical forward current of $20mA$,
and a maximum forward current of $30mA$^{1} (for reference, a GPIO pin
of an ESP32 provides up to ca max $40mA$).

Color | $V_{f}$ | $I_{f}$ |
---|---|---|

White | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

Warm White | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

Blue | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

Red | $1.8V$ - $2.2V$ | $20mA$ - $30mA$ |

Green | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

Yellow | $1.8V$ - $2.2V$ | $20mA$ - $30mA$ |

Orange | $1.8V$ - $2.2V$ | $20mA$ - $30mA$ |

Pink | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

UV | $3.2V$ - $3.8V$ | $20mA$ - $30mA$ |

### Resistance

Since these LEDs all generally have consistent forward currents and forward voltages, we can just use Ohms law and work out a reference table for common supply voltages.

Supply voltage $V_{s}$ | $V_{f}=1,8$ | $V_{f}=3,2V$ |
---|---|---|

$3,3V$ | $75Ω$ | $5Ω$ |

$5V$ | $160Ω$ | $90Ω$ |

$12V$ | $510Ω$ | $440Ω$ |

The resistor values are assume the typical forward current $I_{f}$ of $20mA$.

Forward voltage $V_{f}$ | $V_{s}=3.3V$ | $V_{s}=5V$ | $V_{s}=12V$ |
---|---|---|---|

$1.8V$ | $75Ω$ | $160Ω$ | $510Ω$ |

$3.2V$ | $5Ω$ | $90Ω$ | $440Ω$ |

The voltage across the circuit is equal to the sum of the voltage across the components in the circuit, the resistor and the LED.

So for an LED with a forward d voltage $V_{f}=1.8V$ that is connected to a supply voltage $V_{s}=3.3V$, the voltage across the resistor is $V=V_{s}−V_{f}=1.5V$.

```
>>> I = 0.02 # 20 mA == 0.02 A
>>> Vs = 3.3
>>> Vf = 1.8
>>> V = Vs - Vf
>>> V/I # R = V/I
75 # 75 Ohm
```

So to connect LED with a forward voltage of 1.8 V to 3.3 V, it should be protected by a 75 Ω resistor.

### Anatomy of a green 5mm LED^{}2

### Wiring schematics

*Multiple LEDs connected in series.*

*
Proper way to connect multiple LEDs in parallel, each LED has its own current limiting resistor.
*

### Pinouts

Regular and RGB 3mm and 5mm LED diodes^{3}:

- The cathode leg ($−$ or $K$) is the shorter leg (usually $17mm$).
- The anode leg ($+$ or $A$) is the longer leg (usually $19mm$).

## Stepping down voltage with resistence

There are multiple different ways to step DC Voltage down. Using a buck converter is simple, but they are bulky. But resistence reduces voltage (voltage falls as resistance increases).

To do that, you use two resistors $R_{1}$ and $R_{2}$ and "divide" the circuit
between them^{4}, connecting $R1$ to $V_{IN}$ and $R_{2}$ to $GND$.
If $R_{1}$ and $R_{2}$ are of equal value, $V_{IN}$ is reduced by half ($V_{OUT}=V_{IN}/2$).

This circuit is called a voltage divider, $R_{1}$ is a pull-up resistor and $R_{2}$ is a pull-down resistor.

The general equation for reducting $V_{IN}$ to $V_{OUT}$:

$R_{2}=V_{IN}−V_{OUT}V_{OUT}×R_{1} $

Since both $R_{1}$ and $R_{2}$ are unknown (also we aren't in school, and experimentation is more interesting than algebra anyway) this involves some experimentation and picking some value resistor for $R_{1}$ and then calculating ca. what value resistor we need to get for $R_{2}$.

For example $10kΩ$ is a reasonable starting point for $R_{1}$. Stepping $7V$ down to $5V$:

```
>>> v_out = 5
>>> v_in = 7
>>> r1 = 10
>>> (v_out*r1)/(v_in-v_out) # 5*10 / (7-5)
25.0 # 50 / 2
```

So to step $7V$ down to $5V$ using a $10kΩ$ pull-up resistor $R_{1}$ to $V_{IN}$, we need to use a pull-down resistor $R_{2}$ that is $25kΩ$.

## Potentiometers

## References

^{3}

^{7}