Sensor from engine spark plug: only collecting data for a few seconds.

You will need extremely robust spike suppression circuitry to protect the Arduino input.

Seems like an awful lot of code to read RPM.