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

by sam_moshiri in Circuits > Electronics

690 Views, 0 Favorites, 0 Comments

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

PWM Cooling FAN Control & Over Temperature Protection using LM35 and ATTiny13

Proper thermal dissipation is an essential rule for nowadays electronics. 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-wires or 4-wires 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). To get high-quality fabricated PCB boards, you can send the Gerbers to PCBWay and purchase original components using the componentsearchengine.com. 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.

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)

Supplies

Main Ref: https://www.eeweb.com/pwm-cooling-fan-controller-a...

[1]: ATTiny13 datasheet: https://componentsearchengine.com/Datasheets/1/AT...

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

[3]: 2N7002 datasheet: https://datasheet.datasheetarchive.com/originals/...

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

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

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

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

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

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

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

Figure 1 Schematic Diagram of the PWM Cooling Fan Controller Device

Fig-1.jpg

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.


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 mound 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.

Figure 2 an Intel CPU Fan Which Is Cheap Enough to Be Used for Cooling

Fig-2.jpg

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.

Figure 3 PCB Layout of the PWM Cooling FAN Control Circuit

Fig-3.jpg

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.

Figure 4 All Supported Electronic Designing CAD Software by the SamacSys Plugins

Fig-4.jpg

Figure 5 Selected Component Libraries in the SamacSys Altium Plugin

Fig-5.jpg

Figure 6 a 3D View and Two Assembly Drawings of the PCB Board

Fig-6.jpg

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:

Code

<span>#include <util/delay.h>    </span><br>

// 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);
  }
}

Figure 7 Additional Boards Manager URLs, Arduino IDE Preferences Section

Fig-7.jpg

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_MCUdu...

Figure 7 shows this part of the Arduino IDE.

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.

Figure 8 Installed MicroCore Library to Support the ATTiny13 MCU

Fig-8.jpg

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.

Figure 9 HEX File Generation in the Arduino IDE

Fig-9.jpg

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].

Figure 10 25KHz PWM Signal to the FAN (Siglent SDS1104X-E)

Fig-10.jpg

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

Figure 11 Bill of Materials for the PWM Cooling-FAN Control Circuit

Fig-11.jpg