Problem while reading the hall effect sensor of a computer fan

Hi everyone,

I made a small project for me for the first time on an Arduino Nano board.
I want to know the speed of à computer fan, to create an flowmeter.

I already had a "clean" signal by using a 4 pins fan (808020 computer fan).
But as I don't need the PWM pins, and i wanted to downscale my flowmeter, I tried using a 3 pins fan (606015). And when I plug th enew fan on my Nano, the signal shown by the monitor is this :

Do you know if there can be an issue with the way I read my signal ?

Here is my prog:

/*-----------------------------------------------------------VARIABLES-------------------------------------------------------------*/

const int analogInPin = A2;                           /* Entrée analogique raccordée au ventilateur */
const byte PIN_SIGNAL = 2;                            /* Constantes pour la broche de mesure */

int sensorValue = 0;                                  /* Valeur lue sur le ventilateur */ 
int outputValue = 0;                                  /* Valeur de sortie vers le PWM (analog out) */

/*-------------------------------------------------------------TICK----------------------------------------------------------------*/

void tick() {                                         /* Fonction d'interruption pour la mesure entre deux fronts */

  static unsigned long previousMicros = 0;
  unsigned long currentMicros = micros();
  
  periode = currentMicros - previousMicros;           /* Calcul le temps écoulé depuis le précédent front */
  
  previousMicros = currentMicros;                     /* Met à jour la variable pour la prochaine interruption */
}

/*-------------------------------------------------------------SETUP----------------------------------------------------------------*/

void setup() {
  
  delay(500);
  Serial.begin(115200);                               /* Initialise le port série 19200 115200 921600 9600*/
  
  //pinMode(PIN_SIGNAL, INPUT_PULLUP);                /* Met la broche en entrée */
  attachInterrupt(digitalPinToInterrupt(PIN_SIGNAL), tick, RISING);
  
  delay(200);                                         /* Permet une première mise à jour de "periode" */

}

/*--------------------------------------------------------------LOOP----------------------------------------------------------------*/

void loop() {

  sensorValue = analogRead(analogInPin);              /* Lecture de la valeur analogique */
      
  //if (sensorValue != 0)                             /* Traitement du signal en échelons reguliers */
  //  sensorValue = 5;

  outputValue = map(sensorValue, 0, 1023, 0, 5);      /* Mapping à la plage de la sortie analogique */

  Serial.print("sensor = ");                          /* Affichage du résultat sur le moniteur */
  Serial.print(sensorValue);

  Serial.print("\t output = ");
  Serial.println(outputValue);

}

Nice picture but not sure what axis is what. Labeling that would help. Also try adding a pull up or pull down resistor and see what the signal looks like. It looks like noise to me. An schematic would help as well as links to the hardware items technical information.

I would start with that. While I can't speak for your specific fans all common computer fans I have worked with required an external pullup resistor. I generally used 10K for resistance. Also it's common for the pulse out to be two pulses per revolution.

Ron

1 Like

I tried the resistor trick, with several ones, but it don't seems to work.
The axis are (I think) time on x-axis and a logical 0-to-1023 signal on y-axis.
I think the probleme might come from the fan, because the hall effect sensor doesn't seems to do anything.

Not a trick, but a requirement.

Fan ground to Arduino ground, tach output to a digital pin,
external 10k resistor between tach pin and Nano 5volt pin (or internal pull up with pinMode).

Not sure what you mean with that.
The tach pin of a computer fan does not provide a voltage that you can measure with an analogue pin.

To know the speed of the fan you have to measure the time between pulses.
Leo..

Thanks Wawa for the help.

Is it possible to do it on a analog pin of the arduino ? My previous fan worked on A2.

Ok, so I plugged my fan like Wawa said.

The Red wire on the Arduino 5V pin
The Black wire on the Arduino GND pin
The Yellow wire on the D2 pin

I then openned the exemple "DigitalInputPullup", to test the respond of the system, it has the pullup function so I think I don't need an external pullup. And it's working !
The signal is a clear step.

But one problem remains : when I lauch the Serial Monitor, the simulation stops automatically after 4-5 seconds. Any idea why ?

static unsigned long previousMicros = 0;

Does this not mean previousMicros() is not to be changed?

Honestly I found that part of the program online, and I don't fully undestand what is it for

... the function returns nothing (void()), so the math in that ISR goes nowhere. Maybe there is a library file involved?

What happens when you comment-out the ISR?

Ok, I get what you want to do. You want to measure fan speed and my guess is eventually use a fan tachometer output to measure air flow? Maybe air velocity?

I looked at your code and it makes no sense. Assuming using the tachometer output of a fan you have the pulses going into A2 (Analog Input 2). Why do you have a pulse train going to an analog input?

Then something strange happens. You take an analog input and do this:

outputValue = map(sensorValue, 0, 1023, 0, 5);

A typical computer fan measuring 80mm X 80mm X20mm will run on 12 VDC. The average current draw will be about 150 to 160 mA. The tach out signal using a 10 K pullup will be 12 volt pulses. Not good for a 3.3 volt micro or even a 5.0 volt micro.

That explains a lot. You can't just cobble pieces and parts of code together. I can't get your posted code to even compile let alone load on an Arduino Uno.

So what exactly in detail is your project? The final project? You want to measure exactly what?

Ron

If you use A2 as a digital pin (digitalRead), then yes.

I didn't say that.

The red (+) wire is to power (spin) the fan.
I thought you wanted to use the fan as a flow meter, so don't connect the red wire.
Leo..

I doubt using a PC type cooling will work to measure air flow. My thinking here is the tachometer out from one of these fans is normally an open collector output. The actual hall effect sensor is powered by the fan power which is the 12 volt fan power. The hall effect sensor in turn drives the tach out transistor. So even if we put a pullup on the tach out there is nothing powering the hall effect sensor. Please correct me if I am wrong on this Leo. I just don't see this working. Not using a common PC fan.

Ron

You might be right. Never thought about it that way.
That means OP can't use a PC fan to measure air flow.
Leo..

Just my best guess. There are sensors out there to measure air flow using an Arduino I just don't see using a PC fan as working and I could be wrong.

Ron

I’d be busy taking the fan apart to see if I could disable the fan motor but continue powering the Hall effect.

It is not clear from the post how the OP wants to measure air flow. All we have is this:

I want to know the speed of à computer fan, to create an flowmeter.

There are plenty of cheap Chinese air flow meters on line, usually advertised as wind speed gauges. Hold them in an opening of known size, and it is trivial to calculate the volume flow.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.