Magnets around us! arent they? Here is a small post about the reed switch which senses these magnets around us! Rather than letting you read, I am going to show it as a video! watch it ! have fun!
Well, the procedure is very simple, all we have to do is get the sensor and connect it with the Arduino!. The connections are
VCC - 5V
GND - GND (of course)
Data - 2
Connect and run the setup using the code below!
int led = 13; // LED pin
int reed = 2; // The sensor data pin is connected to the digital pin no.2 of arduino
int state; // A variable to store the state of the switch
pinMode (led, OUTPUT);
pinMode (reed, INPUT);
state = digitalRead(reed); // read the value and assign it to state
if (state == HIGH) //LED glows when magnetic field is detected