I have just got a magnetic reed switch and want to connect it to my arduino but don't know where to start?Cant find much on the web regarding connecting this up. I've read I need to include a pull down/up resistorand believe the arduino has some built in accessed via the software. The switch has two wires brown & blue.

Thanks for your help, I used the "debounce" code as a start and have managed to connect the reed , I used the serial monitor to display when the pin goes from 1 to 0 with the magnet attached and it works fine. I have a question about the Reed, when I connect it directly through the 5V and Ground on the Arduino and close the switch with a magnet I get a LED light in the switch. However when I hook the 5V to Pin 7 and ground to Arduino I can read the change but the LED doesn't light? Any Ideas?

// constants won't change. They're used here to // set pin numbers:const int ReedPin = 7; // the number of the Reed Switch pinconst int ledPin = 13; // the number of the LED pin

// Variables will change:int ledState = HIGH; // the current state of the output pinint ReedState; // the current reading from the input pinint lastReedState = LOW; // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long lastDebounceTime = 0; // the last time the output pin was toggledlong debounceDelay = 50; // the debounce time; increase if the output flickers

if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: ReedState = Reed_Val; }

digitalWrite(ReedPin, HIGH);

Serial.println(Reed_Val);

// save the reading. Next time through the loop, // it'll be the lastButtonState: lastReedState = Reed_Val;}

I have a question about the Reed, when I connect it directly through the 5V and Ground on the Arduino and close the switch with a magnet I get a LED light in the switch. However when I hook the 5V to Pin 7 and ground to Arduino I can read the change but the LED doesn't light? Any Ideas?

Simple reed switches do not have internal LEDs in them. How it should be wired depends on the specifics of your 'not simple' reed switch. If it has an internal led, does it also have a current limiting resistor to prevent damage to the led? Is the led in series with the contacts or parallel? Wiring straight across +5vdc and ground may not be safe for the switch or what you are powering it with.

Only a link to a datasheet for your specific 'not simple' reed switch can tell us how it should be operated and wired up.

Thanks for the link. however that is a pretty poor datasheet. It doesn't explain electrically how the led is wired in relationship with the contacts at all. I can offer no advice based on that information. Not your fault, just a poor datasheet.

I do a lot of projects and contact bounce is a problem I rarely encounter if you write the code correctly. My advice would be to never use the library.

It looks like that data sheet is designed for someone replacing the reed switch in a specific piece of equipment.However as you have the switch you can test with a meter which connectors short in the presence of a magnetic field.

I will order some basic reed switches but for testing this will do I think, haven't blown anything yet :~. I have it now so when I remove the reed switch from the magnet a buzzer sounds two pitches and a LED flashes. The obvious flaw now in the program is when I put the magnet back the alarm stops. I want it to continue until I press a reset button. I figure that when the alarm sounds I read the input from the button and continue sounding the alarm until the button is pressed and the switch is closed. How would I incorporate that into the code?

const int ReedPin = 7; // the number of the Reed Switch pinconst int ledPin = 13; // the number of the LED pinconst int buzzPin = 11; // the number of the buzzer pin

// Variables will change:int ledState = HIGH; // the current state of the output pinint ReedState; // the current reading from the input pinint lastReedState = LOW; // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long lastDebounceTime = 0; // the last time the output pin was toggledlong debounceDelay = 50; // the debounce time; increase if the output flickers

if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: ReedState = Reed_Val; } digitalWrite(ReedPin, HIGH);

// Serial.println(Reed_Val); //uncomment this to check monitor to see if we are getting 0 or 1's // save the reading. Next time through the loop, // it'll be the lastButtonState: lastReedState = Reed_Val;

if (Reed_Val ==LOW) { //If we get 1's switch is closed Serial.print("Everything is fine"); digitalWrite(ledPin, LOW); delay(1000); //monitor every second }

if (Reed_Val ==HIGH) { //If we get 0's switch is open so sound the buzzer