KY-025 Reed Switch Module and Arduino

The KY-025 Reed Switch Module is a small electrical switch which operates with an applied magnetic field, the module can be used as proximity sensor.

KY-025 Reed Switch Module
KY-025 Reed Switch Module

The module has digital and analog outputs. A potentiometer is used to calibrate the sensitivity of the sensor for the analog output whereas the digital output is simply either 1 or 0 depending on whether the switch is open or closed, the digital mode is the easiest to use.

What is a reed switch?

The reed switch is an electrical switch operated by an applied magnetic field. It consists of a pair of contacts on ferromagnetic metal reeds in a hermetically sealed glass envelope. The contacts may be normally open, closing when a magnetic field is present, or normally closed and opening when a magnetic field is applied. The switch may be actuated by a coil, making a reed relay, or by bringing a magnet near the switch. Once the magnet is pulled away from the switch, the reed switch will go back to its original position.

An example of a reed switch’s application is to detect the opening of a door, when used as a proximity switch for a burglar alarm.

Parts List

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
Sensor kit 37 IN 1 SENSOR KITS FOR ARDUINO HIGH-QUALITY FREE SHIPPING (Works with Official for Arduino Boards)
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Connection

This is the connections we used

Connect the board’s analog output (A0) to pin A0 on the Arduino and the digital output (D0) to pin 2. Connect the power line (+) and ground (G) to 5V and GND.

KY-025 module Arduino connection
A0 A0
G GND
+ 5V
D0 2

 

arduino and ky025 layout
arduino and ky025 layout

Code

Example 1

[codesyntax lang=”cpp”]

const int reedPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
int reedState = 0;         // variable for reading the reed switch status
  
void setup() 
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(reedPin, INPUT);     
}
 
void loop()
{
  // read the state of the pushbutton value:
  reedState = digitalRead(reedPin);
  // check the reed switch is .
  // if it is, the buttonState is HIGH:
  if (reedState == HIGH) 
  {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else 
  {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

[/codesyntax]

Example 2

[codesyntax lang=”cpp”]

// Arduino pin numbers
//D2 and A0 used on board and connected to D0 and A0 on the module
//G ground
//+ 5V
//open arduino console - upload the code and watch the result
 
const int digital = 2;
const int analog = 0;
 
void setup()
{
pinMode(digital, INPUT);
Serial.begin(115200);
}
 
void loop()
{
Serial.print(digitalRead(digital));
Serial.print("-");
Serial.println(analogRead(analog));
delay(250);
}

[/codesyntax]

 

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :