Bicycle speedometer

I would suggest two things.

  1. Switch the magnet polarity, and see if the sensor responds better.
  2. Use a stronger external pull up (4.7K) instead of the internal pullup you enabled with
pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);
//equivalent to pinMode(switchPin, INPUT_PULLUP);