ITCooky Recipes

Lets cooky it yammy things!

How to automatically turn on PC fans with Arduino according to temperature!

дата October 24, 2020

Previously, I made software solution to turn the fans on/off via a relay on the Arduino upon entering the operating system. It works on Ubuntu (off), it worked on Windows via PowerShell (on), but now it doesn’t want to work anymore … so why should we bind to the OS if we can hang a temperature sensor on the Arduino?

The Arduino will monitor the temperature itself and turn on additional fans. Using the serial port, it will be possible to turn on/off the fans manually, turn on/off the automatic mode, observe the temperature.

Ill take form the article How to turn on additional fans on PC via Arduino!
1. Arduino with micro USB and 5V pin. The original Arduino Nano would work, but I didn’t have it, I had thatRobotDyn UNO R3 CH340G (R3-ATmega328/CH340G)
2. Double relay like this Relay Module 2 relays, 5V
3. Case for Arduino
4. Molex adapter for 4 fan connectors (2x5V 2x12V). I had an old Zalman ZM-MC 1, I had to cut the fan connectors to fit the PWM connectors
5. Cable Molex to Molex

And I added
6. Temperature sensor in DS18B20, its advantages are already calibrated and several can be connected to a line, but I have one like this DS18B20 Temperature Sensor Module, 2pcs, Detection Sensor Module Board for Arduino DC 5V 18B20, Digital Signal Output
7. USB motherboard adapter to a normal connector like this Kebidu USB 2.0 9 Pin Female 2 Ports Adapter Converter Motherboard Mainboard Internal Expander PC
I connect Arduino to it and it is very close to the video card, I even had to isolate it, I hope the electrical tape doesn’t melt!

The connection diagram is as follows

In the Arduino Software (IDE) you need to add two libraries One Wire library by Paul Stoffregen and Dallas Temperature library here everything is explained randomnerdtutorials.com

We go to Sketch> Include Library> Manage Libraries and there we will finde and install

Scetch

#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

const int PIN9 = 9; 
const int PIN8 = 8; 
const int tempOFF = 40; 
const int tempON = 45; 
bool value;
bool autostate;
String sdata="";  // Initialised to nothing.
String version="    Arduino Fan Temperature Control by itcooky.com v1.0"; 
int con = 0;
int coff = 0;


void setup() {
  // initialize digital pin LED_BUILTIN as an output.
   pinMode(PIN8, OUTPUT);
   pinMode(PIN9, OUTPUT);
   Serial.begin(9600);
   sensors.begin();
   value = EEPROM.read(0);
   autostate = EEPROM.read(1);
   Serial.println(version);
   Serial.print("    Started with ");
      if (autostate == 1)
    {
          Serial.println("AUTO ON");
    } else {
          Serial.println("AUTO OFF");      
    }
   Serial.println("---> Type \"help\" + [enter] for Help");


}


void loop(void ) {
byte ch;

sensors.requestTemperatures(); 
int tempCUR = sensors.getTempCByIndex(0);

if (value == 0) {
digitalWrite(PIN9, HIGH);
digitalWrite(PIN8, HIGH);
}
if (value == 1) {
digitalWrite(PIN9, LOW);
digitalWrite(PIN8, LOW);
}
if (autostate == 1)
{
if ( tempCUR <= tempOFF) {
coff++;
con = 0;
if (coff == 100)
{
value = 0;
}
}
if ( tempCUR >= tempON) {
con++;
coff = 0;
if (con == 100)
{
value = 1;
}
}




}
   if (Serial.available()) {
      ch = Serial.read();

      sdata += (char)ch; 

      if (ch=='\r') {  // Command recevied and ready.
         sdata.trim();
         
     if (sdata == "help") 
        { 
          Serial.println("    HELP");
          Serial.println("on - FANs on (set auto off)");
          Serial.println("off - FANs off (set auto off)");
          Serial.println("temp - see sensor temperature");
          Serial.print("autoon - auto start FANs than temp is more than ");
          Serial.print(tempON);
          Serial.print("°C and stop than its less than ");
          Serial.print(tempOFF);
          Serial.println("°C");
          Serial.println("autooff - stop auto FANS control");
        } 
     if (sdata == "autoon") 
        { autostate = 1;
          EEPROM.write(1, 1);
          Serial.println("    AUTO ON");
          Serial.print("FANs on temp ");
          Serial.print(tempON);
          Serial.println("°C");
          Serial.print("FANs off temp ");
          Serial.print(tempOFF);
          Serial.println("°C");
          Serial.print("Temperature now: ");         
          Serial.print(tempCUR); 
          Serial.println("°C");
        }       
      if (sdata == "autooff") 
        { autostate = 0;
          EEPROM.write(1, 0);
          Serial.println("    AUTO OFF");
          Serial.print("FANs on temp ");
          Serial.print(tempON);
          Serial.println("°C");
          Serial.print("FANs off temp ");
          Serial.print(tempOFF);
          Serial.println("°C");
          Serial.print("Temperature now: ");         
          Serial.print(tempCUR); 
          Serial.println("°C");  
        }        
     if (sdata == "temp") 
        {           
          Serial.print("Temperature now: "); 
          Serial.print(sensors.getTempCByIndex(0)); 
          Serial.println("°C");   
        }
     if (sdata == "off") 
        {       
          EEPROM.write(0, 0);
          EEPROM.write(1, 0);
          value = 0;
          autostate = 0;
          Serial.println("    FANs off (AUTO OFF)");
          Serial.print("Temperature now: ");         
          Serial.print(tempCUR); 
          Serial.println("°C"); 
        }
     if (sdata == "on") 
        {
          EEPROM.write(0, 1);
          EEPROM.write(1, 0);
          value = 1;
          autostate = 0;
          Serial.println("    FANs on (AUTO OFF)");
          Serial.print("Temperature now: ");         
          Serial.print(tempCUR); 
          Serial.println("°C"); 

        }   
         sdata = ""; // Clear the string ready for the next command.
        }
     }
}

Here you only need to change the constant tempOFF tempON temperatures at which the fans will turn off and on, you must consider the place where the sensor will be, analyze the temperature of it!

We put everything together according to the schematic, upload scetсh to your arduino and install it on the computer. I have a case Coguar QBX, thanks to SFF power supply, I have a great place to put Arduino


The sensor itself is located above the memory, next to the video card, the hottest place on the PC.

You can connect to Arduino through the serial port through the program Arduino Software (IDE) by the menu Tools> Serial Monitor ! But in Windows 10 I will connect via Putty!

Download Putty here www.chiark.greenend.org.uk

In Windows, look here Select Start> Settings> Devices> Bluetooth & other devices in which COM port the Arduino appeared, I have it on COM4 with this configuration I connect, the speed is set to 9600

In the window that appears, I type help , press [enter]! I can’t see what I’m entering on the screen!

I get a list of available commands

    HELP
on - FANs on (set auto off)
off - FANs off (set auto off)
temp - see sensor temperature
autoon - auto start FANs than temp is more than 45°C and stop than its less than 40°C
autooff - stop auto FANS control

Here I look at the temperature, the command temp and [enter], shows the temperature with hundredths
I turn on the fans, this immediately turns off the automatic control.
I turn off the fans and turn on the automatic control – here the temperature is without hundredths

The relay clicks when activated, so it is always clear that the fans have been turned on; well, it is clear that from the noise of fans too!


One Response to “How to automatically turn on PC fans with Arduino according to temperature!”

  1. […] the way, turning on additional fans like i am doing it in this article How to automatically turn on PC fans with Arduino according to temperature! goes down 3 degrees from A4500, soo it makes sense to blow the end of the […]

Leave a Reply

Your email address will not be published. Required fields are marked *