This project uses a reed switch to determine when the mailbox door has been opened, and when it is closed again. Reed switches come in many form factors, including like the one shown below which is designed to be mounted onto something. In this case, the switch itself is contained within the half that has the three screw terminals on it. The other half is the matching magnet.

A reed switch is like any other switch, for example, a push button switch. However, instead of activating the switch with your finger, you activate it with a magnet.

The are two forms of reed switches that are most common. The first one is a normally open (NO) reed switch, which has two terminals. The second one is both NO and normally closed (NC), which has three terminals, NO, NC, and common. Standalone NC reed switches exist, but are highly uncommon and difficult to find.

For this project, you are required to use a switch that has a NC terminal. Since NC reed switches are rare, that typically means using a reed switch that has both NC and NO functionality.

Reed switches are in their initial state when the magnet is not present. As indicated by the names, a normally open (NO) switch's initial state is open, and a normally closed (NC) switch's initial state is closed.

For a NC switch, when there is no magnet present, the circuit between the normally closed terminal and the common terminal is completed, which means electricity is flowing through the circuit. When the magnet is introduced, the switch opens, which means no electricity is flowing through it. (NO switches are the opposite.)

When purchasing three-terminal reed switches, depending on where or what manufacturer you get your reed switch from, the terminals or wires may not come labeled, or, even worse, they may be labelled the opposite of what you expect (NC is marked as NO, and vice versa). This page is here to guide you through identifying the appropriate reed switch terminals to connect to your Feather. Starting here can save you a lot of troubleshooting later.

There are two options provided to identify the terminals on your reed switch: using a multimeter, or running a CircuitPython program. The multimeter method requires to you to have a multimeter. The program method is most easily done using your microcontroller on a breadboard.

Multimeter Continuity Mode

First, power your multimeter on and set it to continuity mode. If you're unsure how to do this, check the Multimeter guide for details.

The continuity setting on a multimeter is measuring resistance in ohms. When there is no continuity, multimeters will show various things on the display, including 1, OL, or -1. To sort out how your specific multimeter displays continuity and a lack thereof, try the following.

First, verify what your display shows when there is no continuity.

Make sure the probes are separated, and you will see what the initial display is for your specific multimeter. The multimeter used for this demonstration displays OL.

Then, verify how your multimeter indicates continuity.

Bring the probe tips together. You will see the display update with a number of ohms. As well, you may hear a beep, but only if the beep is a feature of your multimeter's continuity mode.

These are the two different results you will be looking for while identifying your reed switch terminals.

When checking for continuity, it doesn't matter which probe is held against which end of the circuit. Continuity is indicated when the circuit is complete, which is irrelevant to probe location.

Using a Multimeter to Identify your Reed Switch Terminals

The following steps will walk you through how to use a multimeter to determine which switch terminal is common, NC, and NO.

Begin with the magnet separated from the reed switch.

Choose any two terminals, and hold each of the multimeter probes against one terminal.

If the multimeter doesn't show continuity, there is no continuity between the two terminals.

Check the other terminal pairs, by moving the probes around.

When continuity is indicated, this means you have found the common and the normally closed (NC) terminals. However, you don't know which is which yet.

For the purposes of this project, this is enough information. This project does not care which terminal is wired to which pin, as long as they are the common and NC terminals. The Soldering and Assembly section will refer to connecting common to the ground pin, and normally closed to a specific digital pin. However, either terminal can be connected to either pin.

If you're interested in learning how to identify which terminal is common and which terminal is NC, feel free to continue through the rest of the steps.

The next two steps require the magnet to be present against the reed switch.

Check each of the terminal pairs again for continuity.

When continuity is indicated, it means you have found the common and the normally open (NO) terminals. However, you still don't know which is which yet.

Now it's time to determine exactly which terminal is which.

There will be one terminal that caused continuity in both cases, i.e. with and without the magnet present. This is your common terminal.

The first image shows continuity without the magnet. The second image shows continuity with the magnet present. The terminal that is common to both images is marked with an arrow. On this reed switch, this is the common terminal.

Now that you've identified your common terminal, separate the magnet from the reed switch. Hold one probe against the common terminal, and verify which of the other two terminals causes continuity. Continuity with the common terminal is indicated on the third terminal. That is your NC terminal.

You identified the common and NC terminals as the two outside terminals. Therefore, you now know the middle terminal is the NO. (You can verify this by reintroducing the magnet, and checking continuity on the common terminal and the NO terminal.)

Now you know the identification of all three terminals!

Project assembly will be easier if you label the two pins you intend to use.

Using CircuitPython to Identify Your Reed Switch Terminals

Another option is to let CircuitPython tell you which terminal is which. This code verifies which terminals result in connectivity to which other terminals, and uses that information to identify which terminal is normally closed (NC), which is common, and which is normally open (NO).

Wiring

