Phipps Electronics

Order within the next 

FREE SHIPPING OVER $199

50,000+ ORDERS

WORLDWIDE SHIPPING

SSL SECURED

Using the Mini Magnetic Reed Module KY-021 with Arduino

Contents

Introduction:

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

Mini Magnetic Reed Module KY-021:

The KY-021 Module will be our main component for this tutorial. This module has a mini reed switch mounted on a breakout board with a resistor. Figure 1 shows the module as seen in fritzing.

Figure 1: KY-021 Mini Magnetic Reed Module

Pin Out:

The KY-021 module has three pins.

Component PinDescription
(-)GND
middle+5V
SSignal

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 Magnet Detector:

After learning about the KY-021 module and the reed switch, it is now time to build a project using the module. Our project will switch on the Arduino’s built-in LED if the KY-021 module detects a magnet.

Components:

For this project, we need the following components:

  • Arduino Uno board (1 pc.)
  • KY-021 Mini Magnetic Reed Module (1 pc.)
  • Jumper wires

Wiring Diagram:

Figure 2 shows the connection between the Arduino Uno and the KY-021 Mini Magnetic Reed Module.

Figure 2: Connection Diagram

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

Component PinDescription
(-)GND
middle+5V
SSignal

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-021.ino and upload it to your Arduino board.

				
					// Arduino and KY-021 module
void setup() {
  pinMode(8, INPUT);    // module connected to pin 8
  pinMode(13, OUTPUT);  // built-in LED of arduino
}
void loop() {
  if(digitalRead(8) == HIGH) digitalWrite(13, HIGH);  // module activates, switch On the LED
  else digitalWrite(13, LOW);
}
				
			

Project Test:

Apply power to your Arduino Uno board and bring a magnet near the reed switch. The LED should switch-on when the reed switch senses the magnet.

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