Table of Contents

Voltage Divider

Using two resistors $R_{1}$ and $R_{2}$ an input voltage $V_{in}$ can be lowered to a resulting voltage $V_{out}$ according to the formula:

$$
\begin{eqnarray*}
V_{out} &=& \frac{V_{in} * R_{2}}{R_{1} + R_{2}}
\end{eqnarray*}
$$

using the following circuit diagram:

                                
      * -------*                
      |        |                
      |        *                
      |        \                
      |        / R1             
      |        \                
   +  *        *                
               |                
  Vin          *-------*        
               |       | +      
   -  *        *       *        
      |        /          Vout  
      |        \ R2    *        
      |        /       | -      
      *--------*-------*        
                                                         

The equation has four parameters $V_{in}$, $V_{out}$, $R_{1}$ and $R_{2}$ such that when three parameters are known, the fourth parameter can be obtained by solving the equation.

For ease-of-use, let $R_{1}$ be the resistance that you pick and let $R_{2}$ be the resistance you need to calculate after having picked the value for $R_{1}$. The following steps convert the formula in order to solve for $R_{2}$:

$$
\begin{eqnarray*}
V_{out} &=& \frac{V_{in} * R_{2}}{R_{1} + R_{2}} &\Leftrightarrow& \\
V_{out} ( R_{1} + R_{2} ) &=& V_{in} * R_{2} &\Leftrightarrow& \\
V_{out} R_{1} + V_{out} R_{2} &=& V_{in} * R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{1} + V_{out} R_{2}}{V_{in}} &=& R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{1}}{V_{in}} + \frac{V_{out} R_{2}}{V_{in}} &=& R_{2} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}} &=& R_{2} - \frac{V_{out} R_{1}}{V_{in}} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}} - R_{2} &=& - \frac{V_{out} R_{1}}{V_{in}} &\Leftrightarrow& \\
\frac{\frac{V_{out} R_{2}}{V_{in}} - R_{2}}{V_{in}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
\frac{\frac{V_{out} R_{2}}{V_{in}}}{V_{in}} - \frac{R_{2}}{V_{in}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
\frac{V_{out} R_{2}}{V_{in}^{2}}} - \frac{R_{2}V_{in}}{V_{in}^{2}} &=& \frac{- \frac{V_{out} R_{1}}{V_{in}}}{V_{in}}} &\Leftrightarrow& \\
R_{2}\frac{V_{out} - V_{in}}{V_{in}^{2}} &=& - \frac{V_{out} R_{1}}{V_{in}^{2}} &\Leftrightarrow& \\
R_{2}(V_{out} - V_{in}) &=& - V_{out} R_{1} &\Leftrightarrow& \\
R_{2} &=& - \frac{V_{out} R_{1}}{V_{out} - V_{in}} &\Leftrightarrow& \\
\end{eqnarray*}
$$

Counter-intuitively, the formula for $R_{2}$ appears to result in a negative value but one has to bear in mind that $V_{out}$ will always be smaller than $V_{in}$ such that the result will always be negative and suppress the negative sign in front of the right-hand side of the equation.

Autofire

Autofire is a game feature that allows the player to flick a hardware switch in order to make the game character shoot at the fastest possible rate thereby alleviating the player's need to mash the fire button repeatedly. Many (retro) consoles do not benefit from a built-in autofire switch. Alternative or addon controllers often had an autofire button.

On all consoles, the hardware buttons are no more than a momentary single press single throw (SPST) switch that closes a circuit and (usually) instructs the microprocessor to execute the corresponding action (ie: shoot).

As such, a circuit can be built using a NE555 timer that will rapidly make the connection between the two leads in parallel with the original hardware button.

For this mini-project, an astable circuit based on the NE555 timer is built:

                    Vcc
                     +
                     |
+--------------+-----+
|              |     |
R1         +---+-----+---+
|          |   4     8   |
+----------+ 7         3 +------+ Vout
|          |             |
R2         |    NE555    |
|          |             |
+----+-----+ 6         5 +------+
|    |     |   2     1   |      |
|    |     +---+-----+---+      |
C1   |         |     |          C2 = 10nF
|    +---------+     |          |
+--------------------+----------+
                     |
                    GND

where:

The formula to calculate the frequency at which the output voltage switches between high and low is given by:

$$
f = \frac{1.44}{(R_{1} + 2 R_{2})C_{1}}
$$

