Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Demo 2.3: Switches, Contact Bounce and Relays

A switch is the most elementary component in this module, and it is the one everybody is most confident they already understand. Two wires, joined or not joined. There is nothing to it.

That confidence lasts until the first time a button is wired to a counter. Press it once, and the counter goes up by four.

This demonstration is about the gap between those two sentences. It covers what is actually being sold when you buy a switch, what the labels on the packet mean, what really happens in the few milliseconds after a contact closes, and what changes when the thing moving the contacts is a coil rather than a finger.

Why it is here, and here rather than later

Section titled “Why it is here, and here rather than later”

It looks like an elementary topic to be meeting this far into a module. There are two reasons for its position.

The first is the reading’s own. The chapters that follow explore an older kind of digital technology built from mechanical switch contacts rather than solid-state gates, and none of it can be read without knowing what a normally-closed contact is. Meeting switch circuits at the same time as logic gates makes both easier, and it sets up Boolean algebra.

The second is practical, and it is why this sits in the same section as the breadboard. A button is the first thing anybody wires to a circuit, and it is the first thing that misbehaves. The previous demonstration was about faults you can see if you look. This one is about a fault you cannot see at all, because it is over in three milliseconds.

Switch types is the catalogue. Hand switches, actuated by a person; limit switches, actuated by the motion of a machine; process switches, actuated by a physical quantity crossing a threshold. Pick one and its schematic symbol is drawn, and you can actuate it to see what the contacts do.

Poles, throws and normal is the vocabulary, made rather than described. Choose how many poles and how many throws you want and the switch is drawn and named, so SPST, DPDT and 4PDT stop being letters. It also has the selector-knob demonstration: drag the wiper slowly between two positions and watch what the common is connected to under break-before-make and under make-before-break.

Contact bounce is the centrepiece and the reason the page exists. There is a button. Press it, and an oscilloscope catches what actually reached the circuit. The timebase runs from 0.1 to 10 milliseconds per division, and it is worth using the whole range, because the same press looks like a clean edge at one end of it and a mess at the other. Then fit one of the two cures and press again.

Relays is a switch whose actuator is a coil, which is how a logic output ends up controlling something that could kill you. It covers the isolation, the contact ratings, the flyback diode, and the various ways a relay puts noise back into the circuit that drove it.

Switches, Contact Bounce and Relays

What is actually being sold, what the labels mean, what really happens when you press one, and what a coil lets you switch with it.

A switch is any device used to interrupt the flow of electrons in a circuit.

  • Switches are binary. They are completely on, which is closed, or completely off, which is open.
  • The simplest kind brings two conductors into contact by the motion of a mechanism.
  • Others contain electronics and respond to light, or to a magnetic field, or to a temperature.
  • Either way the device presents you with a pair of terminals that are joined or not joined.
  • What separates the families is not the contacts but what moves them: a person, a machine, or a physical quantity.
What actuates it

Actuated by a person.

Type
Symbol

Unactuated, which is the normal state, and the state it is in on the shelf.

Pushbutton

A button pressed and released.

Normal state: Usually spring-returned to the out position, so momentary.

  • The default is momentary: an internal spring pushes the button back out.
  • Some latch alternately on and off with each push, which is a different part rather than a different way of pressing it.
  • Some stay in until pulled back out, and those usually have a mushroom head so they can be grabbed. Emergency stops are this kind.
  • A momentary button tells you an event happened. It cannot tell you a state, because it does not hold one.
Momentary or latching, and why it matters before you write any code
  • A momentary switch is spring-returned, so it is only actuated while something is holding it there.
  • A latching switch stays where it was put, so it holds a state without anything holding it.
  • A momentary button reports an event. A latching switch reports a state. They are not interchangeable and no amount of software makes them so.
  • If you want a button to toggle something, the toggling is done in your circuit or your code, not by the button.
  • The same body is sold both ways, so the part number rather than the appearance is what tells you which you have.
Choosing one
  • There is usually more than one way to sense a thing, and usually no perfect switch for the job.
  • Match the actuation to what is actually available: a person, a moving part, or a quantity.
  • Prefer non-contact sensing where the machinery is fast or the duty is high, because nothing that does not touch can wear out.
  • Check the current and the voltage the contacts are rated for, and check them for the kind of supply you have. The two ratings are not the same.
  • Check the minimum current as well as the maximum, which is the wetting current on the next tab.
Why this is here at all
  • It looks like an elementary topic to meet this late in a module.
  • It is here because the circuits that follow are built out of mechanical contacts rather than solid-state gates, and they cannot be read without it.
  • Learning switch-based circuits alongside logic gates makes both easier, and it sets up Boolean algebra.
  • It is also here because a button is the first thing anybody wires to a microcontroller, and the first thing that misbehaves.

