Control the Speed of a PC Fan Using Arduino

by VirtualBlack in Circuits > Arduino

558 Views, 0 Favorites, 0 Comments

Control the Speed of a PC Fan Using Arduino

20231119_001750.jpg

Control the speed of a 12 volt computer fan using a PWM signal with an Arduino, simple and effective.

Supplies

Supplies nedeed:

  • A 12 volt DC power supply
  • An Arduino Mega 2560
  • A mini size breadboard
  • Male to Male Jumper wires
  • A computer fan

Download and Install the Arduino IDE

Step 1.jpg

In case you haven't already done this, you have to download and install the Arduino IDE on your computer in order to load the code into the arduino, you can download it on the Arduino official website https://www.arduino.cc/en/software

I used Arduino IDE version 2.2.1 but any version should work.

Connect the Components According to the Diagram

Connections_diagram.jpg

Follow the diagram to connect the components, Pin 1 of the fan should be connected to ground, Pin 2 should be connected to the positive terminal of the 12 volt power supply and Pin 4 should be connected to digital Pin 11 of the Arduino.

Pin 1 of the fan is usually marked with a big number "1" on the connector, so you can identify it that way.

Pin 3 of the fan is not used since this project's objective is to simply control the speed of the fan, and this pin is to read the RPMs of the fan.

Upload the Code Into the Arduino

code screenshot.jpg

Open the attached file with the arduino IDE, connect the arduino to any USB port of your computer and upload the code.

The way the code works is that it makes the Arduino generate a PWM signal on Pin 11 with a 25 KHz frecuency and a certain duty cycle, the reason for a 25 KHz signal is because it reduces the PWM noise since this frecuecny is outside of the human hearing range (20 Hz - 20 kHz).

I have tested the signal with an oscilloscope and it's indeed 25 KHz.

Set the Desired Speed

Line 12.jpg

You can change the speed of the fan by changing the duty cycle percentage in line 12, where 0% means minimum speed and 100% means full speed. By default is at 20%

I have also added code in void loop () function that prints the current duty cycle on the serial monitor every second, I think it makes easier to keep track of the speed you set.

I hope you find this useful.