hall effect sensor to measure speed reading in KPH or in RPM

hi! im new to this kind of sensor, can somebody help me how to use this sensor to measure speed, btw this is the code i saw from the internet, but my problem is why is this code has no input from the sensor? like the analogRead syntax? can somebody change this code to a code that can measure a speed. and what is the meaning of the attachIntterupt? what is the 0 pin use for? thanks for the help! :smiley:

volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(115200);
attachInterrupt(0, magnet_detect, RISING);//Initialize the intterrupt pin (Arduino digital pin 2)
half_revolutions = 0;
rpm = 0;
timeold = 0;
}
void loop()//Measure RPM
{
if (half_revolutions >= 20) {
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
//Serial.println(rpm,DEC);
}
}
void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
{
half_revolutions++;
Serial.println("detect");
}

Please post a wiring diagram for the sensor and explain the physical situation.

Have you attached a magnet to a wheel?

why is this code has no input from the sensor?

The posted code takes input from the sensor on Digital pin 2 and reads it with an interrupt.

what is the meaning of the attachIntterupt?

At the top of the web page where the forum appears, there is a tab "Learning". Undee it you will find "Reference" where answers to basic syntax questions can be found.

Bad code. You should never, ever print within an interrupt.

void magnet_detect()//This function is called whenever a magnet/interrupt is detected by the arduino
 {
   half_revolutions++;
   Serial.println("detect");
 }