Using two resistors and an input voltage can be lowered to a resulting voltage according to the formula:
using the following circuit diagram:
* -------* | | | * | \ | / R1 | \ + * * | Vin *-------* | | + - * * * | / Vout | \ R2 * | / | - *--------*-------*
The equation has four parameters , , and such that when three parameters are known, the fourth parameter can be obtained by solving the equation.
For ease-of-use, let be the resistance that you pick and let be the resistance you need to calculate after having picked the value for . The following steps convert the formula in order to solve for :
Counter-intuitively, the formula for appears to result in a negative value but one has to bear in mind that will always be smaller than such that the result will always be negative and suppress the negative sign in front of the right-hand side of the equation.
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:
The period is the time covered for one cycle, high and low:
T |<--------->| | | | T1 T0 | |<--->|<--->| | | | +-----+ +-----+ | | | | | | | | -----+ +-----+ +-----
where, (the time spends as high) is given by:
respectively (the time spends as low) is given by:
Empirically, a button press by a player on the hardware buttons has variable and 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 , defined (as the ratio between the time that the button is being held down and the time that button is released):
is equal to , meaning an equal time of the button being held down and released.
In this case, the mark space ratio will be such that we can write and substituting with the formulas for respectively , we obtain:
Let for simplicity and solving:
meaning that for a mark space ratio , the value of the resistor must be ; in other words, the resistor is shorted (tersely, the wire itself will imply some resistance that will just be ignored).
Pedantically, the period should be equal to the CPU clock time because a higher frequency would simply not be perceived by the CPU however, the period 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 could be chosen as any value close to the FPS. In this case, let () and which would mean that the button will be pressed for and then depressed for () and then pressed again, …
For both equations for and reduce to:
and solving for :
That is, taking values for the capacitor we can obtain the necessary value for the resistor . For instance, taking a capacitor of (), the value for is obtained:
And, as it always is the case with engineering, nobody is going to produce a resistor, just for you. One can plot vs and select points on the curve in order to hopefully obtain practical values for and :
So, let's see: when then . Of course, were the values and to be substituted in the original formulas, which is not exactly the initial goal of - 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 could perhaps be substituted by a variable resistor such that the period could become adjustable.
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 which is the standard voltage used by most IoT devices.
The value of the base resistor 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 such as the from a GPIO pin equal to the sum of the base-emitter voltage of the NPN transistor and the base voltage :
using Ohm's law, it is known that:
Substituting, the following relation is obtained:
In order to guarantee that the transistor operates in the saturation region, the base current is multipled by a factor of , such that:
Also, knowing that BJT behave typically as a forward-biased diode with an approximate voltage drop of , it is obtained that . Now, since the base-emitter voltage is usually negligible by comparison to the input voltage , the formula reduces to:
Finally, to determine , the following relation is given:
where is the DC gain of the transistor and is the current flowing through the collector.
Substituting for the following formula is obtained:
from where the value of the base resistor can be determined as a relation between the input voltage , the DC gain of the transistor () and the collector current (also the load current).
As an example, let us assume that the device to be powered requires the load current , that the device should be toggled from a GPIO pin capable of supplying and that the DC gain of the transistor .
In that case the value of the base resistor is:
or .
The value for the load 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 and applying Ohm's law in quadrant , the load current can be determined as:
Assume the following circuit:
+--------- S2 +----------+ | 3.3V | - GND | C |/ +--- S1 +----+/\/+----B| 2N3904 | 0V 460kOhm |\ | E - GND | | + + (a) 864.7uV + - (b) | - GND
When the GPIO () 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 which is insufficient to power a device (connected to pins and ).
+--------- S2 +----------+ | 3.3V | - GND | C |/ +--- S1 +----+/\/+----B| 2N3904 | 3.3V Rb=460kOhm |\ | E - GND | | + + (a) 2.966V + - (b) | - GND
When the GPIO () is pulled high, the BJT transistor will allow up to to flow from through the collector and to the emitter thereby powering a device (connected to pins and ).
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.
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 () 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.
An RC circuit delays the voltage between the two poles of the resistor.
Schematic:
(a) (b) +----+/\/\/\+----+ R | | + ----- ----- C + | | + GND
After a given time the voltage applied at pole (a) will be forwarded to point (b) as where . The time is computed as where is the value (in Ohms) of the resistor and is the value (in Farrads) of the capacitor.
The circuit will be:
(a) (b) +----+/\/\/\+----+ R=10kΩ | | + ----- ----- C=100nF + | | + GND
Assuming:
and applying to the input pin (a), the time it will take for the voltage to propagate from (a) to (b) will be:
and the voltage obtained at will be:
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.
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 and .
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 and lower and the VGS(th)
value is usually also very small (ie: between and ). 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:
If the power in Watts is less than a quarter Watt, then more than likely a heatsink is not required.
An interesting mono-to-stereo converter based on two LM1458
amplifiers.
Using the formula:
where:
given a battery with a given rating and a given voltage one can determine the Watt-Hours () that the battery can provide. Dividing the Watt-Hours by the rating of the equipment in Watts () leads to an approximation of time (measured in hours) that the battery will be able to run the equipment for.
In other words:
where:
The formulas can then be combined conveniently by substituting and then solving for :
resulting in the final formula:
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 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, amount of hours, discharging a lead-acid car battery beyond 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 , 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.
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 and , the negative current created by inductor will not backflow and destroy any circuitry on the path between and .
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 that has been transformed into a latching relay by connecting the relay inductor to the line that is supposed to carry the voltage load . One limitation of this circuit is that the coil voltage must equal the load voltage (which can be rare).
The switches and represent the trigger, respectively the reset switches that carry the functions of engaging the relay, when the trigger switch () is engaged, respectively breaking the circuit when the reset switch () switch is pressed.
In order to understand the circuit, the load line is followed, between and whilst paying attention to the state of the switches and .
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.
Outcome | ||
---|---|---|
depressed | depressed | With both switches depressed, the coil voltage is zero , the load voltage is zero such that the circuit is off and cannot bear a load. |
depressed | pressed | With depressed and pressed, the coil voltage is zero () due to current not being able to flow neither between and nor between and such that the circuit is off and cannot bear a load. |
pressed | pressed | With held down and pressed, the coil voltage will be equal to () with current flowing between and , the relay will be engaged and current will flow between and such that the circuit will be on and capable of bearing a load. |
depressed | pressed | With held down and now the switch released, a circuit is still formed between , and (via junction ) such that the circuit is on and can still bear a load. |
depressed | depressed | Now, when is released, the coil circuit between and is broken, such that the relay decouples, and with the relay decoupled, the load circuit between and 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 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.
The following is a schematic for driving an LED light strip with 4 contacts (12V
, R
, G
and B
) using an Arduino. A power source is used to power the Arduino via a step-down module to 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 from the collector to the emitter and carry between to of power which may be sufficient for a smaller LED light strip depending on its power consumption.
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 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 when one remote button is pressed and then 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 , when the B
button is pressed, the current will flow through the voltage divider and reduce the circuit voltage to and finally when the A
button is pressed, the current will flow straight-through from the 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 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.
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 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 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!