Attachinterrupt not working properly

I am trying to make a bike speedometer with an Arduino Nano and an LCD display and I recently figured out that the attachinterrupt function only worked on certain pin. I had it on pin 10 before but changed it to pin 2 as it was not working. Once I changed it to pin 2 the speed kept going up without the reed being connected or when it was connected it still kept going up. Does anyone know why it would be doing this?


#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

float start, finished;
float elapsed, time;
float circMetric = 2.314194; // wheel circumference (in meters)
float circImperial;
float speedm;

void setup()
circImperial = circMetric * .62137;

attachInterrupt(digitalPinToInterrupt(2), speedCalc, RISING);

start = millis();

analogWrite(7, 20);

lcd.begin(16, 2);



void speedCalc()
if ((millis() - start) > 100)
elapsed = millis() - start;

start = millis();

speedm = (3600 * circImperial) / elapsed;

void loop()
lcd.setCursor(0, 0);
lcd.print(" “);
lcd.setCursor(0, 0);
lcd.print(” MPH ");

source_code.ino (838 Bytes)

How is the reed switch connected to pin 2? Do you have pullup or pulldown resistors on input pins to keep the pins from "floating" and causing false HIGHs or LOWs when the switch is not activated? Best way is like S3 in the diagram, no external resistor needed, logic is reversed though (pin is LOW when switch is closed).

The only place I have a resistor is on the wire that goes to ground.