arduino RPM meter for laser project

I am using arduino to make an RPM meter to read the pulses off an ordinary intel cpu fan with 3 leads (+,-, rpm signal)
I tried using digitalread() and pulsein() but I get fuzzy results.
anyone knows how to read those signals reliably?

code examples:

void loop()

if (scanvalue!=previous_scan) {pulsecount++; previous_scan=scanvalue;}

if (millis() - previousMillis > interval)
interval=((millis() - previousMillis)/pulsecount)*50
previousMillis = millis();

//code blinking code here

Hello Tomas,

You have to use an external interruption. Look at, link is in french but you can understand code. In summary, the SIGNAL(SIG_INTERRUPT0) function is called each time the state of the digital digital change.

Hello Tomas,

I’ve made a reply with code here :

thanks very much!