The period $T$ is the time covered for one cycle, high and low:

           T
     |<--------->|
     |           |
     | T1    T0  |
     |<--->|<--->|
     |     |     |
     +-----+     +-----+
     |     |     |     |
     |     |     |     |
-----+     +-----+     +-----

where, $T_{1}$ (the time $V_{out}$ spends as high) is given by:

$$
T_{1} = 0.694 (R_{1} + R_{2}) C_{1}
$$

respectively $T_{2}$ (the time $V_{out}$ spends as low) is given by:

$$
T_{0} = 0.694 R_{2} C_{1}
$$

Empirically, a button press by a player on the hardware buttons has variable $T_{1}$ and $T_{2}$ and it does not matter whether the player spends more time with the button held down than with the button depressed when the player mashes the button.

Nevertheless, for simplicity, let us assume that the mark space ratio $M$, defined (as the ratio between the time that the button is being held down and the time that button is released):

$$
M = \frac{T_{1}}{T_{0}}
$$

is equal to $1$, meaning an equal time of the button being held down and released.

In this case, the mark space ratio will be $1$ such that we can write $T_{1} = T_{0}$ and substituting with the formulas for $T_{1}$ respectively $T_{0}$, we obtain:

$$
0.694 (R_{1} + R_{2}) C_{1} =  0.694 R_{2} C_{1} 
$$

Let $p=0.694$ for simplicity and solving:

\begin{eqnarray*}
p (R_{1} + R_{2}) C_{1} &\equiv& p R_{2} C_{1} \Rightarrow \\
R_{1} + R_{2} &\equiv& R_{2} \Rightarrow \\
R_{1} &\equiv& 0
\end{eqnarray*}

meaning that for a mark space ratio $M=1$, the value of the resistor $R_{1}$ must be $0$; in other words, the $R_{1}$ resistor is shorted (tersely, the wire itself will imply some resistance that will just be ignored).

Pedantically, the period $T$ should be equal to the CPU clock time because a higher frequency would simply not be perceived by the CPU however, the period $T$ could also be equal to the frames per second rating since a higher frequency could not be perceived on the screen.

In the end, various games accept different button mash speeds such that the period $T$ could be chosen as any value close to the FPS. In this case, let $T=0.02ms$ ($20ms$) and $M=1$ which would mean that the button will be pressed for $T_{1}=10ms$ and then depressed for $T_{0}=0.01s$ ($10ms$) and then pressed again, …

For $R_{1}=0$ both equations for $T_{1}$ and $T_{0}$ reduce to:

$$
0.01 &\equiv& 0.694 R_{2} C_{1} 
$$

and solving for $R_{2}$:

\begin{eqnarray*}
R_{2} &\equiv& \frac{0.01}{0.694 C_{1}}
\end{eqnarray*}

That is, taking values for the capacitor $C_{1}$ we can obtain the necessary value for the resistor $R_{2}$. For instance, taking a capacitor of $1 \mu F$ ($0.000001 F$), the value for $R_{2}$ is obtained:

\begin{eqnarray*}
R_{2} &\equiv& \frac{0.01}{0.694 0.000001} \\
&\approx& 11409.221892 \ldots \Omega
\end{eqnarray*}

And, as it always is the case with engineering, nobody is going to produce a $11409.221892 \ldots \Omega$ resistor, just for you. One can plot $C_{1}$ vs $R_{2}$ and select points on the curve in order to hopefully obtain practical values for $C_{1}$ and $R_{2}$:

So, let's see: when $C_{1} \approx 8 \mu F$ then $R_{2} \approx 2k \Omega$. Of course, were the values $C_{1}=8*10^{-6}$ and $R_{2}=2000$ to be substituted in the original formulas, $T = T_{1} + T_{0} \approx 11.10ms$ which is not exactly the initial goal of $10ms$ - but good enough to simulate a repeated button press!

Consoles will definitely not mind variations of the order of milliseconds when it comes to button mashing however, if leeway is to be given, then $R_{2}$ could perhaps be substituted by a variable resistor such that the period $T$ could become adjustable.

Transistor as a Switch

A 2N3904 BJT (base-junction transmitor) transistor can be used as a low-voltage switch in a circuit instead of a relay. The schematic is built around $3.3V$ which is the standard voltage used by most IoT devices.

