magnetic reed switch

Hi

I'm trying to wire a reed switch so that it's pulled low and I can monitor its state with digital pin 5.

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 5;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

I have it wired so that 5v is supplied to the red wire and the black wire is connected to ground but with a 10k pull down resistor in between. The black wire is also connected to digital input five.

When I run the code and bring the two magnets together, I can hear the reed clicking, but the LED doesn't illuminate.

I suspect it's my wiring that's at fault.

Yes, but until you learn how to draw out your circuit and post it's hard to help, red and black wire means little to us without context. The easiest way to interface to a reed switch is to wire one end of the switch to ground and the other end to the arduino input pin. Then enable the input pin's internal pull-up resistor in your setup function:

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH); // turn on input pin's pull-up resistor 

}

Lefty

retrolefty: Yes, but until you learn how to draw out your circuit and post it's hard to help, red and black wire means little to us without context. The easiest way to interface to a reed switch is to wire one end of the switch to ground and the other end to the arduino input pin. Then enable the input pin's internal pull-up resistor in your setup function:

Hi Lefty, I hope I've learnt now?

Code

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 5;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH); // turn on input pin's pull-up resistor 
  Serial.begin(57600);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Just prints '1' to serial the whole time! :S

Thanks for your help.

Sorted it! As you so astutely pointed out earlier in thread, red and black are NOT the right connections to be monitoring.

Bizarrely, it's red and yellow, for anyone else with a Maplin MM11M.

I was told black and red were the signal pins and blue and yellow to be tamper. Not so.

Thanks to the staff at Maplin (who for the most part are just till operators) for that misinformation! ]:) :D