How To Connect A Reed Switch Module To Arduino

Table of contents:

How To Connect A Reed Switch Module To Arduino
How To Connect A Reed Switch Module To Arduino

Video: How To Connect A Reed Switch Module To Arduino

Video: How To Connect A Reed Switch Module To Arduino
Video: Connecting Reed switch module with Arduino 2024, December
Anonim

The name "reed switch" comes from the phrase "sealed contact". And this explains its structure. In fact, a reed switch is two open (or closed) contacts located in a vacuum flask, which change their state to the opposite when exposed to a magnetic field. Reed switches are very popular sensors that are used in many applications. This includes control of door opening / closing, various actuation counters, speed counters, etc. Let's connect a reed switch to the Arduino and see how it works.

Module with reed switch
Module with reed switch

It is necessary

  • - Arduino;
  • - a module with a reed switch or just a reed switch;
  • - permanent magnet;
  • - a computer.

Instructions

Step 1

Let's connect the reed switch module to the Arduino according to the diagram below. Power is supplied from 5 V or from 3.3 V. Connect the signal to digital pin D2.

The reed switch module contains a 10 kΩ variable resistor. With this resistor, you can set the reed switch threshold and thus adjust the sensitivity. The module also contains an LM393 comparator to exclude false alarms of the magnetic sensor.

Wiring a reed switch module to Arduino
Wiring a reed switch module to Arduino

Step 2

Let's write a sketch of processing the reed switch actuation. Everything is simple here. Set the pin number to which we connect the module output - "2", and turn it on for "wiretapping". We activate the pull-up resistor on the leg "2". We set pin 13 as the output. We turn on the serial port at a speed of 9600 baud. And then every 20 ms we read the readings of the reed switch and send the value to the port. If the reed switch is open - "1" is displayed, if closed - "0" is displayed.

In addition, the LED on the 13th leg of the Arduino glows as long as the reed switch contacts are closed. Pay attention to the inversion of the signal read from the sensor.

Sketch for processing reed switch actuation
Sketch for processing reed switch actuation

Step 3

Connect the power to the Arduino. The LED on the module will light up, indicating that the module is powered.

Now we bring a permanent magnet to the reed switch - the reed switch contacts will close and the LED will light up, indicating that the reed switch is activated. Remove the magnet again - the reed switch will open and the LED will go out. If we turn on the port monitor, we will see the actuation of the reed switch in the form of zeros among the stream of ones when the contact is open.

Reed switch actuation
Reed switch actuation

Step 4

Let's connect a separate reed switch to the Arduino. Everything is extremely simple here. The reed switch is connected in the same way as the button, with a 10 kOhm resistor. The program will remain the same.

Turn on the power, bring the magnet to the reed switch - the Arduino LED will light up while the reed switch contacts are closed.

Recommended: