This is a pretty simple process if you have mess with them before, do beware that some have sealed hole.
Just connect the 2nd or the 3th pin to the your MCU digital pin, and make sure to use high value resistor like 1M ohm or somthing, my arduino crash if i connect it raw, and your may too, even death is possible.
I wasnt able to find that fan hall effect latch data sheat, but i figure they are the same anyway.
My fan hall effect latch, output high at 180 and 360, so the my code divide it by 2.
Doing some coding and thats it.
I did check it accuratecy using slowmo, they spit out the same number so that good enough.
Mine is in RPS but converting it to RPM is easy.
Serial.println(((fan1_rotation_accumulate / 2.0) / measure_time), 1); //rps
Serial.println(((fan1_rotation_accumulate / 2.0) / measure_time) * 60.0, 1);//rpm
//THIS ONE IS THE LATER CODE SNIPPET
//THE WHOLE CODE IS BELOW
static uint16_t fan1_rotation_accumulate = 0;
static unsigned long start;
static unsigned long end;
static float measure_time = 5; // rps every second
static bool fan1_high_flag = false;
static bool start_high_flag = false;
//fixed time acumulation
// edit: i made i small improvement to this code after posting, by adding an extras if statement,
// this make the ouputed data very consistant, but it resolution is tide to how long the time window you're measuring
if (digitalRead(2) == LOW || start_high_flag == true) { //start as soon as it pass the hall effect and turning low. Not sure why it only output rounded number
start_high_flag = true;
if (digitalRead(2) == HIGH) {
start_high_flag = false;
start = micros();
while (1) {
if (digitalRead(2) == HIGH) {
if (fan1_high_flag == false) {
fan1_high_flag = true;
fan1_rotation_accumulate++;
}
} else {
fan1_high_flag = false;
}
end = micros();
if ((end - start) / 1000000.0 >= measure_time) {
Serial.print("fan_1:");
Serial.println((fan1_rotation_accumulate / 2.0) / measure_time, 2); //rps
fan1_rotation_accumulate = 0;
break;
}
}
}
}
//THE WHOLE CODE
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
}
void loop() {
static uint16_t fan1_rotation_accumulate = 0;
static uint16_t fan2_rotation_accumulate = 0;
static unsigned long start;
static unsigned long end;
static float measure_time = 1; // rps every second
static bool fan1_high_flag = false;
static bool fan2_high_flag = false;
/*
//fixed time acumulation
start = micros();
while (1) {
//fan 1
if (digitalRead(2) == HIGH) {
if (fan1_high_flag == false) {
fan1_high_flag = true;
fan1_rotation_accumulate++;
}
} else {
fan1_high_flag = false;
}
//fan 2
if (digitalRead(3) == HIGH) {
if (fan2_high_flag == false) {
fan2_high_flag = true;
fan2_rotation_accumulate++;
}
} else {
fan2_high_flag = false;
}
end = micros();
if ((end - start) / 1000000.0 >= measure_time) {
Serial.print("fan_1:");
Serial.println(((fan1_rotation_accumulate / 2.0) / measure_time), 1); //rps
// Serial.println(((fan1_rotation_accumulate / 2.0) / measure_time) * 60.0, 1);//rpm
fan1_rotation_accumulate = 0;
Serial.print("fan_2:");
Serial.println(((fan2_rotation_accumulate / 2.0) / measure_time), 1);
fan2_rotation_accumulate = 0;
break;
}
}
*/
//avg by time
// fit for stable ouput
// instead of waiting 60s to see result, you can see the result get more narrowed down with time
// run longer time frame by changing the time_frame measuring window
// it wont be good for fast changing rpm
static uint8_t acum_time = 1;
static uint8_t time_frame = 60; //in second
start = micros();
while (1) {
//fan 1
if (digitalRead(2) == HIGH) {
if (fan1_high_flag == false) {
fan1_high_flag = true;
fan1_rotation_accumulate++;
}
} else {
fan1_high_flag = false;
}
//fan 2
if (digitalRead(3) == HIGH) {
if (fan2_high_flag == false) {
fan2_high_flag = true;
fan2_rotation_accumulate++;
}
} else {
fan2_high_flag = false;
}
end = micros();
if ((end - start) / 1000000.0 >= measure_time) {
//Serial.println(acum_time);
Serial.print("fan_1:");
Serial.println(((fan1_rotation_accumulate / 2.0) / (measure_time * acum_time)), 2);
Serial.print("fan_2:");
Serial.println(((fan2_rotation_accumulate / 2.0) / (measure_time * acum_time)), 2);
acum_time++;
if (acum_time >= time_frame) {
fan1_rotation_accumulate = 0;
fan2_rotation_accumulate = 0;
acum_time = 1;
}
break;
}
}
}