First, you'll need to wire the reed switch to your Feather so that all three terminals are connected.

The following diagram uses the Feather ESP32 V2, and the default pin assignments in the code match the diagram. You can substitute any CircuitPython-compatible microcontroller, and any pin combination, as long as the code is updated to match.
  • Attach wires to all three terminals on your reed switch.

Reading left to right, connect the following:

  • Reed switch terminal 1 to Feather D15.
  • Reed switch terminal 2 to Feather D32.
  • Reed switch terminal 3 to Feather D14.

CircuitPython Code

Download the following using the Download Project Bundle button, and load code.py onto to your microcontroller.

# SPDX-FileCopyrightText: 2022 Brian Rossman
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
A CircuitPython program to identify reed switch terminals on a switch with three
terminals (normally closed, normally open, and common). This code is not designed
for two terminal reed switches.
"""
import time
import board
import digitalio
import supervisor

# Update these pins to match the pins to which you connected the reed switch.
TERMINAL_ONE = board.D14
TERMINAL_TWO = board.D32
TERMINAL_THREE = board.D15

# Create digital pin objects using the pins defined above.
pin_1 = digitalio.DigitalInOut(TERMINAL_ONE)
pin_2 = digitalio.DigitalInOut(TERMINAL_TWO)
pin_3 = digitalio.DigitalInOut(TERMINAL_THREE)

# Wait for the serial connection to be established.
while not supervisor.runtime.serial_connected:
    time.sleep(0.25)
time.sleep(1)

# Prompt and wait for confirmation the magnet is NOT near the reed switch.
print("Ensure no magnet is near the reed switch.")
print("Press ENTER to continue")
input()  # Waits for you to press enter to continue.

# Set Terminal 1 as the only output.
pin_1.switch_to_output()

# Set Terminal 2 & 3 as inputs to detect connectivity.
pin_2.switch_to_input(pull=digitalio.Pull.UP)
pin_3.switch_to_input(pull=digitalio.Pull.UP)

# Set the output pin to False.
pin_1.value = False

# Negate pin logic due to use of pull-up.
ab_common = not pin_2.value
ac_common = not pin_3.value

# Prompt and wait for confirmation the magnet IS near the reed switch.
print("Place the magnet against the reed switch.")
print("Press ENTER to continue")
input()  # Waits for you to press enter to continue.

# Negate pin logic due to use of pull-up.
b_when_closed = not pin_2.value
c_when_closed = not pin_3.value

# Print pin assignments for reference.
print(f"Terminal pin assignments:\nTerminal 1 = {TERMINAL_ONE}" +
      f"\nTerminal 2 = {TERMINAL_TWO}\nTerminal 3 = {TERMINAL_THREE}\n")

# Print which terminal is Normally Closed, Common, and Normally Open.
if ab_common and not ac_common and not b_when_closed and not c_when_closed:
    print("Normally Closed: Terminal 1, Common: Terminal 2, Normally Open: Terminal 3")
elif not ab_common and ac_common and not b_when_closed and not c_when_closed:
    print("Normally Closed: Terminal 1, Common: Terminal 3, Normally Open: Terminal 2")
elif ab_common and not ac_common and not b_when_closed and c_when_closed:
    print("Normally Closed: Terminal 2, Common: Terminal 1, Normally Open: Terminal 3")
elif not ab_common and not ac_common and not b_when_closed and c_when_closed:
    print("Normally Closed: Terminal 2, Common: Terminal 3, Normally Open: Terminal 1")
elif not ab_common and ac_common and b_when_closed and not c_when_closed:
    print("Normally Closed: Terminal 3, Common: Terminal 1, Normally Open: Terminal 2")
elif not ab_common and not ac_common and b_when_closed and not c_when_closed:
    print("Normally Closed: Terminal 3, Common: Terminal 2, Normally Open: Terminal 1")
else:
    # All options are covered above. If none are valid, there may be an issue with your wiring.
    print("Something went wrong, check connections and try again.")

Now, run the code and connect to the serial console.

First, you will be prompted by the following. As it says, make sure there is no magnet near the reed switch, and press enter on your keyboard.

Next, you'll be prompted by the following. Again, follow the instructions by holding a magnet against the reed switch, and while the magnet is held in place, press enter on your keyboard to continue.

Finally, you'll see there results. First, the serial console lists which terminals are assigned to which pins for reference, so you don't have to go back through the code to figure out how you wired it. Then, it prints out which terminal is normally closed, common, and normally open, in that order.

Since you only need NC and common for this project, you'll want to label those two terminals to make project assembly smoother.

Between those two options, you should have successfully identified the terminals on your reed switch, regardless of what the product copy or terminal labels indicate. The next step is assembly!

This guide was first published on Sep 14, 2022. It was last updated on Apr 15, 2024.

This page (Identify Your Reed Switch) was last updated on Apr 15, 2024.

Text editor powered by tinymce.