Temperature controlled fan-speed

Hello,

I want to use a PC fan into my project together with a temperature sensor (when temperature increses the fan speed should also increase).

The fan comes with 4 pins cable:
1 - 12v
2 - GND
2 - Signal
4 - PWM

How can I use the fan into my project in order to controll the speed of the fan?
Can I use that PWM pin of the fan somehow?

Thank you!

007|600x494

Hello
Post the datasheet of the device used.

Which Arduino?
At what temperature will the fan run full speed?
At what temperature will the fan run minimum speed?
How will you determine temperature?

What is the temperature sensor that you will use? Post a data sheet.

To get you started.

Connect the fan as follows. Board is Uno.
1 - 12v >> 12V
2 - GND >> 12V supply ground and Arduino ground
2 - Signal >> Arduino pin 3 to measure revolutions per second
4 - PWM >> Arduino pin 5 to control speed
I don't know what temperature sensor that you have so will simulate a sensor with a potentiometer. Connect a 1K to 100K pot wiper to pin A0 (and to Arduino 5V and ground). See here.

Adjust the speed with the pot. View the speed (revs/second) in serial monitor.

const byte pwmPin = 5;
const byte pulsePin = 3;
const byte potPin = A0;

volatile unsigned long pulseCount = 0;

void setup()
{
   Serial.begin(115200);
   pinMode(pulsePin, INPUT_PULLUP);
   attachInterrupt(digitalPinToInterrupt(pulsePin), counter, FALLING);
}

void loop()
{
   analogWrite(pwmPin, analogRead(potPin) / 4);
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      noInterrupts();
      unsigned long thisCount = pulseCount;
      interrupts();
      pulseCount = 0;
      Serial.print("counts per second  ");
      Serial.println(thisCount);
   }
}

void counter()
{
   pulseCount++;
}

1 Like

I use DS18B20 temperature sensor (the long metal version which is waterproof).

Temperature Sensor

Then you need to answer the questions asked by @ JCA34F.
The answers will tell you how you have to scale the PWM numbers (0 to 255) to get the fan speed that you want versus temperature.

Use the pot to see how speed relates to PWM. Like PWM = 0 means x revs/second and PWM = 255 means y revs/second.

I use ESP32
Full speed would be at 27 degrees
Minimum speed would be at 22 degrees
(ideal temperature to keep is 22 degrees)
And I will determine temperature with the temperature sensor (DS18B20).

You haven't told us what you are wanting to cool.

Is it the room temperature?
If the ambient temperature is 27degrees, a fan will not bring the temperature down to 22 degrees - it just blows 27 degrees air around.

or is it a semiconductor on a heatsink, with the ambient temperature at 22 degrees or less?

Yes, the ambient temperature is 22 degrees. So it should work in this regard, but I just don’t know how to write the code.

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