The value of the base resistor $R_{b}$ that must be used in order to run the transistor at saturation can be calculating. Let the following circuit be a guide for the calculations:

                                    
                                    +--------+ Vcc
                                    /
+------------------+                \
^       ^          |                /
|       |          \                |  | Ic
|    Vb = Ib * Rb  / Rb             |  v
|       |          \        Ib      C
|       |          |        ->    |/
Vi      v          +---+---------B|\  hFE
|                      ^            E
|                      | Vbe        |
|                      v            |
+-----------------------------------+
                                    |
                                    - GND

We have an input voltage $V_{i}$ such as the $3.3V$ from a GPIO pin equal to the sum of the base-emitter voltage of the NPN transistor $V_{be}$ and the base voltage $V_{b}$:

$$
\begin{eqnarray*}
V_{i} &=& V_{b} + V_{be}
\end{eqnarray*}
$$

using Ohm's law, it is known that:

$$
\begin{eqnarray*}
V_{b} &=& I_{b} * R_{b}
\end{eqnarray*}
$$

Substituting, the following relation is obtained:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} - V_{be}}{I_{b}}
\end{eqnarray*}
$$

In order to guarantee that the transistor operates in the saturation region, the base current is multipled by a factor of $3$, such that:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} - V_{be}}{3 * I_{b}}
\end{eqnarray*}
$$

Also, knowing that BJT behave typically as a forward-biased diode with an approximate voltage drop of $\approx 0.6V$, it is obtained that $V_{i} - V_{be} \approx 0.6V$. Now, since the base-emitter voltage $V_{be}$ is usually negligible by comparison to the input voltage $V_{i}$, the formula reduces to:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i}}{3 * I_{b}}
\end{eqnarray*}
$$

Finally, to determine $I_{b}$, the following relation is given:

$$
\begin{eqnarray*}
$I_{b}$ &=& \frac{I_{c}}{hFE}
\end{eqnarray*}
$$

where $hFE$ is the DC gain of the transistor and $I_{c}$ is the current flowing through the collector.

Substituting for $R_{b}$ the following formula is obtained:

$$
\begin{eqnarray*}
R_{b} &=& \frac{V_{i} * hFE}{3 * I_{c}}
\end{eqnarray*}
$$

from where the value of the base resistor can be determined as a relation between the input voltage $V_{i}$, the DC gain of the transistor ($hFE$) and the collector current $I_{c}$ (also the load current).

As an example, let us assume that the device to be powered requires the load current $I_{c} \approx 100mA = 0.1A$, that the device should be toggled from a GPIO pin capable of supplying $3.3V$ and that the DC gain of the transistor $hFE = \beta = 100$.

In that case the value of the base resistor $R_{b}$ is:

$$
\begin{eqnarray*}
R_{b} &=& \frac{3.3V * 100}{3 * 0.1A} \\
&=& \frac{3300}{0.3} \\
&=& 11000 \Ohm
\end{eqnarray*}
$$

or $R_{b} = 11k\Ohm$.

The value for the load $I_{c}$ can be determined using the same schematic:

                                    
                                    +--------+ Vcc
                                    |   Ql   ^
                                    /        |
+------------------+                \ Rl   Vcc-Vce
^       ^          |                /        |
|       |          |           | Ic |        |
|       |          |           v    |        v
|       |          \                +--------+ 
|    Vb = Ib * Rb  / Rb             |        ^
|       |          \        Ib      C        |
|       |          |        ->    |/         |
Vi      v          +---+---------B|\  hFE   Vce
|                      ^            E        |
|                      | Vbe        |        |
|                      v            |        v
+-----------------------------------+--------+
                                    |
                                    - GND

where:

Knowing that every load has an internal resistance $R_{l}$ and applying Ohm's law in quadrant $Q_{l}$, the load current $I_{c}$ can be determined as:

$$
\begin{eqnarray*}
I_{c} &=& \frac{V_{cc} - V_{ce}}{R_{l}}
\end{eqnarray*}
$$

Example

Assume the following circuit:

          
 +--------- S2 +----------+
 |         3.3V           |
 - GND                    |
                          C
                        |/
 +--- S1 +----+/\/+----B|  2N3904
 |    0V     460kOhm    |\
 |                        E
 - GND                    |
                          |
                          + + (a) 864.7uV

                          + - (b)
                          |
                          - GND

