KY-021 Mini Reed Switch Module


Arduino magnetic reed switch module Keyes KY-021. A reed switch is a magnetic sensor that is normally open and gets closed when exposed to a magnetic field.


The KY-021 Mini Magnetic Reed Switch Module consists of a 10kΩ resistor and a small reed switch actuated by a magnetic field, commonly used in mechanical systems as proximity sensors. Compatible with popular electronic platforms like Arduino, Teensy and ESP8266.

Operating Voltage3.3V to 5v
Output TypeDigital

KY-021 Connection Diagram

Connect the module's Power line (middle) and ground (-) to +5 and GND respectively. Connect signal (S) to pin 2 on the Arduino.

KY-021 Arduino Connection diagramclick to enlarge

KY-021 Arduino Example Code

The following sketch will turn on the pin 13 LED on the Arduino when the module detects a magnetic field. Place a magnet near the KY-021 to activate the reel switch.

int led = 13; // LED pin
int reelSwitch = 2; // magnetic senso rpin
int switchState; // variable to store reel switch value

void setup() 
  pinMode (led, OUTPUT);
  pinMode (reelSwitch, INPUT);

void loop()
  switchState = digitalRead(reelSwitch); // read the value of digital interface 2 and assign it to switchState
  if (switchState == HIGH) // when the magnetic sensor detect a signal, LED is flashing
    digitalWrite(led, HIGH);
    digitalWrite(led, LOW);

Leave a Reply

1 Comment threads
1 Thread replies
Most reacted comment
Hottest comment thread
2 Comment authors
pepito perezsai Recent comment authors

hi, how to contact you

pepito perez
pepito perez

hi, she don’t love u :’v