Maker.io main logo

3-Wires/4-Wires FAN Control and Over Temperature Protection using LM35

2022-06-08 | By Hesam Moshiri

License: Attribution Non-commercial

Proper thermal dissipation is an essential rule for electronics nowadays. The best operating temperature for the electronic components is 25 degrees (standard room temperature). Thermal dissipation in some commercial devices is not done properly which affects the lifetime and performance of the devices. So, embedding a compact automatic cooling fan controller board would be useful. Also, it can be used to protect your own designed circuits and their power components, such as regulators, Mosfets, power transistors … etc.

Previously, I had introduced a circuit to control the cooling fans, however, my intention was not to use any microcontroller and keep it as simple as possible. So, the device was a simple ON/OFF switch for the fan, depending on the defined temperature threshold. This time, I decided to design a complete and more professional circuit to control the majority of the standard fans (25KHz PWM) using an LM35 temperature sensor and an ATTiny13 microcontroller.

I used SMD components, and the PCB board is compact. It can control one or several standard 3-wire or 4-wire fans, connected in parallel, such as CPU fans. Moreover, the target device/component can be protected against over-temperature using a relay. The user is also notified by visual/acoustic warnings (a flashing LED and a Buzzer).

To design the schematic and PCB, I used Altium Designer 22 and the SamacSys component libraries (Altium plugin). I initially tested the circuit on a breadboard. I used the Siglent SDM3045X multimeter to accurately examine the voltages and the Siglent SDS1104X-E oscilloscope to examine the shape, duty cycle, and frequency of the PWM pulse.

 YouTube: https://www.youtube.com/watch?v=EZF5MhIT5wk

Specifications

  • Supply Voltage: 12VDC (See text)
  • Load Over-temperature Protection: Yes (above 60 degrees)
  • PWM Frequency: 25KHz
  • FAN Voltage: 12VDC
  • Maximum Load Voltage/Current: 250V-10A (AC/DC)
  • Active Temperature Thresholds: 25C to 60C
  • Over-temperature Warning: Yes (Flashing LED and Buzzer)

Circuit Analysis

Figure 1 shows the schematic diagram of the PWM cooling fan control device. The heart of the circuit is an ATTiny13 microcontroller [1]. It reads the temperature values and decides what to do with the fan, relay, and the buzzer.

 fog1

Figure 1

Schematic diagram of the PWM cooling fan controller device

 

According to the ATTiny13 datasheet: “The ATtiny13 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny13 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.”

I have configured the clock source of the IC1 for 9.6MHz, internal. It is enough for our applications without using an external clock source, such as a crystal. R1 is a pull-up resistor for the Reset pin to prevent the MCU to Reset unwantedly. C2 and C3 are decoupling capacitors to reduce the noise of the +5V supply.

Power Supply

The main component of the power supply is REG1, which is a 78L05 regulator [2]. I selected the SO-8 package for this regulator. P5 is a two-pins male XH connector that supplies the controlling board and fan(s). The current of the supply voltage (12V) is dependent on the number of connected fans, otherwise, the current consumption of the +5V supply rail is very low. R7 and C7 build a low-pass RC filter at the input to reduce the input noise as much as possible, however, the voltage drop on the RC filter is not significant to affect the operation of the regulator. D3 is an 0805 green LED that shows the proper supply provision and R8 limits the current to D3. C5 and C7 are used to reduce the output voltage noise.

ALARM

The components of this section are R5, R6, P4, and D2. D2 is a 0805 red LED that flashes when over-temperature happens. R5 limits the D2 current. P4 is a 2-pins XH male connector that is used to connect a 5V buzzer. R6 limits the current to the buzzer.

RELAY

The components of this section are Q1, D1, R4, C4, K1, and P3. K1 is a 12V-10A relay that is used to switch OFF the load when over-temperature happens. It is normally closed (NC) which means the load is ON. D1 protects the Q1 against reverse currents of the Relay’s inductor and C4 damps the current spikes. Q1 is a 2N7002 [3] mosfet that is used to switch the Relay. R4 is used to pull-down the gate pin of Q1 to avoid unwanted triggering.

LM35 Temperature Sensor

P1 is a 3-pins male XH connector that is used to connect the LM35 sensor to the board. You should mount the LM35 on the heatsink using thermal glue and use a short wire to connect the sensor to the board. C1 is a decoupling capacitor that is used to reduce noise.

AVR ISP Programmer

ISP is a 5-pins male header that is used to program the microcontroller onboard. You can use whatever programmer you like, such as the cheap USBasp programmer or similar.

12V FAN

P2 is a 3-pins XH male connector that is used to connect the fan(s) to the board. Q2 is used to transfer the PWM pulses to the control pin of the fan. R2 is a 10K pull-up resistor that shifts the 5V PWM signal level to 12V. R3 is a pull-down resistor to avoid unwanted triggering of the gate pin of Q3. Figure 2 shows a typical Intel CPU fan which could be one of your options to cool down the components, using this controller board.

 fig2

Figure 2

An Intel CPU fan which is cheap enough to be used for cooling

PCB Layout

Figure 3 shows the PCB layout of the design. It is a two layers PCB board and except for the Relay and connectors, other components are SMD. The smallest package size is 0805, you shouldn’t have any problem with soldering the component, although you can order it fully assembled.

 fig3

Figure 3

PCB layout of the PWM Cooling fan control circuit 

When I decided to design the schematic and PCB for this project, I realized that I don’t have the component libraries of Q1[4], Q2, REG1[5], and IC1[6] in my component libraries storage. So as usual, I selected IPC-rated SamacSys component libraries and installed the missing libraries (schematic symbol, PCB footprint, 3D model) using the free SamacSys tools and services. There are two ways to import the libraries: You can visit the componentsearchengine.com and download and import the libraries manually, or you can use the SamacSys CAD plugins and automatically import/install the libraries into the design environment. Figure 4 shows all supported electronic designing CAD software [7]. As it is clear, all famous players are supported. I use Altium Designer, so I installed the missing libraries using the SamacSys Altium plugin (Figure 5) [8]. Figure 6 shows a 3D view of the PCB board and assembly drawings.

 fig4

Figure 4

All supported electronic designing CAD software by the SamacSys plugins

 fig5

Figure 5

Selected component libraries in the SamacSys Altium plugin

 fig6

Figure 6

A 3D view and two assembly drawings of the PCB board

 

The Code of the Microcontroller

I use the Arduino IDE to write and compile the code of the microcontroller. I installed the MicroCore [9] in the library manager to be able to compile the code for the ATTiny13. You can consider the code below:

Copy Code
#include <util/delay.h>    


// Clock at 9.6MHz
#define F_CPU 9600000


const int PWMPin = 1;
analog_pin_t PotPin = A3;
const unsigned char relayPin = 0, buzzerPin = 4;
unsigned int rawTemp = 0, out = 0;
unsigned char counter = 0;


void setup()
{
analogReference(INTERNAL1V1);
pinMode(PWMPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(relayPin, 0);
digitalWrite(buzzerPin, 0);
// Phase Correct PWM Mode, no Prescaler
// PWM on Pin 1(PB1), Pin 0(PB0) disabled
// 9.6MHz / 192 / 2 = 25Khz
TCCR0A = _BV(COM0B1) | _BV(WGM00);
TCCR0B = _BV(WGM02) | _BV(CS00);
// Set TOP and initialize duty cycle to zero(0)
OCR0A = 192; // TOP - DO NOT CHANGE, SETS PWM PULSE RATE
OCR0B = 192; // duty cycle for Pin 1(PB1)
}


void loop()
{
rawTemp = analogRead(PotPin) + rawTemp;
counter ++;
if (counter == 15) {
rawTemp = rawTemp / 15;
if (rawTemp < 232) {
OCR0B = 192;
} else {
out = map(rawTemp, 232, 558, 192, 0);
OCR0B = out;
}
if (rawTemp > 560)
{
emergency_OFF();
}
counter = 0;
rawTemp = 0;
}
_delay_ms(25);
}


void emergency_OFF() {
while (1) {
digitalWrite(relayPin, 1);
digitalWrite(buzzerPin, 1);
_delay_ms(250);
digitalWrite(buzzerPin, 0);
_delay_ms(250);
}
}

I have defined the ADC reference voltage to be 1.1V-Internal. It means the maximum value of the ADC is 1023 for 1100mV of input voltage. The output voltage of the LM35 temperature sensor for 25 degrees is 250mV and 600mV for 60 degrees. So, it nicely fits within the range of ADC input, up to 110 degrees, without any hardware modifications.

To change the thresholds, you should modify the out = map(rawTemp, 232, 558, 192, 0), for instance, to increase the temperature upper threshold from 60 degrees to 70 degrees.

To install the MicroCore, you should insert this URL in the Additional Boards Manager URLs, in the preferences section of the Arduino IDE:

https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json

Figure 7 shows this part of the Arduino IDE.

 fig7

Figure 7

Additional Boards Manager URLs, Arduino IDE Preferences Section

Then you should go to the Tools menu and Boards Manager and install the MicroCore. Then you will see the installed Board as it is shown in Figure 8.

 fig8

Figure 8

Installed MicroCore library to support the ATTiny13 MCU

To generate the HEX file and program the MCU, you should go to the Sketch menu and press the Export Compiled Binary. Figure 9 shows a picture of this process.

 fig9

Figure 9

HEX file generation in the Arduino IDE

Then just connect your programmer to the ISP header of the PCB board and program the MCU. Fuse bits should be set on the 9.6MHz internal clock, with no clock division.

Test

As it is clear from the YouTube video, I tested the circuit on the breadboard before I go to design the schematic and PCB. So, you can be sure that everything works perfectly. Figure 10 shows the PWM signal of the fan control pin. I used the Siglent SDS1104X-E oscilloscope to capture the signal [10].

 fig10

Figure 10

25KHz PWM signal to the FAN (Siglent SDS1104X-E)

Bill of Materials

Figure 11 shows the bill of materials and part numbers for this project.

 fig11

Figure 11

Bill of materials for the PWM Cooling-FAN control circuit

References

Main Ref: https://www.eeweb.com/pwm-cooling-fan-controller-and-over-temperature-protection-using-lm35-and-attiny13/

[1]: ATTiny13 datasheet: https://ww1.microchip.com/downloads/en/DeviceDoc/2535S.pdf

[2]: 78L05 datasheet: https://www.st.com/resource/en/datasheet/l78l.pdf

[3]: 2N7002 datasheet: https://datasheet.datasheetarchive.com/originals/distributors/Datasheets-26/DSA-502170.pdf

[4]: 2N7002 schematic symbol, PCB footprint, 3D model: https://componentsearchengine.com/part-view/2N7002/Nexperia

[5]: L78L05 schematic symbol, PCB footprint, 3D model: https://componentsearchengine.com/part-view/L78L05ABD13TR/STMicroelectronics

[6]: ATTiny13 schematic symbol, PCB footprint, 3D model: https://componentsearchengine.com/part-view/ATTINY13-20SSU/Microchip

[7]: Electronic designing CAD software plugins: https://www.samacsys.com/library-loader-help

[8]: Altium Designer plugin: https://www.samacsys.com/altium-designer-library-instructions

[9]: MicroCore board manager: https://github.com/MCUdude/MicroCore#analog-pins

[10]: Siglent SDS1104X-E oscilloscope: https://siglentna.com/product/sds1104x-e-100-mhz/

 

TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum