Water Meter - Pulsing Reed Switch


I’m having trouble reading a pulse from a water meter. Nothing is printed to the serial monitor when it should, but messing with the wire causes an output of “1” to be displayed. The reed switch closes every 1 gallon. Meter specs:

Maximum Switched Current: 500 mA;
Maximum Recommended Switching: 32
Volts (AC or DC);
Contact REsistance: 70 mOhms

My code is this:

int inputPin = 2; // choose the input pin
int val = 0; // variable for reading the pin status
int prevState = 0;

void setup() {
pinMode(inputPin, INPUT); 

void loop(){
prevState = val;
val = digitalRead(inputPin); // read input value
if (val != prevState) {
  if (val == HIGH) { // check if the input is HIGH
  } else {

It looks like you need a pullup resistor on the reed switch else the value will always read 0 on the input:

digitalWrite(inputPin, HIGH);

Put the above in setup().

Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Eureka! Thanks.