Part

Reed switch

Two blades in glass that snap shut when a magnet comes near. Drag the magnet along it.

See every part
  • 2 pins
  • 3 settings
  • In 2 projects
  • In 1 lesson
Drawn live by the editor's own code, at the size you see it.
At a glance

The Reed switch in brief

What it is, and every setting the properties panel gives it.

A reed switch is two ferrous blades sealed in a glass tube, the sensor in door and window alarms, bike computers and lid interlocks. It has two legs and no supply or chip: one leg goes to a digital pin set to INPUT_PULLUP and the other to GND, on an Uno or an ESP32 alike, and the pin reads LOW while a magnet holds the blades shut. Mokxi’s slider is the magnet’s distance, 0 to 60 mm, starting open at 40. The switch closes at the close property, 15 mm by default, and opens again at close divided by release, 0.8 by default, so at 18.75 mm: the hysteresis every reed datasheet quotes as operate and release figures, and the reason a creaking door does not chatter. Each change bounces through a fixed burst of makes and breaks lasting settle, 0.5 ms by default, enough to count one opening twice without a debounce. The classic mistake is no pull-up, which leaves the pin floating while the switch is open. Contact ratings, welding on inductive loads, which way the field runs and a strong magnet holding it shut for good are not modeled.

Family
Sensors
Pins
2
close
15
release
0.8
settle
0.5
Pins

2 pins

Named as the editor names them, so a wire lands where you expect it.

  • 1
  • 2
How to use it

How to use a reed switch with an Arduino

A reed switch has two legs and no supply. In the door alarm one leg goes to pin 2 and the other to GND, and pin 2 uses the chip’s own pull-up, so the pin reads LOW while the magnet holds the blades shut and HIGH when the door opens and they spring apart.

Two things show up when you drag the magnet. The blades bounce for a fraction of a millisecond as they close, so the sketch only believes a reading that has held for 20 ms. And it closes at about 15 mm but holds on to nearly 19 mm, which is why a door that creaks a little does not set it off.

Part pin
Board pin
1
Pin 2 (INPUT_PULLUP)
2
GND

Any board wires it the same way, one leg to a GPIO with INPUT_PULLUP and the other to GND; on an ESP32 the pin simply reads 3.3 V when the switch is open.

Arduino Uno: door alarmlive0.000 s 0.00x
Hold the button
This is the simulator itself, running here. Click anything to open it in the editor.
Open or closed
const int REED = 2;
void setup() {
  pinMode(REED, INPUT_PULLUP);
  Serial.begin(115200);
}
void loop() {
  // HIGH is the pull-up with the blades apart: the door is open
  Serial.println(digitalRead(REED) == HIGH ? "open" : "closed");
  delay(200);
}
How it is modeled

What is true about the Reed switch, here

In its help article’s own words: what the simulation gets right, and where it stops.

The reed switch

Two steel blades in a glass tube, overlapping but not touching. A magnet near it magnetizes them, they attract each other and snap shut; take the magnet away and their own springiness pulls them apart. Every door sensor, every bike computer and every washing-machine lid interlock is one of these.

Drag the slider to move the magnet. Two things are modeled on purpose.

It does not let go where it grabbed. The switch closes at about 15 mm and holds on out to nearly 19, because once the blades are touching the magnetic circuit through them is better. Datasheets quote that as an operate and a release figure and Mokxi has it as close and release. It is why a door that creaks an inch does not set an alarm off, and it is the same shape of trick a sketch does in software when it adds hysteresis to a threshold.

The blades bounce. Not for the hundred milliseconds a rolling ball takes (they are light and stiff, and the datasheets say well under one), but enough to count one opening twice if the sketch believes the first edge it sees. settle is 0.5 ms by default and 0 turns it off. Like the tilt switch's, the pattern is fixed (the same five edges evenly spread every time) rather than the varying burst a real contact makes.

Not modeled on the reed: the magnet's orientation and pole (the slider is distance alone, where a real switch cares a great deal which way the field runs), the contact's current and voltage ratings, and the fact that a strong enough magnet will hold the blades shut permanently.

See it: Door alarm.

From Sensors that are a resistor or a switch, in full.

Projects

See the Reed switch in a project

2 built-in projects use it. Each opens in the editor, already wired.

Lessons

Where it turns up in a lesson

One lesson places it in its own circuit.

Boards

The boards it is shown on

Each of these 2 boards has a built-in project with the Reed switch in it.

Wire up the Reed switch

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.