Reed-switch Interfacing with Arduino UNO and LCD

Hello friends, In this short tutorial I will give you knowledge about "How to interface reed switch with Arduino UNO and LCD." 


Instead of reed switch we can use any other switches like tilt switch, push button, PIR sensor or something that gives output as PIR sensor gives(IR Proximity sensor) and so on.

Ok, Lets start,

At first we have to learn about "What is reed switch."
Image result for reed switch
Reed-switch is a type of switch which is controlled by magnetic field i.e (Magnet).
When magnet comes near the reed switch, it will works as close switch and vice-versa.
But it is not like a "Hall Effect Sensor"



Ok, take a look of this circuit:-

We can use buzzer or LED in pin 13.

VIDEO:  
https://www.youtube.com/watch?v=PxTf_ru6LdM&t=2s


CODE:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int LED = 13;   //pin for the LED
int SWITCH = 7;   //INPUT pin where the REED-SWITCH is connected
int BUTTON_STATE = 0;   //whether switch is ON or OFF
void setup() {
  lcd.begin(16,2);
  lcd.print("LOADING");
  delay(2000);
  lcd.clear();
  pinMode(LED, OUTPUT);  //LED is OUTPUT
  pinMode(SWITCH, INPUT);  //REED-SWITCH is INPUT
}
void loop() {
  BUTTON_STATE = digitalRead(SWITCH);  //reading state of REED-SWITCH whether it is ON or OFF
  if (BUTTON_STATE == HIGH) {    //  if state is ON or magnet is near the REED-SWITCH
    digitalWrite(LED, LOW);// then keep LED ON
    lcd.print("DOOR IS CLOSED");
    delay(100);
    lcd.clear();
  } else {
    digitalWrite(LED, HIGH);      //if magnet is far from the REED-SWITCH then keep LED OFF
    lcd.print("DOOR IS OPEN");
    delay(100);
    lcd.clear();
  }
}

Comments

Popular posts from this blog

MQ-6 Gas Sensor Interfacing with Arduino UNO and LCD

#How to make wireless spy earpiece for your exams

How to make USB Speaker for PC