Difference between revisions of "Electronics notes/Knobs and dials"

From Helpful
Jump to: navigation, search
m (On floating inputs)
m (Debouncing)
Line 176: Line 176:
The mechanics in almost all switches means their contacts will physically bounce a few times before settling - called {{imagesearch|contact bounce}}.
The mechanics in almost all switches means their contacts will physically bounce a few times before settling, called '''contact bounce'''.
You may like to see {{imagesearch|contact bounce|what that looks like when sampled}}

Revision as of 13:54, 3 August 2021

This is for beginners and very much by a beginner.

It's intended to get an intuitive overview for hobbyist needs. It may get you started, but to be able to do anything remotely clever, follow a proper course or read a good book.

Some basics and reference: Volts, amps, energy, power · Ground · batteries · resistors · changing voltage · transistors · fuses · diodes · varistors · capacitors · inductors · transformers · baluns · amplifier notes · frequency generation · skin effect

And some more applied stuff:

IO: Input and output pins · wired local IO · wired local-ish IO · ·  Various wireless · 802.11 (WiFi) · cell phone

Sensors: General sensor notes, voltage and current sensing · Knobs and dials · Pressure sensing · Temperature sensing · humidity sensing · Light sensing · Movement sensing · Capacitive sensing · Touch screen notes

Actuators: General actuator notes, circuit protection · Motors and servos · Solenoids

Some stuff I've messed with: Avrusb500v2 · GPS · Hilo GPRS · JY-MCU · DMX · Thermal printer ·

Noise stuff: Stray signals and noise · sound-related noise names · electronic non-coupled noise names · electronic coupled noise · ground loop · strategies to avoid coupled noise · Sampling, reproduction, and transmission distortions

Audio notes: See avnotes

Microcontroller and computer platforms Arduino and AVR notes · ESP series notes · STM32 series notes · · · ·

Less sorted: device voltage and impedance, audio and otherwise · electricity and humans · power supply considerations · Common terms, useful basics, soldering · PLL · pulse modulation · signal reflection · resource metering · SDR · Project boxes · Unsorted stuff

See also Category:Electronics.


Variable resistors (see potmeters), many of the ones with a knob are single-turn, meaning they go though their resistance range in ≤ 360 degrees.

Hacking servos

Servos use a potmeter as a sensor, so you could solder wires to that potmeter.

Mostly makes sense to do to continuous-rotation servos (or servos you've hacked that way), and/or when you also want to still use the servo (because otherwise it's just a pricier pot)

(...but manually turning the servo is likely to damage said gears, particularly for higher torque gearboxes, particulary for cheap plastic ones, so in general this is not very useful).

So possibly consider continuous pots, even if they're not necessarily cheaper.

Rotary/linear encoders

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Incremental encoders, a.k.a. Relative encoders (only) report/detect change in position, from which you can calculate direction and speed. ...assuming you're sampling fast enough to not miss transitions.

quadrature encoding in a disc

The idea behind incremental encoders is roughly that they're seeing two things 90 degrees out of phase

One way is to use a a quadrature encoding disc, read out with two sensors at the same angle.

An optical relative encoder can do much the same another way (e.g. many mouse scrollwheels, and also opto-mechanical ball mice) are often a single disc with slits, and it's not the disc but the positioning of the sensor that puts one half such a distance ahead of the other, which lets you one signal is ahead of the other, and you can additionally detect direction (verify)

The two are effectively the same in terms of what you do with the output.

The rate of changes is the speed, and you can tell direction by which leads the other. This video is a decent indication of what happens on these two outputs.

As-is, relative encoders are useful for things like menu navigation, where only movement matters in the first place, and when sensing speeds.

absolute encoider disc

Absolute encoders report their actual position, from which you can then calculate direction and speed.

You could intuit these as encoding their position as an integer, but they're actually Gray code, more useful in this context because it lets you detect and potentially correct successive values that don't make sense.

Virtual absolute encoder (TODO)


In terms of electronics or code




When using switches as input

On floating inputs

Consider that switches often either connect or disconnect an input, meaning one state is a broken circuit.

This means there is nothing to pull it to a stable state, and EM from nearby ICs or the environment can be the strongest effect, particularly if the traces are longer.

