Reed Switch Interfacing With Arduino

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

ARDUINO

Reed Switch Interfacing with Arduino


By Shashi Jul 27, 6
Kumar 2018

Reed Switch Interfacing with Arduino

Reed switch is used in many of the real-life applications such as magnetic door switch, laptops, smartphones etc. In this article, we learn about
Reed Switch and guide you to Interface a Reed Switch with Arduino.

Reed Switch
Reed switch is basically an electrical switch which is operated when a magnetic field is brought near to it. It was invented byW. B. Ellwood in
1936 at bell laboratories. It is made up of two small metal pieces kept inside a glass tube under vacuum. In a typical reed switch two metal pieces
will be made of a ferromagnetic material and covered with rhodium or ruthenium to give them long life. The switch will be activated when there is
a presence of magnetic field around the switch.
The glass enclosure of the two metal pieces protect them from dirt, dust and other particles. Reed switch can be operated in any environment
such as environment where flammable gas is present or environment where corrosion would affect open switch contacts.

There are two types of reed switch.

1. Normally open reed switch


2. Normally closed reed switch

In normally open reed switch, switch is open in the absence of magnetic field and it is closed in the presence of magnetic field. Under the
presence of magnetic field, two metal contacts inside the glass tube attract each other to make contact.

In normally closed reed switch, switch is closed in the absence of magnetic field and it is open in the presence of magnetic field.

Applications of Reed switch

Used in telephone exchange


In laptops to put the screen on sleep if the lid is closed
Used in window and door sensors in burglar alarm system

Components Required
Arduino Uno
Reed switch
Resistors
LED
Magnet
Connecting wires

Arduino Reed Switch Circuit Diagram


Working of Reed Switch with Arduino
Arduino Uno is a open source microcontroller board based on ATmega328p microcontroller. It has 14 digital pins (out of which 6 pins can be used
as PWM outputs), 6 analog inputs, on board voltage regulators etc. Arduino Uno has 32KB of flash memory, 2KB of SRAM and 1KB of EEPROM. It
operates at the clock frequency of 16MHz. Arduino Uno supports Serial, I2C, SPI communication for communicating with other devices. The table
below shows the technical specification of Arduino Uno.

Microcontroller ATmega328p

Operating voltage 5V

Input Voltage 7-12V (recommended)

Digital I/O pins 14

Analog pins 6

Flash memory 32KB

SRAM

Leiterplatten Discount
2L in 4AT, 100µm, Ø 0.2mm: 35€ 2KB

1-48 Lagen ab 1AT, z.B. Prototyp 4L: 59€ - 5AT, 6L:


98€, kein Privatverkauf

multi-circuit-boards.eu OPEN

EEPROM 1KB

Clock speed 16MHz

To interface reed switch with Arduino we need to build a voltage divider circuit as shown in the figure below. Vo is +5V when the switch is open
and 0V when the switch is closed. We are using a normally open reed switch in this project. Switch is closed in the presence of magnetic field and
it is open in the absence of magnetic field.

Code explanation
The complete code for this Arduino reed switch project is given at the end of this article. The code is split into small meaningful chunks and
explained below.

In this part of the code we have to define pins on which Reed switch and LED which is connected to Arduino. Reed switch is connected to digital
pin 4 of Arduino and LED is connected to digital pin 7 of Arduino through a current limiting resistor. The variable “reed_status” is used to hold the
status of reed switch.

int LED = 7;
int reed_switch = 4;
int reed_status;

In this part of the code, we have to set status of pins on which LED and reed switch is connected. Pin number 4 is set as input and pin number 7 is
set as output.
void setup()
{
pinMode(LED, OUTPUT);
pinMode(reed_switch, INPUT);
}

Next, we have to read the status of reed switch. If it is equal to 1, switch is open and LED is turned off. If it is equal to 0, switch is closed and we
have to turn on LED. This process is repeated every second. This task is accomplished with this part of the code below.

void loop()
{
reed_status = digitalRead(reed_switch);
if (reed_status == 1)
digitalWrite(LED, LOW);
else
digitalWrite(LED, HIGH);
delay(1000);
}

So as you have seen its very easy to use Reed Switch with Arduino.

Code
int LED = 7;
int reed_switch = 4;

int reed_status;

