Current monitor for fan running with PWM through FET

I am running 12V fan with FET transistor through digital pin with PWM (analogWrite). I wanna be able to know, when the fan stops because of failure (for example, if i would hold the fan with my arm the system must notice that).

I tried with LM324 current monitor through analog port but without luck. http://weber.fi.eu.org/blog/images/current_monitor.png

Have got any idea, how to do that?

Either high side current measurement or use a small resistor on the source of the mosfet and measure the voltage over it - a little simpler.

I tried this with 0,1 and 0,22 ohm resistor but difference in voltage when fan was running normal and when i hold them with hand was almost negligible. I am running fan with three PWM states: 50%, 75% and 100%. Can you be more specific, where to measure and how to se the difference?

How much current does the fan take? The ADC has a resolution of just under 5mV using the default analog reference; so if you choose the value of resistor in series with the mosfet source so that it drops 50mV or 100mV when the fan is operating normally, you will easily be able to detect it - but only if you read it while the mosfet is turned on.

The resistor value is a function of the current and the capabilities of your measurement instruments.

If you were to use low-side measurements, put your current sensing resistor on the source. Also put a low-pass filter on it, like 10k / 0.1uf capacitor and measure the voltage over the capacitor - the values of the resistor / capacitor depends on your pwm frequencies.

That approach assumes that you cannot synchronize the current sensing with pwm output. If you can, you don't need the low-pass filter - you then have cycle-by-cycle current control of the pwm.

If it's real important to know if the fan is running or not I would not rely on the current flow amount, I would want to know if there was actual air flow being generated or not. Possible detection methods? Perhaps some kind of sensitive air flow switch. Perhaps two thermistors one placed in the air flow path and one not in the air flow path and if the temperature delta between the two was not above some minimum value then there is a air flow problem, regardless of the current the motor is drawing. Again measure or detect directly what is the most important process variable, not some indirect derived signal.

Lefty

dc42:
How much current does the fan take? The ADC has a resolution of just under 5mV using the default analog reference; so if you choose the value of resistor in series with the mosfet source so that it drops 50mV or 100mV when the fan is operating normally, you will easily be able to detect it - but only if you read it while the mosfet is turned on.

Fan needs 630 mA (12V).. I connected fan to FET like this:

DRAIN - Fan GND (12V is connected directly to fan+)
GATE - To Arduino
SOURCE - GND

So, if i am using connection of FET and fan like this.. Where should i put resistor and where should i measure (analog input of arduino)?

