Arduino Magnetic Reed Switch KY-021

Hello world! yep yep, i made another simple example project.
This time for the KY-021 Mini reed switch. / Arduino Magnetic Reed Switch.
It will simply turn on and off a light with a relay by using a magnetic field.
Reed switches are used allot in burglar alarms.

Schematic:
Ky-021 Arduino Magnetic Reed Switch

Parts list:
Arduino Uno, I used the robotdyn Uno.. one with 7 analog pins! Very good stuff! buy it!
KY-021 Mini reed Switch
KY-019 1 Channel Relay.
A magnetic field, can be any magnet but best to use is a small one. Or even better a magnet from a alarm.
Set of jumper wires. MM/FF/MF
Lamp + power cable (optional) dont need this! The relay itself will show you if it works by turning on a led.

Code:

//Author: Danny van den Brande, arduinosensors.nl.
//Hello world! I made a simple example on the KY-021 mini reed switch / Arduino Magnetic Reed Switch.
//Do what ever you like with this code! This code will turn on a relay.
//In my video i used a lamp, but you can add any device to the relay if you want.
//reed switches can be used for a dozen of things but is mostly known for its use
//in burglar alarms, and work with a magnetic field.
int Relay = 9 ;
int MiniReed = 8; 

int val ;
void setup ()
{
  pinMode (Relay, OUTPUT);
  pinMode (MiniReed, INPUT);
}
void loop ()
{
  val = digitalRead (MiniReed) ;
  if (val == HIGH) 
  {
    digitalWrite (Relay, HIGH);
  }
  else
  {
    digitalWrite (Relay, LOW);
  }
}

What is a reed switch?
The reed switch is an electrical switch operated by an applied magnetic field. It was invented at Bell Telephone Laboratories in 1936 by W. B. Ellwood. It consists of a pair of contacts on ferrous 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 to 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.
Source:wiki

Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *