Project tutorial
Make a Fan Controller with Arduino

Make a Fan Controller with Arduino © CC BY-NC-SA

You have a fan, but you don't know how to control it? Then you're right here.

  • 10,390 views
  • 1 comment
  • 7 respects

Components and supplies

Kce8bkptj7srmwx6wcxu
Arduino Mini 05
You can also use any other Arduino
×1
11026 02
Jumper wires (generic)
×1
Fan (with PWM pin)
×1

Apps and online services

About this project

I have a server of two Raspberry Pis and they needed to be cooled. I grabbed a fan. But it was way to loud! So I got an Arduino, wrote some Code and now I can control my fan.

Step 1: Figure out the pins of the fan connector

You need a fan with a Plus (red) pin, a Minus (black) pin and a Speed pin. Some fans with three pins have plus, minus but then a Speedometer pin. The Speedometer pin is an output of the fan saying how fast the fan is rotating. Fans with four pins have a Speedometer pin and a Speed pin.

Step 2: Connect the Arduino to the fan

Connect 12V to the Plus pin of the fan, GND to the Minus pin of the fan and a PWM pin, for example pin 3 of the Arduino to the Speed pin of the fan.

Step 3: Code

#include <EEPROM.h>
#define FAN_PIN 3;
#define FS_ADDR 0x01
int fanSpeed;
void setup() {
 // put your setup code here, to run once:
 pinMode(3, OUTPUT);
 EEPROM.get(FS_ADDR, fanSpeed);
 if(fanSpeed < 1) fanSpeed = 255;
 analogWrite(FAN_PIN, fanSpeed);
 Serial.begin(9600);
}
char rx_byte = 0;
String input = "";
void loop() {
 if (Serial.available() > 0) {    // is a character available?
   rx_byte = Serial.read();       // get the character
   // check if a number was received
   if ((rx_byte >= '0') && (rx_byte <= '9')) {
     input.concat(rx_byte);
   }
   else if (rx_byte == '\n') {
     Serial.print("Received: ");
     Serial.println(input);
     if(input.toInt() < 256) {
       fanSpeed = input.toInt();
       EEPROM.put(FS_ADDR, fanSpeed);
     } else {
       Serial.println("Invalid Number");
     }
     input = "";
   }
   else {
     Serial.println("Not a number.");
   }
 } // end: if (Serial.available() > 0)
 analogWrite(FAN_PIN, fanSpeed);
}

Step 4: Control it!

You can change the fan speed with putting in a number over serial. It saves the number also in the EEPROM (at FS_ADDR) so when it resets, the speed will be the same than before.

Code

FanController.inoArduino
#include <EEPROM.h>

#define FAN_PIN 3;
#define FS_ADDR 0x01
int fanSpeed;

void setup() {
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  EEPROM.get(FS_ADDR, fanSpeed);
  if(fanSpeed < 1) fanSpeed = 255;
  analogWrite(FAN_PIN, fanSpeed);
  Serial.begin(9600);

}
char rx_byte = 0;
String input = "";

void loop() {
  if (Serial.available() > 0) {    // is a character available?
    rx_byte = Serial.read();       // get the character
  
    // check if a number was received
    if ((rx_byte >= '0') && (rx_byte <= '9')) {
      input.concat(rx_byte);
      
    }
    else if (rx_byte == '\n') {
      Serial.print("Received: ");
      Serial.println(input);
      if(input.toInt() < 256) {
        fanSpeed = input.toInt();
        EEPROM.put(FS_ADDR, fanSpeed);
      } else {
        Serial.println("Invalid Number");
      }
      input = "";
    }
    else {
      Serial.println("Not a number.");
    }
  } // end: if (Serial.available() > 0)
  analogWrite(FAN_PIN, fanSpeed);
}

Schematics

img_0150_LxZVUbAsjv.JPG
Img 0150 lxzvubasjv

Comments

Similar projects you might like

AV Cabinet Fan Controller

Project tutorial by BuddyC

  • 14,956 views
  • 8 comments
  • 33 respects

Bathroom Ventilation Fan Controller

Project tutorial by Erik de Ruiter

  • 4,198 views
  • 2 comments
  • 16 respects

Humidity Sensor-Controlled Bathroom Exhaust Fan

Project showcase by LIMPINGLIM

  • 12,839 views
  • 12 comments
  • 36 respects

Humidity Controller

Project tutorial by Shaeroden

  • 10,627 views
  • 3 comments
  • 15 respects

@Tiny85 Sleep Controller : Low Power Embedded System

Project tutorial by Shahariar

  • 6,689 views
  • 0 comments
  • 13 respects

Multi-Zone Heating Controller

Project tutorial by erkr

  • 15,984 views
  • 8 comments
  • 37 respects
Add projectSign up / Login