Dorm Door Access w/ Servo, Reed Switch, and RFID Reader

Hello all!
I’m working on an alternative way to access my dorm that doesn’t involve my physical key but my university ID card, which is also a HID Proximity (125kHz) Badge. I am using a Duemilanove (ATmega328) with my Mac and Arduino 1.0.5, along with (on the hardware side) a HID RPK40 iClass + Prox (125kHz) + Keypad reader, Hitec HS-55 servo, and a generic magnetic reed switch. My ultimate goal is to present my badge to the reader and (depending on the status of the reed switch) either unlock or lock the door through the servo connected to the deadbolt. (Deadbolt controls lock of handle outside)

I have successfully modified code that I have found online to read my badge, flash the LEDs, and trigger the beeper on the reader. What I have yet to be able to do is get the reed switch and servo to work. I have attached my current code, but will snip relevant sections in-line here.

To start off - my issues with the reed switch. The switch itself is a no-name switch intended for use with security systems. I figure it’s the same concept as one I’d buy with an exposed circuit board, so it should work. Please correct me if I am wrong here. It just has two wires coming out. One I inserted in Digital 13 and the other in the GND immediately adjoining Digital 13. I then used this snippet of code…

void checkLock() {
  int state = 0;
  state = digitalRead(13);
  if ( state == HIGH ) {
    boolean deadboltLocked={true};
    Serial.println("Magnetic Sensor States Deadbolt is Currently Locked");
  }
  else {
    boolean deadboltLocked={false};
    Serial.println("Magnetic Sensor States Deadbolt is Currently UnLocked");
  }
}

to check the lock’s state. Unfortunately, this always returns unlocked, or LOW. I have tried connecting Digital 13 and GND together with a jumper, and even that didn’t cause it to read HIGH. Again, this is just how I understand it. Please feel free to correct me. What do I need to do to detect the proper state?

As for the servo, this is the main example that I followed. http://playground.arduino.cc/Learning/SingleServoExample (and this too http://www.robotshop.com/blog/en/arduino-5-minute-tutorials-lesson-5-servo-motors-3636)
When I upload the sketch using the first example, the servo immediately turns as far as it can (180 degrees) and then until I unplug either the data wire 5V, or GND, it tries to fight to keep turning. In this case, the servo data wire goes into Analog 0.
I have tried this code from the second link with the servo in Digital 8.

#include <Servo.h>

Servo myservo;

void setup() {
  myservo.attach(8);
}

void loop() {
  myservo.write(25);
  delay(1000);
  myservo.write(100);
  delay(1000);
}

And it behaves as expected. It loops between rotating 25 degrees, then 100 degrees in opposite directions.
What I want is for it to turn the specified degrees upon a valid card presentation, and then essentially power off, and allow for manual turning without fighting the motor so that a key can still be used as a manual override.

Please let me know if I need to clarify, or if you need more details. I have commented quite a bit in the attached sketch, but again, let me know if you have questions. Thanks in advance for any help!

DormMultiProx_ino.ino (7.16 KB)

I would choose an other pin than 13 because that one has the onboard led connected.
I attach a schematic how to connect the reed switch. The resistor should be around 10K (not critical)

reed switch.JPG

Aah, so the resistor is the problem. Ok. I'll head to RadioShack to get one.
Pardon my ignorance, but why do I need to connect the reed switch to 5V?

Ok, it basically Ohms law.
An unconnected arduino pin has a very high impedance. High enough to produce a voltage drop which can be interpreted as a “1” for many unsuspected reasons like touching the pin or leakage current from the pin itself. So an unconnected pin has an undefined level and one should never assume anything else.
The resistor between the pin and GND lowers this very high impedance to the value of the resistor. Lets say 10K. In order to get a voltage drop across the resistor (at least 3,3V) there need to be a current of 0,3mA trough it. such a current cannot flow by accident so the pin will be at “0” level. Until the switch closes an connect the pin to +5V. The 5V supply has no problem att all supplying another 0.5mA so the pin will sense 5V and interpret that as a “1”

Sorry for the delay. Got a bit sidetracked. I’m working on making a mock-up of my wiring in Fritzing. Would you be so kind as to confirm my layout? (Ignore the Uno reference. That’s all Fritzing had.) Ultimately, one will be the magnetic switch for deadbolt position, one will be an unlock button to unlock the deadbolt, and the other a lock button to lock the deadbolt.

Resistors should be 10kOhm instead of 10 ohm. And fritzing has most arduino boards. They are in a separate bin though

Trying again. How’s this one?

Better. It should work