Step 1: Notice that the families are about actuation, not about contacts

Section titled “Step 1: Notice that the families are about actuation, not about contacts”

Open Switch types and step through the three families.

A toggle switch, a limit switch and a pressure switch are all the same thing electrically: a pair of contacts and a mechanism that moves them. What differs is what does the moving. That is why the symbols are all the same contact with a different actuator drawn on it, and why the symbol set is worth recognising rather than memorising.

Notice the proximity switch in particular. The diamond around it is not decoration: it says the device is electronic rather than a plain contact, and a non-electronic magnetic proximity switch uses the same symbol as the lever-actuated limit switch.

Step 2: Get momentary and latching straight

Section titled “Step 2: Get momentary and latching straight”

Still on the first tab, read the note under the panel.

A momentary switch is spring-returned, so it is only actuated while something is holding it there. A latching one stays where it was put. A momentary button reports an event; a latching switch reports a state, and no amount of software turns one into the other. If you want a button to toggle something, the toggling happens in your circuit or your code.

The same body is sold both ways, so it is the part number rather than the appearance that tells you which you have.

Step 3: Build the switch you have been writing on the parts list

Section titled “Step 3: Build the switch you have been writing on the parts list”

Open Poles, throws and normal and set poles to 2 and throws to 2.

The poles are the moving contacts, so two poles means two separate circuits switched by one actuator. The throws are the fixed contacts each pole can reach. Two throws means each circuit is transferred from one destination to another rather than simply interrupted, which is why a double-throw switch is never open for long and a single-throw one is.

Press Actuate the switch and watch which contacts light up. Then step through the presets: SPST, DPST, SPDT, DPDT, 4PDT.

Step 4: Learn what normal means, and then unlearn what you assumed

Section titled “Step 4: Learn what normal means, and then unlearn what you assumed”

Set throws to 1 and try the normally-open and normally-closed options.

Normal means unactuated. For a process switch, the honest way to work out its normal state is to picture it sitting on a shelf, uninstalled: a pressure switch sees zero pressure, a temperature switch sees room temperature, a level switch sees an empty tank, a flow switch sees no flow.

Now read the amber note, because this is the part that catches people out. A flow switch used as a low-flow alarm on a cooling system must be normally closed, even though the system’s normal operating condition is a steady flow. In service the flow holds the contacts open, and losing the flow lets them return to their normal, closed state and raise the alarm. If you think of normal as the usual state of the process you will get this backwards every time.

Drag the wiper position slider from position 3 to position 4, stopping half way.

With break-before-make, which is the usual arrangement, the common is connected to nothing at all while the wiper is between positions. With make-before-break it bridges the two, so the common is always connected to something, at the price of shorting adjacent positions together as it passes.

Neither is correct in general. Choose by asking which is worse in your circuit: a momentary open, or a momentary short between neighbours.

Step 6: Press the button and find out what really happened

Section titled “Step 6: Press the button and find out what really happened”

Open Contact bounce, leave the switch on the cheap tactile button, set the timebase to 1 ms per division, and press and hold.

The trace drops at time zero, and then does not stay down. It comes back up, goes down again, and repeats several times over the next two or three milliseconds before settling. The switch was pressed once. Read the third statistic: a counter clocked by this would typically have counted seven or eight times.

This is not a bad button and it is not a wiring fault. The moving contact has mass and the mechanism has elasticity, so the contact rebounds off the fixed one and comes back with less energy each time until the energy is gone.

Now let go, and look at the release. It bounces too, and on most parts it is the worse of the two, because a spring is releasing the contact rather than a finger placing it.

Step 7: Wind the timebase through its whole range

Section titled “Step 7: Wind the timebase through its whole range”

Set the timebase to 10 ms per division, and press again. The whole event is a barely visible flicker at the left of the screen.

Now set it to 0.1 ms per division. It is a long, detailed sequence of perfectly valid presses.

Both pictures are of the same press. The first is how it looks to a person, and it is why nobody notices this when they wire a switch to a lamp. The second is how it looks to a logic gate, and a 16 MHz processor executes something like ten thousand instructions inside a single millisecond, so from its point of view the bounce is not a glitch, it is a long conversation.

Step down the list of switches and press each one, using Fit the bounce to keep it on the screen.

The quality tactile button settles in about a third of a millisecond and the cheap one takes several times that. The toggle switch is worse again, because there is more mass in the moving part. The microswitch is unremarkable on the make and poor on the break.

Then press the mercury-wetted one. It does not bounce at all. That is the last item on the reading’s list of cures: once contact is made, the surface tension of the mercury maintains continuity even while the moving contact is rebounding. It also explains why the cure is not used: it is limited to low currents, it only works one way up, and mercury is toxic.

