Several months ago I had been playing with a few things and ran across an old 20mm case fan on my workbench. Out of sheer boredom I plugged it into my UNO on the 5v supply and to my amazement the fan spun up. I toyed with the tach signal line but didn’t get any immediately useful information.
Now I’ve got a project in mind where I need to use a fan to keep another component cool and it’d be nice to be able to monitor the fan speed (or setup a tattletale if the fool thing slows/stops). Anyone know if its possible to measure a fan’s tach signal and use it in a sketch?
One of the tricky things about the fan’s tach output is it is usually only valid when the fan is powered on. If you hook up a multimeter the tach line and spin the fan by hand with the power off, you probably won’t see anything. If you power it on, you should see something, but your multimeter is probably too slow to register it. I think you usually see two pulses per revolution on computer fans. I suppose you could apply power to the fan but prevent it from spinning with your hand, then watch on a multimeter as you slowly turn it by hand to verify that it works.
Some fans have an open-drain tach output, so if you still don’t see anything, try with a ~10K pullup resistor. The few I’ve tried recently didn’t need one.
You should be able to connect it to a digital input pin and use the arduino to watch the pin change. I’m not very familiar with the arduino libraries, but the pulseIn() function looks like it would do the job.
If you do supply more than 5V to the fan, use a voltage divider to keep the voltage the arduino sees down to 5V.
emf:
One of the tricky things about the fan’s tach output is it is usually only valid when the fan is powered on. If you hook up a multimeter the tach line and spin the fan by hand with the power off, you probably won’t see anything. If you power it on, you should see something, but your multimeter is probably too slow to register it. I think you usually see two pulses per revolution on computer fans. I suppose you could apply power to the fan but prevent it from spinning with your hand, then watch on a multimeter as you slowly turn it by hand to verify that it works.
So if I have the fan powered by a 12v source, a common ground with the Arduino, and the tach pinned to an analog input I ought to be able to get something from it? If that fan is running around 4k RPM and it pulses twice per revolution will that stack overflow the 10bit ADC? A digital input is either LOW or HIGH state, no? If I want to measure the fan speed I’d need to use an Analog input, right?
I’ve been told that 4pin fans with a tach and a PWM input are around, but I’ve not seen them and I expect they will be pricey.
emf:
Some fans have an open-drain tach output, so if you still don’t see anything, try with a ~10K pullup resistor. The few I’ve tried recently didn’t need one.
You should be able to connect it to a digital input pin and use the arduino to watch the pin change. I’m not very familiar with the arduino libraries, but the pulseIn() function looks like it would do the job.
If you do supply more than 5V to the fan, use a voltage divider to keep the voltage the arduino sees down to 5V.
Thats good advice, no desire to fry the Arduino by feeding it an overvolt. But if I’m using an isolated powersource, I do need a common ground to read the tach pin don’t I? I know one is needed when powering servos with an external source. If I’m only pulling ground and the tach pin to the Arduino is the voltage divider still nessisary?
The tach output is a digital signal, so you’d connect it to a digital input. It’s not something that varies from 0 volts when the fan is stopped to 5V when the fan is at max speed, like you might expect. Instead, it will always read either 0V or whatever supply voltage you give it, let’s say 12V. As the fan turns, for the first 90 degrees the output is 0V. At 90 degrees, it goes high to 12V for the next 90 degrees. When it reaches the 180 degree point, it’ll go low again to 0V. At 270 degrees, it goes high again, and then when it hits 360 degrees it will go low and the cycle will repeat.
To get the fan’s speed, you can measure how long the pulses are (which is what pulseIn() should do). If the 90-degree to 180-degree high pulse lasts for 25ms, the fan is making on revolution in 100ms, so that’s 600rpm. You could also do it another way, by counting the number of pulses in a second, then multiplying by 30 (since you get two high pulses/rev) to get the rpm.
If you’re trying to PWM the fan and still measure speed, you can still measure the speed with a 3-wire fan. One rather easy way is to stop your normal PWMing whenever you want to measure speed, and just turn the fan on. Watch for and time a complete pulse to get your speed, then resume your normal PWMing. If you only need to update your fan speed reading every few seconds, these long pulses won’t make any noticeable difference.
As for the rest, you do need a common ground. You need to make sure the input pin doesn’t get more than 5V, but how depends on your fan. If you’re lucky and your tach signal already gives you 5V when you power it with 12V, you can feed it straight to the arduino. If the tach signal is open-collector, you can pull it up to 5V with 10K and feed it to the arduino. If it gives you 12V, use a voltage divider to get the voltage down to 5V.
[edit] I just tried a 80mm case fan I had lying around from last time newegg had a good sale. It was open-collector, so there was no obvious output on the tach pin until I added a 10K pullup.
emf:
The tach output is a digital signal, so you’d connect it to a digital input. It’s not something that varies from 0 volts when the fan is stopped to 5V when the fan is at max speed, like you might expect. Instead, it will always read either 0V or whatever supply voltage you give it, let’s say 12V. As the fan turns, for the first 90 degrees the output is 0V. At 90 degrees, it goes high to 12V for the next 90 degrees. When it reaches the 180 degree point, it’ll go low again to 0V. At 270 degrees, it goes high again, and then when it hits 360 degrees it will go low and the cycle will repeat.