void setup()
{

pinMode(LED, OUTPUT);
pinMode(reed_switch, INPUT);

void loop()

{
reed_status = digitalRead(reed_switch);

if (reed_status == 1)
digitalWrite(LED, LOW);

else
digitalWrite(LED, HIGH);

delay(1000);
}

Video
TAGS ARDUINO UNO ARDUINO REED SWITCH MAGNETIC FIELD

RECOMMENDED ARTICLES AND WEBINARS

Deploy AI at the Edge – Free Webinar

IAR DevCon – Free Developer Conference for Embedded/IoT Engineers

Preparing for ISO 26262 Version 2 – Free Webinar

Thread Synchronization in Linux and Windows Systems, Part 1

Security in the 5G Era – Free Webinar

Watch Your Circuit’s Input Voltage During Power-Up!

For the Professional Maker: ClearCrawler Moves with the Help of Capacitors and nRF24L01+ Control

Beyond the ‘Scope of Real-Time Embedded Debugging

Get Our Weekly Newsletter!


Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest

Email Address *

Name

Country
United States of America

Subscribe

RELATED CONTENT
PREVIOUS POST
​How to Build a Raspberry Pi FM Transmitter

NEXT POST
Voice controlled Home automation using Amazon Alexa on
Raspberry Pi
Interfacing a PCF8591 ADC/DAC Module with Arduino

Charlieplexing Arduino - Controlling 12 LEDs with 4 GPIO Pins

DIY Arduino Power Supply Shield with 3.3v, 5v and 12v Output
Options

Arduino based Morse Code Generator

How to Use APDS9960 RGB and Gesture Sensor with Arduino

Arduino CAN Tutorial - Interfacing MCP2515 CAN BUS Module with


Arduino

DIY Arduino Digital Protractor using MPU6050 Gyroscope

Arduino based Text to Speech (TTS) Converter

COMMENTS

niyogakiza japhet
Jul 30, 2018 Log in or register to post
comments
how can we reprogram fm microcontroller

OmniSystems
Jul 31, 2018 Log in or register to post
comments
This is a simple program and perhaps a good example of the "basics" for a
beginner to start with, but if we just wanted to turn the LED off and on from the switch we really don't need an Arduino to do
that. Perhaps you can add some more programming so the reed switch could be the same as used for a burglar alarm and
placed on a door and the Arduino could send an email, a text (SMS) to a cell phone or perhaps a Windows text message
(broadcast) to a computer to alert that someone opened the door?

Hiro_Hamada
Aug 01, 2018 Log in or register to post
comments
Yeah point agreed. But still I think once we interface with Arduino and
learn how to read the sensor everything that you state can be done

Vince
Sep 09, 2018 Log in or register to post
comments
This tutorial perhaps represents the first step in a complex system- for
example, I'm using a reed switch to activate a custom pattern on a strip of WS2812 LEDs whenever my sliding pantry
door is opened. The strip is controlled by an Arduino NANO running the FastLED library, making it easy and fun to write
all kinds of custom patterns (every 100th door opening results in a surprise rainbow pattern, for example. :).

JMG Janssen
Aug 15, 2019 Log in or register to post
comments
@Shashi Kumar,

The schematic of the reedswitch shows a pullup resistor for the digital i/o. This is NOT a voltage divider circuit.

JMG Janssen
Aug 15, 2019 Log in or register to post
comments
You could also use the function internal pullup. There is no need for an external
resistor..

LOG IN OR REGISTER TO POST COMMENT

LATEST POSTS

Arduino Controlled Musical Fountain using Sound Sensor


Schottky Diode – Characteristics, Parameters and Applications

New surface mount inductors to meet complex requirements of today’s high power density

Display Controller Sales to Generate US$ 23 Bn Revenue in 2019

What is Blockchain and how can it be used to keep your data secure

NEWS ARTICLES PROJECTS

New surface mount inductors to meet complex requirements of today’s high power density
Display Controller Sales to Generate US$ 23 Bn Revenue in 2019

New VIPer Converter Features High MOSFET Breakdown Voltage for Robust and Reliable Power Supplies

Maxim Integrates the Most Advanced Battery Protector to Deliver the Highest Level of Safety in Industry’s Most Accurate,
Lowest Quiescent Current Fuel Gauge ICs

Figure 1 Top-15 Semiconductor Suppliers’ Sales Fall by 18% in 1H19

Connect with us on social media and stay updated with latest news, articles and projects!

CATEGORIES

Embedded Electronics

Power Electronics

Analog Electronics

Internet of Things

Audio Electronics

Electric Vehicles

POPULAR

ROBOTICS 555 CIRCUITS ARDUINO PROJECTS RASPBERRY PI PROJECTS ELECTRONICS NEWS ELECTRONICS FORUM

CALCULATORS

NEWSLETTER

Sign Up for Latest News

Enter your email

Subscribe

Hardware Startup?

This website uses cookies to improve user experience. By using the website you are giving your consent to set cookies. For more information,
read our cookie policy and privacy policy. Copyright © 2019 Circuit Digest. All rights reserved.

Privacy Policy | Cookie Policy | Terms of Use | Contact Us | Advertise


OK, I Understand

You might also like