When this is sensed, particularly by high impedance inputs, this gives fairly unpredictable behaviour.

The most basic solution is a pullup/pulldown resistor.

On internal pullups

A lot of platforms, DIY or not, you can enable an internal pullups via code, which means you don't need to add a resistor to such a circuit.

Note that these internal pullups tend to be high-valued (e.g. order of 50K), and when

traces are long,
you have no shielding,
you work with high-EM environments, and/or
you are working with SoCs designed to live in shielded traces with short traces (e.g. RPi's SoC)

...then that may not be enough to pull down enough to quiet down all EM noise, you you can get spurious interrupts, and want to add your own resistors, maybe on the order of 5-10k.


The mechanics in almost all switches means their contacts will physically bounce a few times before settling, called contact bounce.

You may like to see what that looks like when sampled

Since most buttons are pulled down or up, this means fast switching in the electrical sense as well: a very quick alternation between contact and no contact.

In buttons that you have to hold down, noisy variation may also happen on movement, as the contacts scrape over each other.

Possible problems

  • If it's driving a load directly, well, most loads don't care so much, so this is often fine
  • Some electrical components that don't like switching that fast
Say, if you're switching on an IC, it may not like bounce on its Vcc, or some of its inputs.
  • Fast sensing, such as those from an IC or microcontroller, may be fast enough to sense and react to all those changes
You may not want that to happen
  • If sensing from a microcontroller, and sampling a button only occasionally,
you may accidentally find in the state it mostly isn't in and do something unexpected.

Possible solutions

  • in digital sensing, there are various solutions in code
many are variations on the idea that it should be in actuated state most of the time
and before you start storing a history, note that a simpler way is to count up or down depending on the last sensed value.
this will react more slowly - but for most human-operated switches, few-millisecond reaction is enough
  • In the case of double throw switches, you actually deal with three states - connected to one, connected to the other, or inbetween.
and there is sometimes some latching solution you can get from logic. This will have basically no latency, but take a few more components.
  • In analog circuits, one way to debounce is a filter
for example, and RC circuit
the idea being is that if it must charge to the pressed state, it only matters that it's mostly being pressed
this will react more slowly - but for most human-operated switches, few-millisecond reaction is enough
note, however, that this only lessens the problem, it doesn't fix it entirely, because there is no hysteresis or latching in there, so there will still be a threshold around which it'll flip-flop (depending on the exact circuit)

TODO: write up a fuller explanation, including common mistakes

There are further considerations:

  • if what you control is safer (or less annoying) in one state, then you may want to bias your logic to be in that state if there is any doubt.
e.g. consider a pushbutton off until it's fairly consistently on
but beware of variants of that code that will effectively debounce in one direction but not in the other.
  • you sometimes care about latency of switching on, so act faster on rising edge than falling edge
particularly if you act only on the rising edge
  • if your load doesn't like fast switching, consider a counter that prevents acting too quickly after the most recent switch

Switches, buttons, toggles, and such

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Encompasses combinations of:

  • Multiple positions,
  • a mechanical tendency to go to one position
toggle/flip, or momentary
  • multiple electronic states,
  • and other electronic properties

Bistability refers to switches that will rest in both states.

It could be both a mechanical and electronic descriptor, though on the mechanical side it's often called latching, or some such term, whereas a monostable would refer to what most relays do (the term "monostable switch" would be rare because we have words like "momentary" and "pushbutton").

...so the terms monostable and bistability are usually about electronic switching, e.g. to pointing out e.g. that

digital circuits can be made to sustain their current state.
thyristors will stay in their current state, while transistors are not
...often then mentioning a simple bistable multivibrator circuit, a.k.a. flipflop), or contrasted with a monostable multivibrator

See also


The distinction between buttons and switches is not more pragmatic than it is hard/strict. Can be a pain in webshopping :)

A few more specific buttons/switches:

  • rocker switch
    • states: often two or three. Usually toggled, sometimes momentary
    • rocker switch
  • push-button
    • states: two. often momentary, sometimes toggled
    • push-button
  • microswitch
    • mainly a small momentary push-button
    • states: Two. Momentary.
    • microswitch
  • Mercury switch
    • states: Two. Depends on orientation (because gravity).
    • no contact bounce
    • mercury switch
  • Reed switch
    • states: Two.
    • Mechanical, closed by nearby magnet
    • reed switch
  • knife switch
    • The circuit breaker of old
    • states: Two. toggled
    • knife+switch


  • end switch
    • a switch positioned at the end of a mechanical range, often to detect when actuation should go no further
    • often a microswitch with some sort of lever, wheel, etc. for durability.\
    • end+switch

Contact bounce (behaviour)

Contact bounce indicates the time in which an arriving contact mechanically settles and in which the connection is not yet stable. See some images. This bounce is often tiny, both in movement and time.

This bounce is rarely important when driving resistive loads, but in anything more complex there the reaction to the bounce itself can matter.

For example, a digital system observing/sampling it may see very fast switching back and forth.

Some components, such as ICs, also don't deal too well with bounce on their Vcc. A bypass capacitor helps here, and is nice for its power stability anyway.

Arcs (behaviour)

Default switch state (design)

Switches that are typically in one state (in the case of buttons will probably return there, rather than be toggled) can be referred to as Normally Open (NO) and Normally Closed (NC)

If it has contacts for more than one state (which, when one state is most natural, can be termed NO and NC contacts), the switch is termed Changeover (CO) (also Double-Throw, implying a typical two-state switch, Triple-Throw, etc.).

Changeover switches can be:

  • break before make, meaning there is some time in which neither side makes contact. This may cause temporary high impedance long enough to cause some unpredictable behaviour
  • make before break, meaning there is some time in which both sides make contact. This may easily cause temporary shorts.

Poles and throwing (design)

Depending on what exactly you want to do, poles and throws can matter when buying a switch.

Amount of poles matters to whether you want to do something with one state (e.g. powered or not) or with both.

Amount of throws matters when you want to control things independently from the same mechanical switch (without digital logic doing it for you). Consider that a car's emergency light switch turns on both turn signals without tying them together electrically.

In some constructions, both matter. Consider multiway switching.

SPST (symbolic)
  • SPST (Single Pole, Single Throw)
    • open or closed

DPST (symbolic)
  • DPST (Double Pole, Single Throw)
    • two separate SPST-style switches controlled by the same mechanics

SPDT (symbolic)
  • SPDT (Single Pole, Double Throw)

DPDT (symbolic)
  • DPDT (Double Pole, Double Throw)
    • two separate SPDT-style switches controlled by the same mechanics

There are further variants of design.

Triple pole and similar also exist, for example triple pole single throw mechanical knife switch circuit breakers.


This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

A relay is an electronically controlled switch.

One circuit can switch a electronically separated circuit, useful when they deal with different voltages and/or different orders of current, a connector that may accept varied devices, as part of process control, as part of safety design, and more.

Often electromechanical, though solid state relays are becoming more common.

Electromechanical relays are solenoids (electromagnets) that push contacts closed.

They are often called just relays, or EMR in contexts where SSRs are also relevant (like here).

Circuit considerations

EMRs may need need on the order of 20mA-50mA to be held well, more when switched from lower voltages, less from higher voltages.

Also, EMRs are largely coils, so are inductive elements that present flyback on their input terminals.

...so if they are switched from ICs or such you will want to sink that spike elsewhere. Circuits with ICs driving them regularly use a transistor (sometimes an optocoupler), and not unusually something (probably a diode) for flyback protection of that transistor/optocoupler.

(Reed relays can switch faster than regular coil relays, but have a current limit that is often on the order of half an amp tops)

SSRs use less control current but run hotter overall, due to their semiconductor nature (for safety's sake assume approx 1W of heat per 1A drawn, but usually noticably less), so you may need a heatsink or risk thermal runaway (read: smoky melty problems), particularly in already-warm conditions.

Relay ratings

Not all are created equal. The physical design will vary with the voltages they are intended to switch.

In particular, most are at most line voltage, because arcing is harder to design away at kilovolts. On the other side of things, lower-voltage-output relays can switch faster because they barely have to think about this issue.

On a related point, when switching significantly inductive effects, you will briefly see larger currents and voltages (the inrush current of the load).

This is one reason a relay's maximum rated inductive load is much lower, often well under half the rated maximum resistive load. This too depends somewhat on the voltage.

For example, the one I'm holding right now is rated for 10A (at 125VAC and 240VAC) for resistive loads, and only for 3A for inductive loads.

There is also a difference between whether it's switching AC or DC. Because DC can sustain an arc longer, DC is derated more(verify). Check the datasheet, the ratings printed on the relay may be correct but less complete.

Hot switching refers to switching a mechanical relay while voltage is applied, and it's the condition that produces arcing and wear.

Cold switching refers to applying voltage only after a relay switch.

Cold switching is possible to design into some test equipment, and sometimes useful to concentrate the wear in a predictable place, but in general many uses of relays will be hot switching.

Solid state relays (SSR) are a relatively new development.

Some designs may be DC-only or have other DC/AC footnotes.

SSRs seem to often be either

for switching AC loads: a SCR or TRIAC
for switching DC loads: a MOSFET (though a combination of two can do AC(verify))

...with optical coupling for isolation.

  • SSRs, being semiconductors they do not wear from the mechanical switching like EMRs do

Comparison between SSRs and EMRs

  • switching speed
SSRs can switch at perhaps 20usec..10msec. That said, ones that have zero cross switching are by definition slower.
EMRs at order of 50ms and wear faster in the process
  • SSRs can switch much larger currents without much higher drive currents
  • SSRs that do zero point switching means no sudden current change
so they don't pollute the waveform as much(verify)

  • EMRs have contact bounce
and, when hot-switching, arcing, welding, and shortened contact lifespan
this is worse on inductive loads
  • EMRs are more susceptible to shock, and orientation matters

  • SSRs are preferable around strong vibration
  • SSRs are preferable when they have to be close to magnetic sensors, temperature sensors
  • SSRs can be preferable in humid and dusty environments (but you may want to protect the entire PCB with an enclosure, so this often matters less)

  • current draw
larger EMRs have to push larger contacts
SSRs are higher resistance by nature, so use a few times more hold current


  • EMRs arc internally so unless they are entirely sealed (various are not) SSRs will be less risky around combustibles/explosives
  • SSRs have different failure modes than EMRs, which can matter
in particular, SSRs are more likely than EMRs to fail closed, which can matter a lot to safety


Failure state
EMRs can weld shut so fail in conductive state, but more usually have their coil fail so fail open
SSRs usually fail in conductive state
In some situations the latter is a much worse idea, both because they may melt or blow, and because the machine is probably not in a safe state before they reak
  • EMRs can have intermittent connections due to poor contact surface (and spot welds over time)
  • EMRs should probably not be switched overly quickly, and because they are physically slowish they often won't even manage
  • SSRs have no clearly primary wear-out mechanism so should last quite long in gentle conditions,
yet there are conditions that kill SSRs faster than EMRs.
  • SSRs are less resistant to heat (see thermal runaway), and at the same time are warmer than EMRs for the same current.
so cooling them can matter
  • EMRs are often derated for varying cases, SSRs somewhat less so(verify).

Voltage surges, momentary shorts, inrush, and (for some) the polarity of what it's switching matters. Which means that EMRs can be preferable for components (motors, transformers) with high inrush current(verify).

Inductive can still create high enough voltage spikes to damage SSR's output transistors

You can generally assume EMRs have on the order of 100K switches in them, varying with quality, how near their current rating they are being used (you might get a spec that says 1M at negligible current, and 10K under significant load).

So assuming a few to a few dozen switches or so per day, they should last years to decades, though in some certain fast-switching uses (e.g. industrial machine control) that might reduce to months so you might want SSRs (with the exception that SSRs may fail on, so which you may want to back up with an EMR for safety and other such interesting implications)





On derating

The switching capacity for inductive loads will be lower than the switching capacity for a resistive loads.

For example, for a given relay the resistive rating may be 5A and the inductive rating 2A

Solid-state relays are nicer in many ways, but have some different considerations related to failure - e.g. surges, large inrush, and reverse voltage, and may be a little more temperature-sensitive.