Note: I forgot to post my pics for this tutorial because I just moved into college at the time, and forogt to pack my USB cable for the camera.Anyway, on Monday, I promised you guys that I'll post a tutorial on how to connect a reed switch to Arduino. Well today, I'm here to keep my promise. Also, for the second time in this blog's history, this tutorial will be presented in Fritzing. So, what parts do you need for this tutorial?

- Arduino (1x)
- Reed Switch (1x)
- 10K Resistor (1x)
- Breadboard (1x)
- LED (1x)
- Magnet(1x)
- Wires(MISC.)
Okay, first connect a LED to pin 13 and Ground on the breadboard. We'll be using this to determine if Arduino detects the reed switch.

Now connect Arduino 5 volt and ground to its own buses. Then insert your reed switch onto your bread. Be care inserting this! When I finished this tutorial a couple days ago, I accidentally broke my reed switch by roughly inserting it onto my breadboard.

Now connect a 10K resistor from 5 volts to the reed switch.

Afterwards, connect Digital Pin 2 of the Arduino board where you connected your 10K resistor to the reed switch. Finally, connect the other pin of the reed switch to ground.

All done! Now open up Arduino's IDE and copy and paste this code onto a blank sketch book.
int ledPin = 13;
int inputPin = 2;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}
void loop(){
val = digitalRead(inputPin);
if (val == LOW) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
}
}
Upload the code! You should notice that the LED lights up automatically. Now grab a magnet and place it close to the reed switch. The LED should automatically turn off.
Well, that's it for me today. See you guys later!