Project36.Reed Switch Module

Description

The KY-025 Reed Switch Module is a small electrical switch operated by an applied magnetic field, commonly used as proximity sensor. The module has both digital and analog outputs. A trimmer is used to calibrate the sensitivity of the sensor. Compatible with Arduino, Raspberry Pi, ESP32 and other microcontrollers. For digital output only use the KY-021 mini reed switch.

Specification

Operation Voltage 3.3V ~ 5.5V Board Dimensions 1.5cm x 3.6cm

Connect

_images/36_bb.png

Code

int led = 13; // define the LED pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int analogVal; //analog readings

void setup()
{
pinMode(led, OUTPUT);
pinMode(digitalPin, INPUT);
//pinMode(analogPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
// Read the digital interface
digitalVal = digitalRead(digitalPin);
if(digitalVal == HIGH) // if temperature threshold reached
{
    digitalWrite(led, HIGH); // turn ON Arduino's LED
}
else
{
    digitalWrite(led, LOW); // turn OFF Arduino's LED
}

// Read the analog interface
analogVal = analogRead(analogPin);
Serial.println(analogVal); // print analog value to serial

delay(100);
}

Phenomenon

_images/36.jpg