When the GPIO ($S_{1}$) pin is pulled low, for instance, programatically by controlling the GPIO pin through software, the current flowing between the collector and emitter of the 2N3904 NPN BJT transistor is as low as $864.7\muV$ which is insufficient to power a device (connected to pins $a$ and $b$).

          
 +--------- S2 +----------+
 |         3.3V           |
 - GND                    |
                          C
                        |/
 +--- S1 +----+/\/+----B|  2N3904
 |   3.3V  Rb=460kOhm   |\
 |                        E
 - GND                    |
                          |
                          + + (a) 2.966V

                          + - (b)
                          |
                          - GND

When the GPIO ($S_{1}$) is pulled high, the BJT transistor will allow up to $2.966V$ to flow from $S_{2}$ through the collector and to the emitter thereby powering a device (connected to pins $a$ and $b$).

PCB Design

Given the required components consisting in just a resistor and a transistors, various PCB designs can made. Small modules can be created by using a 2N3904 transistor and an surface-mounted resistor using a dual-layer PCB. Larger modules would use a standard long resistor on the base but are still sufficiently small to serve most applications.

Shortcomings

The problem with the transistor switch is that the 2N3904 transistor will not allow a high amperage to flow through the junction such that the switch is best used to trigger digital buttons rather than act as a relay. Under no circumstance should a transistor switch be used to operate mains voltages ($220-110V$) and apparatus that might require entire amperes of power. For the latter case, a reed relay such as the R1 series from Rayex Electronics should be used instead of a transistor switch.

RC Delay Circuit

An RC circuit delays the voltage between the two poles of the resistor.

Schematic:

(a)             (b)
+----+/\/\/\+----+
         R       |
                 |
                 +
               -----
               ----- C
                 +
                 |
                 |
                 +
                 GND

After a given time $\tau$ the voltage $V_{in}$ applied at pole (a) will be forwarded to point (b) as $V_{out}$ where $V_{out} \approx 63.2\% * V_{in}$. The time $\tau$ is computed as $\tau \equals R \times C$ where $R$ is the value (in Ohms) of the resistor and $C$ is the value (in Farrads) of the capacitor.

Example

The circuit will be:

(a)             (b)
+----+/\/\/\+----+
      R=10kΩ     |
                 |
                 +
               -----
               ----- C=100nF
                 +
                 |
                 |
                 +
                 GND

Assuming:

\begin{eqnarray*}
R &=& 10k\Ohm \\
C &=& 100n F
\end{eqnarray*}

and applying $V_{in} \equals 3.3V$ to the input pin (a), the time it will take for the voltage to propagate from (a) to (b) will be:

\begin{eqnarray*}
\tau &=& R \times C \\
&=& 10000 * 0.000000001 \\
&=& 0.00001 \\
&=& 10^{-5}s
\end{eqnarray*}

and the voltage obtained at $V_{out}$ will be:

\begin{eqnarray*}
V_{out} &=& 63\% * V_{in} \\
&=& 63\% * 3.3V \\
&=& 2.08V
\end{eqnarray*}

Incidentally, this is the circuit required (page 17, ESP32 Hardware Design Guidelines V1.9) to boot an Espressif ESP32 SoC where point (a) represents the 3.3V pin, point (b) represents the CHIP_PU (or EN, enable) pin and the ground can be leveraged from any pin on the ESP32 board.

Logic Level MOSFETs

MOSFETs are a type of transistors that are capable of switching a high amount of current with a relatively small switching current provided to the base of the transistor. Logic level MOSFETs commonly have an L in their description (ex: IRLZ44) indicating that the voltage provided to the base in order to switch the current between the emitter and collector is commonly between $0$ and $3.3V$.

In order to make sure that a transistor is a logic level transistor the RDS(on) ("Static Drain-to-Source On-Resistance") and the VGS(th) (Gate Threshold Voltage) values can be inspected on the datasheet.

Typically, logic level MOSFETs will have an RDS(on) value about $5V$ and lower and the VGS(th) value is usually also very small (ie: between $1V$ and $2V$). Regular MOSFETs on the other hand will have much higher thresholds.

Logic level MOSFETs also dissipate much less heat: knowing the voltage applied to the base as well as the expected switching current:

\begin{eqnarray*}
P &=& I^{2} * \textt{RDS(on)}
\end{eqnarray*}

If the power in Watts is less than a quarter Watt, then more than likely a heatsink is not required.

Mono to Stero Converter

An interesting mono-to-stereo converter based on two LM1458 amplifiers.

Estimating the Runtime of Equipment on Batteries

Using the formula:

\begin{eqnarray*}
Wh &=& Ah * V
\end{eqnarray*}

where:

given a battery with a given $Ah$ rating and a given voltage $V$ one can determine the Watt-Hours ($Wh$) that the battery can provide. Dividing the Watt-Hours by the rating of the equipment in Watts ($W_{e}$) leads to an approximation of time (measured in hours) that the battery will be able to run the equipment for.

In other words:

\begin{eqnarray*}
t_{h} &=& \frac{Wh}{W_{e}}
\end{eqnarray*}

where:

The formulas can then be combined conveniently by substituting and then solving for $t_{h}$:

\begin{eqnarray*}
Wh &=& Ah * V \\
W_{e}*t_{h} &=& Ah * V \\
t_{h} &=& \frac{Ah * V}{W_{e}}
\end{eqnarray*}

resulting in the final formula:

\begin{eqnarray*}
t_{h} &=& \frac{Ah * V}{W_{e}}
\end{eqnarray*}

where:

Note that many times the voltage has to be stepped or even direct current must be converted to alternative current such that in such cases the formulas would only apply at no-loss efficiency which is impossible. For instance, an inverter, a device that converts direct current to alternative current has a typical loss of $15\%$ such that the loss has to be deducted from the result.

For a lead-acid car battery, if one would calculate that some equipment could be sustained for, say, $t'$ amount of hours, discharging a lead-acid car battery beyond $50\%$ of its total charge would effectively mean killing the battery, such that a more realistic run time for the equipment would be half the calculated time, or, in other words $t_{total}=\frac{t'}{2}$, after which the battery should be disconnected. In some sense, only half a lead-acid car battery calculated watt hours are useful, whilst the other half is necessary to keep the battery itself alive. This is much different with deep-discharge batteries such as LiFePO4 batteries that an be discharged to the full of their Watt-Hour capacity.

Flyback Diode for Relays

The following circuit can often been found in many cases where "relay modules" are sold:

Vcc


+-----------------+
a                 |     +----------+ load
                  |     |
        +---------+     |
        |         |     |
        |     +---|-----|---+ rl
        |     |   3     |   |
        |     |   3     +   |
        ^     |   3 L    /  |
    D1 ---    |   3     +   |
        |     |   3     |   |
        |     +---|-----|---+
        |         |     |
        +---------+     +----------+
                  |
                  |
                 -+- b
                 /// 

The purpose of the D1 diode is to provide a flyback circuit such that when a potential is established and then broken between the points $a$ and $b$, the negative current created by inductor $L$ will not backflow and destroy any circuitry on the path between $a$ and $b$.

Transforming a Non-Latching Relay into a Latching Relay

The following sketch:

a
+-----------------+-----+
Vcc               |     |
                  |     |
             SWt \      |
                  +     |
                  |     |
        +---------+     |
        |         |     |
        |     +---|-----|---+ RLY
        |     |   3     |   |
        |     |   3     +   |
        |     |   3 L    /  |
        |     |   3     +   |
        |     |   3     |   |
        |     +---|-----|---+
        |         |     |
        +---------------+-------+
                  |      x      |
                  |             | |
                  +             | | load
             SWr |              | v 
                  +             |
                  |             |
                  |             |
                 -+- b         -+- c
                 ///           ///

illustrates a circuit containing a non-latching relay $RLY$ that has been transformed into a latching relay by connecting the relay inductor $L$ to the line that is supposed to carry the voltage load $V_{cc}$. One limitation of this circuit is that the coil voltage must equal the load voltage (which can be rare).

The switches $SW_{t}$ and $SW_{r}$ represent the trigger, respectively the reset switches that carry the functions of engaging the relay, when the trigger switch ($SW_{t}$) is engaged, respectively breaking the circuit when the reset switch ($SW_{r}$) switch is pressed.

In order to understand the circuit, the load line is followed, between $V_{cc}$ and $c$ whilst paying attention to the state of the switches $SW_{t}$ and $SW_{r}$.

The following table will summarize the states of the switches, relative to the state of the switches but with the mention that the table should be read linearly as a sequence of states, from top to bottom, rather than an instantaneous display of states.

$SW_{t}$ $SW_{r}$ Outcome
depressed depressed With both switches depressed, the coil voltage is zero $V_{L} = 0$, the load voltage is zero $V_{load}= 0$ such that the circuit is off and cannot bear a load.
depressed pressed With $SW_{t}$ depressed and $SW_{r}$ pressed, the coil voltage is zero ($V_{L} = 0$) due to current not being able to flow neither between $a$ and $b$ nor between $a$ and $c$ such that the circuit is off and cannot bear a load.
pressed pressed With $SW_{r}$ held down and $SW_{t}$ pressed, the coil voltage will be equal to $V_{cc}$ ($V_{L} = V_{cc}$) with current flowing between $a$ and $b$, the relay $RLY$ will be engaged and current will flow between $a$ and $c$ such that the circuit will be on and capable of bearing a load.
depressed pressed With $SW_{r}$ held down and now the switch $SW_{t}$ released, a circuit is still formed between $a$, $b$ and $c$ (via junction $x$) such that the circuit is on and can still bear a load.
depressed depressed Now, when $SW_{r}$ is released, the coil circuit between $a$ and $b$ is broken, such that the relay $RLY$ decouples, and with the relay decoupled, the load circuit between $a$ and $b$ is also broken, such that the circuit turns off and no load can be powered.

The following video is a simulation using the circuit simulator at https://www.falstad.com/circuit/ of the latching relay circuit that follows the state changes described in the table and illustrates the latching functionality (the voltmeter is replaced by a LED):

Even though the theory (and even the simulation) are abstractions, it must be noted that in practice, the trigger switch $SW_{t}$ does not consist of a typical mechanical switch but more than likely be a mini-circuit itself (and perhaps even similar to the transistor switch), such that the "latching behaviour" that this circuit exhibits becomes more apparent and useful.

Arduino Controlled LED Light Strip

The following is a schematic for driving an LED light strip with 4 contacts (12V, R, G and B) using an Arduino. A $12V$ power source is used to power the Arduino via a step-down module to $5V$ as well as the LED light strip via its 12V pin. The three R, G, B LED pins are controlled via three transistors having the emitter connected to the common ground (common with the step down and the power supply). The transistor act as latches, in this case, opening the feed of current from the R, G and B contacts to the ground. In doing so, each component red, green and blue is lit up and mix to form a desired color. In order to achieve the full spectrum of colors, the Arduino GPIO pins will output an analog signal (via the analogWrite function) in order to control the amount of current flowing from the collector connected to the component pins and to the ground. If the GPIO pins were to output a digital signal level, then only a few colors could be achieved since only toggling the R, G and B components on and off would be possible.

                                            12V
      +-------------------------+------------->
      |                         |
   +--+--+                +-----+-----+
   | 12V |                | 12V -> 5V |
   +--+--+                +-----+-----+
      |                         |
      |                         |            R
      |          +---------+ 5V |   +--------->
      |      GND |         |----+   |
      +----------+         |        /
                 |    GPIO +------|+
                 |         |        \ e
                 |         |        v
                 |         |        |
                 |         |       GND
                 | Arduino |                 G
                 |         |        +--------->
                 |         |        |
                 |         |        /    
                 |    GPIO +------|+         
                 |         |        \ e
                 |         |        v
                 |         |        |
                 |         |       GND
                 |         |                 B
                 |         |        +--------->
                 |         |        |
                 |         |        /
                 |    GPIO +------|+          
                 |         |        \ e
                 |         |        v
                 |         |        |
                 +---------+       GND

Since the gate should be opened varying with the analog signal of the GPIO pins, the transistor type used is an NPN transistor. The actual model of the transistor depends greatly on how many LEDs are contained on an LED strip. Most projects involving this type of LED strip control use power-transitors that are capable of driving a large amount of LEDs however, even a general purpose 2N3904 transistor is capable of switching up to $40V$ from the collector to the emitter and carry between $600mW$ to $1W$ of power which may be sufficient for a smaller LED light strip depending on its power consumption.

Reading a Remote Double-Relay Device with a Single Analog Input

The Chinese market produces some relatively-cheap miniature devices that consist in a radio receiver and two relays such that the relays can be controlled remotely with a remote control.

Given the two relays, the most straightforward usage for this device is to control two different appliances by directly connecting their power-lines to the relays on the controller and then use the remote to trigger one or the other.

The remote itself is simple enough, one LED and two buttons marked A and B. Pressing one or the other buttons will remotely couple either relay on the board and establish the connection between the pins marked COM1, respectively COM2 and ON1 respectively ON2 on the back of the device.

It becomes interesting to possibly read the device itself with an Arduino device in order to determine which of the two buttons on the remote control has been pressed. The straightforward solution would be to connect $5V$ to one side of the relay latch, then the other side to two different GPIO pins on the Arduino thereby using the two pins to determine which of the buttons has been remotely pressed. Nevertheless, as Arduino device go as as well as space-constrictions, it is even more interesting to use one single GPIO pin.

The former illustration shows a schematic that uses a voltage divider in order to feed $5V$ when one remote button is pressed and then $3.4V$ when the other button is pressed whilst feeding the signal to an analog pin on the Arduino. The level on the analog GPIO pin can be read using the Arduino such that there are three distinct logical states that the remote control can find itself: no button pressed, button A pressed and button B pressed. In order to better understand this, here is the representation of the signal that ends up being read by the analog PIN on the Arduino.

^ V
|
|  +-----------------------+               +-------------------- A (5V)
|  |                       |               |
|  |                       |               |
|  |                       |  +---------+. . . . . . . . . . . . B (3.4V)
|  |                       |  |         |  |
|  |                       |  |         |  |
+--+-----------------------+--+---------+--+---------------------> STANDBY (0V)
                                                               t

When the remote control is not used, no current flows through the relays such that the analog pin will be at $0V$, when the B button is pressed, the current will flow through the voltage divider and reduce the $5V$ circuit voltage to $3.4V$ and finally when the A button is pressed, the current will flow straight-through from the $5V$ circuit voltage to the analog GPIO pin.

The same principle can be generalized in order to, perhaps have an array of relays and then keep dividing $5V$ using voltage dividers, such that an infinite number of relays and an infinite number of signals could theoretically be distinguished. However, for all practical purposes, the circuit just spares having to expend yet another pin on the Arduino.

Reversing the Polarity on a Single-Coil Latching Relay using a Remote Double-Relay

A remote double-relay is a module that can be found abundantly yet mostly in a format that contains two non-latching SPDT relays and sometimes a latching option might have been preferred. In order to solve the problem, a third latching relay can be added that will allow two circuits to be connected depending on which way the polarity is applied around the relay coil.

One good option for the latching relay is the G6S series of relays with a coil voltage of $3V$ that suits most digital applications. One option is to just find a dual coil relay with its serial number reading G6SK because dual-coil relays do not need the polarity inverted but have a higher cost.

On the other hand, if only single coil relays are available, such as relays from the G6S series with the identifier reading G6SU, such coils must be toggled by reversing the polarity on the internal inductor within the coil. The following is a simple sketch from the top side of the coil internals:

As you can observe, the two pins closest to the mark labeled 1 and 12 correspond to the internal latching coil of the relay. Depending on whether positive or negative current is applied to either poles, the relay will switch current between the other pins meant to act as switches differently, with two modes being available whether pins 1 and 12 are positive or grounded.

An inconvenient problem that arises is that a circuit would have to somehow magically switch its polarity just to trigger the relay differently which is fairly counter-intuitive for a circuit where the positive and ground lanes have been established. However, with a remote-controlled double relay such as the pictured device, it is possible to achieve the inversion of polarity such that "A" and "B" buttons on the remote will map to either two states of the latching relay:


   +------+-----+-------------------+
3V |            |o                  |
          +-----+-------------------+
                 \                  |
      +---+-----+                   |
      |                             |
      |                          +--|---------+
     ---                         |  | 3
     ///                         |  | 3  Latching Relay
                                 |  | 3
                                 +--|---------+
      +---+-----+                   |
      |          \                  |
      |   +-----+-------------------+ 
      |         |o                  |
   +------+-----+-------------------+
3V |  |
      | 
     ---
     ///     
 

The two relays on the left represent the non-latching relays of the remote control where each relay connects to one side when either "A" or "B" buttons are depressed.

The "intelligent" part here is connecting both common and the connected pin of both relays together to $3V$ and to the coil pin of the relay on both sides such that pressing either button on the remote disconnects either side of the remote controlled relay thereby switching the polarity on the pins of the latching relay.

It should be possible to achieve the same effect using diodes and preventing current backflow, but the less components the better!