Reed Switch Interface Circuit Design

A reed switch is two ferromagnetic blades sealed in a glass capsule, closed by a magnetic field. It needs no supply, works from millivolts to hundreds of volts and survives millions of operations, which is why it still appears in door sensors, flow meters, level floats and pulse counters. The interface looks trivial and behaves badly when the details are ignored.

Why the Contact Is Not Ideal

A closed reed switch is a mechanical contact, not a resistor. Its resistance is a few tens of milliohms when new and rises with wear, and the blades bounce against each other for a few hundred microseconds each time they close. A microcontroller that samples the pin fast enough will see a burst of edges rather than one.

Contact bounce is a property of the mechanism and cannot be filtered at the source. It has to be rejected either in hardware with a filter or in software with a time window, and the design has to allow for the contact staying open for a long time and then closing again.

The contact also has a limited current rating and a limited voltage rating. Exceeding the current erodes the plating and welds the blades together, while exceeding the voltage draws an arc that keeps the gap conducting. Both limits are in the datasheet and both are commonly ignored.

Choosing the pull-up resistor

A pull-up resistor defines the state of the input when the switch is open and sets the current through the contact when it is closed. A small resistor gives a fast edge and good noise immunity, but the current heats and erodes the blades; a large resistor is gentle on the contact but the input becomes slow and sensitive to leakage.

For a microcontroller input, a value between ten and a hundred kilohms is the usual compromise. At three point three volts, a hundred kilohms passes thirty three microamps through the contact, which is far below the erosion threshold and still gives a clean logic level.

The pull-up can be internal to the microcontroller, which saves parts, but the internal resistance varies widely between devices and is poorly specified. An external resistor with a known value makes the timing of the filter predictable and costs almost nothing.

Hardware debounce and Filtering

A capacitor across the switch, with a series resistor forming a low pass filter, removes the bounce in the analog domain. The capacitor charges through the pull-up while the contact bounces open, so the voltage does not follow every microsecond of movement.

The time constant has to be longer than the bounce and shorter than the fastest genuine event. A few milliseconds suits a door contact, while a flow meter pulse train at a kilohertz needs something faster and probably a different sensor. Calculating the corner from the expected pulse width avoids guessing.

Take care with the capacitor when the switch is at the end of a long cable. The cable capacitance adds to the filter, and the pull-up then has to charge a much larger load, which slows both edges and can hide genuine short pulses. A Schmitt trigger input with hysteresis restores the clean edges. The general principles behind that stage are the same as for any slow sensor input and are described in our guide to mixed signal board design.

Glass reed switch capsule mounted on a sensor board

Debounce in Software

Software debounce reads the pin, waits, and reads it again. The simplest form requires several consecutive samples with the same value before the state is accepted, and the sample period is chosen from the measured bounce time of the switch.

A state machine that distinguishes a stable open, a debounce window and a stable closed handles both edges and cannot be confused by a slow closure. It also gives a natural place to count events for a pulse input, and to place a minimum interval between counted events.

The debounce is not a substitute for a hardware filter when the contact is far from the processor. Noise picked up on a long cable appears as a burst of random edges that no time window can reject, because the noise lasts as long as the disturbance. Filtering at the pin, and a shielded cable, are the answer there.

the magnet actuator and Its Field

The magnet actuator determines when the switch closes. The field strength falls steeply with distance, so a few tenths of a millimetre of mounting tolerance changes the operate point. The datasheet quotes a range of operate values, and the design should use the worst case rather than the typical.

The orientation matters as much as the distance. A reed switch responds to the field along its axis, so a magnet that approaches from the side, or that rotates during operation, produces a different response. Keeping the axis aligned with the direction of travel makes the operate point repeatable.

A latching reed switch holds its state after the field is removed, which suits a position indicator that must survive a power failure. The interface is the same, but the firmware has to know that the state is not a function of the present field.

Pull-up resistor and debounce capacitor layout for a reed switch input

Protection and Long Cable Runs

A reed switch connected by a long cable behaves as an antenna. A series resistor at the input and a capacitor to the local ground divert induced energy, and a pair of clamp diodes limits the voltage at the pin to the supply rails.

Where the switch is in an industrial environment, an optocoupler at the interface gives isolation and allows the contact to be driven from a separate supply. The current through the contact is then set by the optocoupler input rather than by the logic rail, which is often more convenient.

Reverse voltage is the other risk. A cable that is miswired places the supply across the switch and the input together. A series diode or a bridge at the connector makes the input polarity insensitive and costs a few cents.

Verification and Reliability

Measure the contact resistance with a four wire method rather than a multimeter on a two wire range. The resistance of a healthy reed switch is small enough to be hidden by the lead resistance, and the change with age is best seen as a trend across units.

Cycle the switch through its rated number of operations and check the operate point at intervals. A switch that begins to operate at a much shorter distance is losing its blade tension, and it will eventually fail to close at all. This test is a few days of bench time for a part that will be in the field for years.

Check the assembly for stray ferromagnetic material. A steel screw or a nickel plated bracket next to the capsule diverts the field and shifts the operate point, and the fault appears only in the units where the screw is fitted. The inspection points that catch this kind of build variation are collected in our guide to judging PCB quality, and the release checks that cover the input stage are in our PCB design release checklist.

FAQ

Why does my reed input count extra pulses? Contact bounce and cable noise both produce extra edges. Add a hardware filter at the pin and a debounce window in software, and check the cable shield.

What pull-up resistor should I use? Between ten and a hundred kilohms at three point three volts is a good starting point. It keeps the contact current low while giving a clean logic level.

Can a reed switch drive a relay directly? It can switch a small load within its current and voltage ratings. Beyond that, use the reed switch to drive a transistor or an optocoupler.

Leave A Comment