I would put a small resistor (ideally 10mohm but higher is ok given that the current isn't too big) from the source to ground.

You should see voltage pulses on this resistor (6mv or so) when the motor is running, and nothing when the motor is disconnected.

Whether you use a low-pass filter after that will depend on your particular solution.

You can also detect a stuck motor (connected but not running): you will see higher magnitude of the pulses.

luxy:
Fan needs 630 mA (12V).. I connected fan to FET like this:

DRAIN - Fan GND (12V is connected directly to fan+)
GATE - To Arduino
SOURCE - GND

So, if i am using connection of FET and fan like this.. Where should i put resistor and where should i measure (analog input of arduino)?

Connect the 0.22 ohm resistor between the mosfet source and ground. Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead. Or, use the 0.1 ohm resistor, you will get 63mV across it at full speed.

You should also connect a small resistor (100 to 220 ohms) between the Arduino output pin and the gate of the mosfet, to reduce the peak current to within the Arduino's rating when the pin changes state and the mosfet's input capacitance charges/discharges. An additional resistor (say 100K) between the output pin and ground is recommended, to ensure that the mosfet remains off while the Arduino is powering up and has not yet set the pin to be an output.

dhenry:
I would put a small resistor (ideally 10mohm but higher is ok given that the current isn't too big) from the source to ground.

You should see voltage pulses on this resistor (6mv or so) when the motor is running, and nothing when the motor is disconnected.

As the count resolution for a arduino analog input pin is 5 millivolts or so and who knows what the noise floor will be, this seems like a most undesirable unreliable measurement to use to determine if the motor is operating at normal current draw or not.
Lefty

Whether you use a low-pass filter after that will depend on your particular solution.

You can also detect a stuck motor (connected but not running): you will see higher magnitude of the pulses.

dc42:
Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead.

You mean that i connect one wire after resistor to analog input, right (what did you mean with junction of two)?

[FET SOURCE]-----[RESISTOR]-----(to analogInput)-----[FET GND] <-- like this, right?

which you can easily detect via analogRead

How to do that? I tried with this but if i am correct it can be used only if power supply is 5V?

  1. SensorValue * 12/1023 to get voltage value
  2. Than use I=U/R with values of 12V and 0,22 ohm to get current
  3. If i hold the fan current should increase

Is that right?

either directly (if you synchronize the analogRead with the PWM)

And how to do that?

luxy:

dc42:
Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead.

You mean that i connect one wire after resistor to analog input, right (what did you mean with junction of two)?

[FET SOURCE]-----[RESISTOR]-----(to analogInput)-----[FET GND] <-- like this, right?

No, like this:

[FET SOURCE]-----(to analogInput)-----[RESISTOR]-----[GND]

luxy:

which you can easily detect via analogRead

How to do that? I tried with this but if i am correct it can be used only if power supply is 5V?

  1. SensorValue * 12/1023 to get voltage value

No, sense_voltage = analog_reading * 5.0 / 1024.

luxy:
2. Than use I=U/R with values of 12V and 0,22 ohm to get current

No, use I = V/R with V = sense_voltage as calculated above.

luxy:
3. If i hold the fan current should increase

Is that right?

Yes, most fans will draw more current if you hold them stalled.

luxy:

either directly (if you synchronize the analogRead with the PWM)

And how to do that?

Simplest way is to do a digitalRead from the PWM pin and wait for it to be HIGH before you call analogRead. After the analogRead call, do another digitalRead and check the pin is still HIGH, discarding the analog reading if it is not.

dc42:

No, sense_voltage = analog_reading * 5.0 / 1024.

Ok,

it is intresting to me that i should use 5V although i am powering my fan with 5V.. I will try and report.. Thank you for now!

The 5V in that calculation is the voltage on the Aref pin of the microcontroller. You can use a different voltage reference, see analogReference() - Arduino Reference.

dc42:
The 5V in that calculation is the voltage on the Aref pin of the microcontroller. You can use a different voltage reference, see analogReference() - Arduino Reference.

Today i tried all you sad and i think it works.. I used 10k and 10uF electrolytic capacitor for low pass filter (is 10uF too much?)

I measure this values:

Power of fan: 12V stable over LM7812

rpm = 127 (50%)
fan run normal: 180 mA
hand on fan: 240 mA

rpm = 191 (75%)
fan run normal: 290 mA
hand on fan: 420 mA

rpm = 255 (100%)
fan run normal: 420 mA
hand on fan: 620 mA

Of course this values are changing a little but i think i will be able to include them into my "warning alarm".

Btw, i still don't really understand, how to synchronize the analogRead with the PWM (to measure without low pass filter). Can you give me a code example? This is my part for measuring current:

  analogWrite(fan, 255);
  int sensorValue = analogRead(A0);
 
  float voltage = sensorValue * 5.0 / 1023.0;
  
  float current = voltage / 0.22;
 
  Serial.println(current);

Btw, i still don't really understand, how to synchronize the analogRead with the PWM (to measure without low pass filter). Can you give me a code example? This is my part for measuring current:

I don't think such a method exists, In the external (to the AVR chip) electronics world the PWM lives in the digital domain and the analogReads lives in the pure analog world, they are only equally digital inside the code, So external low pass filtering to eliminate the PWM switching frequency will always be required, unless someone can prove differently?

On second thought, I guess it would be possible to implement a low pass filtering function in code to take many analogRead samples and effectively filter out the PWM switching frequency, might be an interesting project for someone better at software then me. :wink:

Lefty

luxy:
Btw, i still don't really understand, how to synchronize the analogRead with the PWM (to measure without low pass filter). Can you give me a code example?

Something like: (warning - untested code!)

  int sensorValue;
  do
  {
     while (digitalRead(fan) == LOW) { }    // wait for PWM pin to go high
     sensorValue = analogRead(A0);
  }
  while (digitalRead(fan) == LOW);   // repeat if PWM pin has gone low already
 
  float voltage = sensorValue * 5.0 / 1024.0;  
  float current = voltage / 0.22; 
  Serial.println(current);

The simplest method is to buy a fan with a speed feedback output, most computers use one... on the Processor and there are Many different types available. Go For Google...

Bob

I bought TC670 predictive fan failure detector.. If i power my fan directly with 12V it works great with any kind of fan (because of this i am using this IC).

Now i've got a problem because i want to run my fan through FET with PWM. If i use 100% pwm (255 in arduino) this detector works but not if i use any other PWM value. I tried to add low pass filter between source of FET and SENSE of IC but without luck.

Does anyone have any idea how to fix this? This are pictures of TC670 scheme and FET with fan. I connected fet above the sense input, so the SOURCE of the FET and sense resistor and capacitor are connected.

I think I found a solution.. I didn't try yet but it seems like that's it.