How to use reed sensor using arduino


Materials:-
  • Arduino uno
  • Reed sensor
  • LED
Diagram:-


Connections:-

Reed sensor to arduino
  • Senor VCC = Arduino 5v
  • Sensor GND = Arduino GND
  • Sensor A0 = Arduino A5
LED to arduino

  • LED ( - )  = Arduino GND
  • LED ( + ) = Arduino digital pin13  

Code:-

int LED = 13; int reed_sw = A5; int reed_status; void setup() { pinMode(LED,OUTPUT); pinMode(reed_sw,INPUT); } void loop() { reed_status = digitalRead(reed_sw); if(reed_status ==1){ digitalWrite(LED,LOW); delay(100); }else{ digitalWrite(LED,HIGH); delay(100); } }