略過產品資訊
1 / 1

HK STEM CLUB

KY-021 迷你磁簧模組 Mini Magnetic Reed Switch Module

KY-021 迷你磁簧模組 Mini Magnetic Reed Switch Module

定價 HK$15.00
定價 售價 HK$15.00
特價 售罄
查看完整資訊

Description

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.

  • Arduino KY-021 Mini Magnetic Reed Switch Module

  • KY-021 magnetic reed switch Fritzing part image

Specifications

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 Voltage 3.3V to 5v
Output Type Digital

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
S 2
middle +5V
- GND
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);
  }
  else 
  {
    digitalWrite(led, LOW);
  }
}