Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

Using the Reed Switch Module KY-025 with Arduino

Contents

Introduction:

In this tutorial, we will learn about the KY-025 module, what is a reed switch and we will build a simple project using the KY-025 module and an Arduino.

Reed Switch Module KY-025:

The KY-025 Module will be our main component for this tutorial. This module has a reed switch, and an LM393 differential comparator mounted on a breakout board with a potentiometer and several resistors. Figure 1 shows the module as seen in fritzing.

Figure 1: KY-025 Reed Switch Module

Pin Out:

The KY-025 module has three pins.

Component PinDescription
A0Analog output
GGround
(+)+5V
D0Digital output

What is a Reed Switch?

A reed switch is a type of switch that turns on and off when there is a strong magnetic field nearby.

Project:

Arduino Magnetic Sensor:

After learning about the KY-025 module and the reed switch, it is now time to build a project using the module. Our project will get the analog and digital signals from the KY-025 module, display it on the serial monitor, and control the Arduino’s built-in LED.

Components:

For this project, we need the following components:

  • Arduino Uno board (1 pc.)
  • KY-025 Reed Switch Module (1 pc.)
  • Jumper wires

Wiring Diagram:

Figure 2 shows the connection between the Arduino Uno and the KY-025 Reed Switch Module.

Figure 2: Connection Diagram

The KY-025 module pins are connected to the Arduino Uno board as follows:

Component PinDescription
A0A0
GGND
(+)+5V
D08

Code:

Below is the Arduino sketch for our project. I have added comments to explain important parts of the code. Save the code as KY-025.ino and upload it to your Arduino board.

				
					// Arduino and KY-025 module
void setup ()
{
  pinMode (13, OUTPUT); // built-in LED pin set to output
  pinMode (8, INPUT);   // module digital output connected to Arduino pin 8
  Serial.begin(9600);   // initialize serial
}
void loop ()
{
  Serial.print("Analog pin: "); // display analog and digital values to serial
  Serial.print(analogRead(A0));
  Serial.print(" | Digital pin: ");
  if (digitalRead(8) == HIGH) {
    Serial.println("High");
    digitalWrite (13, HIGH); // if magnetic field is higher than threshold , switch-On built-in LED
  }
  else {
    Serial.println("Low");
    digitalWrite (13, LOW);
  }
  delay(100); // wait 100 milliSeconds
}
				
			

Project Test:

Apply power to your Arduino Uno board and open the Serial Monitor in the Arduino IDE. Arduino will output the analog value sent by the module to the serial monitor. If the value reaches the threshold setpoint set by VR1, the built-in LED of the Arduino will also light-up. Adjust the threshold by turning VR1.

SUBSCRIBE FOR NEW POST ALERTS

Subscribe to be the first to know when we publish a new article!
List Subscriptions(Required)

POPULAR POSTS

Scroll to Top