Step 9: Fit the two cures, and find what each one costs

Section titled “Step 9: Fit the two cures, and find what each one costs”

Under Cure it, choose the RC filter. Set the capacitor to 100 nF and press the button.

The amber trace is the voltage on the capacitor. It cannot follow the chattering, and the Schmitt trigger, which has two thresholds and will not change its mind between them, turns it into one clean edge. Watch the fourth statistic: with the filter fitted the answer still arrives almost immediately on the press, because a closed switch discharges the capacitor through a few hundred ohms. Now release the button and watch the same number, because the capacitor has to climb back through the whole 10 kΩ pull-up and the release is reported noticeably late.

Wind the capacitor down to 10 nF and press again. Bounces get through.

Now choose the firmware cure. The pin is sampled every millisecond and a change is not believed until it has held still for the whole settling window. It costs no components at all, which is why it is what you will actually write on the Arduino in the last section of the module. It costs latency instead, and the fourth statistic shows exactly how much.

Open Relays and energise the coil.

A relay is a switch actuated by a magnetic field rather than by a finger. The coil and the contacts are two separate circuits, and the only thing crossing between them is that field, which is drawn on the diagram along with the barrier it crosses. That isolation is the whole value of the part: a few milliamps from a logic output closing contacts that carry ten amps at mains voltage.

Everything from the bounce tab still applies. Relay contacts are mechanical contacts and they bounce like any other.

Switch Across the coil to nothing, and read what the coil reaches at switch-off.

A coil is an inductor, and an inductor opposes a change in its current. Interrupt that current and the coil generates whatever voltage it takes to keep it flowing, which runs to hundreds of volts in a few microseconds. The transistor driving it breaks down, and it does not survive doing that many times.

A diode across the coil, cathode to the positive end, gives that current a path. It circulates and dies away in the coil resistance, and the voltage is clamped about one diode drop above the rail. It is one component, it costs almost nothing, and it is not optional.

The last card on that tab is the one that is easy to skip and worth not skipping. A relay is a mechanical device carrying large currents, sitting next to logic that switches on millivolts of margin, and it injects noise in at least four ways: the unclamped coil at switch-off, the coil’s current step at switch-on pulling the rail down, the contacts arcing on the load side, and the contacts bouncing so that an inductive load is switched several times per operation.

The cures are the ordinary ones, and they are worth being able to name: a flyback diode on the coil, a snubber across the contacts, a separate return for the coil, decoupling on the logic, and physical distance.

Quiz
Select 0/1

A pushbutton is wired to the clock input of a counter. It is pressed once, and the counter advances by five. What is the most likely explanation?

Quiz
Select 0/1

A flow switch is used as a low-flow alarm on a cooling water system, and must close its contacts when the coolant flow is lost. Should it be normally open or normally closed?

Concept Match

Match each term to what it means

Quiz
Select 0/1

Why does a relay data sheet quote a higher contact rating for AC than for DC?

Quiz
Select 0/4

Which of these are genuine ways a relay puts electrical noise back into the low-voltage circuit that drove it? Select all that apply.

Quiz
Select 0/1

A 10 kΩ pull-up, a switch to ground and a 100 nF capacitor debounce a button, feeding a Schmitt trigger. Which statement is true?

Six things to take away.

  1. Switches are grouped by what actuates them rather than by what the contacts look like: hand switches by a person, limit switches by a machine, process switches by a physical quantity. The symbols are the same contact with a different actuator drawn on it.
  2. Poles are the moving contacts and throws are the fixed contacts each can reach, so a DPDT switch transfers two separate circuits between two destinations each. A momentary switch reports an event and a latching switch reports a state, and they are not interchangeable.
  3. Normal means unactuated, which for a process switch means the state it is in on the shelf. It has nothing to do with the usual state of the process, and a low-flow alarm is normally closed.
  4. Contacts bounce for a few milliseconds on both the make and the break. That is invisible to a lamp and enormous to a counter, a gate or a processor, and it is a property of mechanical contacts rather than a defect.
  5. Debouncing is done with an RC filter and a Schmitt trigger, or in firmware by demanding that the input hold still. Both work and both cost latency, and the second costs no components, which is why it is what you will write later in the module.
  6. A relay is a switch actuated by a coil, and it buys isolation and the ability to switch far more than a transistor could. It pays for that with contact wear, bounce, an inductive kick that needs a flyback diode, and a good deal of noise. Mains voltage is not something to build on a bench.

The next section leaves the physical layer behind and starts on the devices themselves. It is worth carrying one idea forward from here: everything above concerned a component that is either fully on or fully off, and the whole of the analogue material that follows is about devices that spend their useful lives somewhere in between.