Magnetic Reed Switch Sensor Module Review and code examples

This post reviews a magnetic reed switch sensor module. There are many of these available on the internet and all work similarly using a basic reed switch. Here I review and test the sensor and provide code to use it.

Overview of the Magnetic Reed Switch sensor

The magnetic reed switch Arduino module shown to the left is one of the many available on the internet. There are a number of minor differences in these sensor modules but many are very similar to this one.

I choose this Arduino sensor as it was one of the most common sensors available in this category.

The sensor has three pins, from left to right on the sensor Digital Out (DO), Ground (GND) and input voltage (VCC). When the sensor reaches a specific level of magnetism detected it will output as LOW on the digital out pin.

There are two LED’s on the board, the right LED is lit when the sensor is powered. If you have connected up the sensor and this is not lit you will want to check your power.

The left LED is lit when the output is LOW, LOW represents that there is a level of magnetism higher than the given value set on the potentiometer.

On the right of the sensor there is a blue potentiometer. This can be adjusted to change the level of magnetism needed to trigger the sensor.  This allows me to adjust the specific level required to the application.

Wiring it up to an Arduino

To test this sensor I am going to wire it up to an Arduino Uno. Shown on the left I am wiring up the connections D0, GND and VCC.

I have wired D0 to the Arduino’s digital Pin 2 to read in the data from the sensor.

The GND and VCC pins have been connected to the Arduino’s GND and 5 volt pins respectively.

Once wired up I can turn on the Arduino and adjust the potentiometer to configure when it should turn the digital output low.

Each time you change the situation that the reed switch is designed to activate it is recommended to calibrate it. This is because the amount of magnetism applied to the switch will vary depending on how you are activating it.

Programming the Arduino

Since the sensor outputs a basic digital signal we only need a small amount of code to check its state. Here I define a variable to hold whether it has detected a magnet. In addition, I define a constant for the Arduino pin I am going to connect the DO pin on the sensor to.

#define REED_IN_PIN 3
int magneticPresence = LOW;

void setup() {

void loop() {
  magneticPresence = digitalRead(REED_IN_PIN);

In the setup method I start up the serial so we can output the sensor value. Then in the loop method I read the sensor and output it.

Final Review

The reed switch is module is a nice way of detecting a magnetic field. Using this Arduino sensor you can adjust the level in which the digital sensor outputs a positive signal. This is helpful as you can easily calibrate the device using the hardware potentiometer.

A good use of this sensor is to check when a magnet is moved close to the sensor. This can be achieved by placing it on a door or similar which will move into the reed switch.

Overall a very nice little sensor.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.