Reed Switch

Introduction: The Reed Switch module is a simple but powerful sensor that can detect the presence of a magnetic field. It consists of two ferrous materials encapsulated in a glass tube, which come into contact and complete an electrical circuit when exposed to a magnetic field. In this step-by-step guide, we’ll show you how to set up the Reed Switch module with an Arduino and create projects that respond to the presence of magnets.

Materials Needed:

  1. Arduino board (e.g., Arduino Uno, Arduino Nano)
  2. Reed Switch module
  3. Magnet (e.g., a small neodymium magnet)
  4. Breadboard and jumper wires
  5. USB cable for Arduino
  6. Computer with the Arduino IDE installed (

Step 1: Wiring

Connect the Reed Switch module to the Arduino board as follows:

  • Connect one end of the Reed Switch to the 5V pin on the Arduino.
  • Connect the other end of the Reed Switch to a current-limiting resistor (e.g., 10K ohms) and then to a digital pin on the Arduino (e.g., D2).
  • Connect the GND (Ground) pin on the Arduino to the GND pin on the Reed Switch module.

Step 2: Arduino Code

Open the Arduino IDE and create a new sketch. Then, enter the following code:

const int reedSwitchPin = 2; // Digital pin connected to the Reed Switch module

void setup() {
  pinMode(reedSwitchPin, INPUT_PULLUP); // Set the Reed Switch pin as INPUT_PULLUP
  Serial.begin(9600); // Initialize serial communication for debugging (optional)

void loop() {
  int reedState = digitalRead(reedSwitchPin); // Read the state of the Reed Switch
  if (reedState == LOW) {
    Serial.println("Magnetic field detected!"); // Display a message when a magnet is detected
    // Your custom actions or functions can be added here.
  // Add optional delay to prevent rapid repeated detections
  // delay(100);

Step 3: Uploading the code

Connect your Arduino board to the computer using the USB cable and select the appropriate board and port from the Arduino IDE. Then, click the “Upload” button to upload the code to the Arduino.

Step 4: Observing the Reed Switch Output

Once the code is uploaded successfully, open the Serial Monitor from the Arduino IDE (Ctrl + Shift + M). The Serial Monitor will display “Magnetic field detected!” whenever a magnet is brought close to the Reed Switch module.

Step 5: Experiment and Interact

Now that the Reed Switch module is set up and responding to magnets, you can experiment with different magnet placements and strengths. Adjust the code to trigger various actions or events in response to the presence of magnets. For example, you can use the Reed Switch module to detect the opening or closing of a door or window, build a magnetic security system, or create interactive installations.

Congratulations! You’ve successfully set up and used the Reed Switch module with Arduino. This versatile sensor allows you to detect the presence of magnets and opens up a wide range of possibilities for interactive projects and security applications. Have fun experimenting and incorporating the Reed Switch module into your Arduino projects to add a touch of magnetic magic!


Leave a reply

Your email address will not be published. Required fields are marked *



Log in with your credentials


Forgot your details?


Create Account