Source: https://mokxi.com/parts/reed
Updated: 2026-11-10

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.

Hold the button

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

Open or closed

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.

### Learn articles

1 lesson

- Arduino Reed Switch: Wiring, Code and a Door Alarm

Boards

## The boards it is shown on

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

- Arduino Uno R3
- ESP32-C3-DevKitM-1

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Reed switch

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

Start building free Open the editor
