How to control fans using LM35 and ATTiny13
Source: InternetPublisher:三月小雨 Keywords: Temperature sensor fan cooling Updated: 2023/12/26
Proper cooling is a basic rule in today's electronics. The optimal operating temperature of electronic components is 25 degrees (standard room temperature). Cooling in some commercial equipment is not done correctly, which can affect the life and performance of the equipment. Therefore, it would be useful to embed a compact automatic cooling fan controller board. Additionally, it can be used to protect your own designed circuits and their power components, such as voltage regulators, MOSFETs, power transistors, etc.
Previously, I have presented a circuit to control a cooling fan, however, my intention was to not use any microcontroller and keep it as simple as possible. The device is therefore 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 using a LM35 temperature sensor and an ATTiny13 microcontroller to control most standard fans (25KHzPWM).
I used SMD components and the PCB board is compact. It can control one or more standard 3-wire or 4-wire fans connected in parallel, such as a CPU fan. Additionally, relays can be used to protect the target device/component from overheating. The user is also notified via visual/audible warnings (flashing LED and buzzer).
To design the schematic and PCB I used AltiumDesigner22 and the SamacSys component library (Altium plugin). For high quality manufactured PCB boards you can send your Gerbers to PCBWay and use componentsearchengine.com to purchase original components. I initially tested the circuit on a breadboard. I used a SiglentSDM3045X multimeter to accurately check the voltage and a SiglentSDS1104X-E oscilloscope to check the shape, duty cycle and frequency of the PWM pulses.
Specification
Power 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)
Valid temperature threshold: 25C to 60C
Overtemperature warning: Yes (flashing LED and buzzer)
circuit analysis
Figure 1-Schematic diagram of PWM cooling fan controller device
Figure 1 shows a schematic diagram of a PWM cooling fan control device. The core of the circuit is an ATtiny13 microcontroller [1]. It reads the temperature value and decides what to do with the fan, relay and buzzer.
According to the ATtiny13 datasheet: "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 a throughput of close to 1MIPS/MHz, enabling the system to Designers can optimize power consumption and processing speed.”
I have configured IC1's clock source to 9.6MHz, internally. For our application it is enough without using an external clock source such as a crystal. R1 is a pull-up resistor for the reset pin to prevent the MCU from being reset accidentally. C2 and C3 are decoupling capacitors used to reduce the noise of the +5V power supply.
power supply
The main component of the power supply is REG1, which is a 78L05 voltage regulator [2]. I chose the SO-8 package for this regulator. P5 is a two-pin male XH connector that provides power to the control board and fan. The current drawn from the supply voltage (12V) depends on the number of fans connected, otherwise the current draw from the +5V rail is very low. R7 and C7 build a low-pass RC filter at the input to reduce input noise as much as possible, but the voltage drop across the RC filter has little effect on the operation of the regulator. D3 is a 0805 green LED used to show the correct power supply, R8 limits the current to D3. C5 and C7 are used to reduce output voltage noise.
alarm
The components of this section are R5, R6, P4 and D2. D2 is a 0805 red LED that will flash when overheating occurs. R5 limits D2 current. P4 is a 2-pin XH male connector for connecting the 5V buzzer. R6 limits the buzzer current.
relay
The components of this section are Q1, D1, R4, C4, K1 and P3. K1 is a 12V-10A relay designed to shut down the load in the event of overheating. It is normally closed (NC), which means the load is open. D1 protects Q1 from the reverse current of the relay inductor, and C4 suppresses current spikes. Q1 is a 2N7002 [3] Mosfet, used to switch relays. R4 is used to pull down the gate pin of Q1 to avoid unwanted triggering.
LM35 temperature sensor
P1 is a 3-pin male XH connector used to connect the LM35 sensor to the board. You should use thermal paste to mount the LM35 on the heatsink and use short wires to connect the sensor to the board. C1 is a decoupling capacitor used to reduce noise.
AVRISP
The ISP is a 5-pin male header used to program the onboard microcontroller. You can use any programmer you like, such as a cheap USBasp programmer or similar.
12V fan
P2 is a 3-pin XH male connector used to connect the fan to the circuit board. Q2 is used to transmit the PWM pulses to the fan's control pin. R2 is a 10K pull-up resistor that converts the 5VPWM signal level to 12V. R3 is a pull-down resistor to avoid triggering Q3's gate pin unnecessarily. Figure 2 shows a typical Intel CPU fan that may be one of your options for cooling components with this controller board.
Figure 2 - An Intel CPU fan that is cheap enough to use for cooling
PCB layout
Figure 3 shows the designed PCB layout. It is a two-layer PCB board, except for the relays and connectors, other components are SMD. The smallest package size is 0805 and you shouldn't have any problems soldering the components, although you can order it fully assembled.
Figure 3-PCB layout of PWM cooling fan control circuit
When I decided to design the schematic and PCB for this project, I realized that I didn't have libraries for Q1, Q2, REG1, and IC1 in my library store. So, as usual, I selected the IPC-level SamacSys component library and installed the missing libraries (schematic symbols, PCB footprints, 3D models) using the free SamacSys Tools and Services. There are two ways to import a library: you can visit componentsearchengine.com and manually download and import the library, or you can use the SamacSysCAD plug-in and automatically import/install the library into your design environment.
The image above shows all supported electronic design CAD software. It's clear that all the famous players are supported. I use AltiumDesigner, so I installed the missing libraries using the SamacSysAltium plugin as shown below.
3D view of the PCB board and two assembly drawings
Microcontroller code
I use ArduinoIDE to write and compile code for a microcontroller. I installed MicroCore[9] in the library manager to be able to compile the code for ATtiny13. You can consider the following code:
// 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 internally. This means that for an input voltage of 1100mV, the maximum value of the ADC is 1023. The output voltage of the LM35 temperature sensor is 250mV at 25 degrees and 600mV at 60 degrees. Therefore, it is ideally suited for the ADC input range, up to 110 degrees, without any hardware modifications.
To change the threshold, you should modify out=map(rawTemp, 232, 558, 192, 0), for example, to increase the upper temperature threshold from 60 degrees to 70 degrees.
To install MicroCore you should insert this URL in the AdditionalBoardsManagerURLs in the preferences section of the ArduinoIDE:
https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json
Figure 7 shows this part of the Arduino IDE.
Figure 7 - Add-on Board Manager URL, ArduinoIDE Preferences Section
Then you should go to the Tools menu and BoardsManager and install MicroCore. You will then see the installed board as shown in Figure 8.
Figure 8 - MicroCore library installed to support ATtiny13MCU
To generate the HEX file and program the MCU, you should go to the Sketch menu and press ExportCompiledBinary. Figure 9 shows a picture of this process.
Figure 9-Generating HEX file in ArduinoIDE
Then simply connect your programmer to the ISP header of the PCB board and program the MCU. The fuse bits should be set on the 9.6MHz internal clock with no clock division.
test
Before designing the schematic and PCB, I tested the circuit on a breadboard. So you can make sure everything is working properly. Figure 10 shows the PWM signal of the FAN control pin. I use a SiglentSDS1104X-E oscilloscope to capture the signal.
Figure 10-25KHzPWM signal to fan (SilentSDS1104X-E)
Material list
Figure 11 shows the bill of materials and part numbers for this project.
Figure 11-BOM of PWMCooling-FAN control circuit
- Improved circuit diagram of 8050 transistor emitter drive relay
- Interface circuit between AD574A and single chip microcomputer
- Interface circuit between 51 single chip microcomputer and MAX7219
- Interface circuit based on 8155 and single chip microcomputer
- Ultrasonic anti-theft alarm designed based on microcontroller and HC-SR04
- Make a capacitive soil moisture sensor using ESP32
- USB-serial port conversion circuit made with CP2102 chip
- MAX232 connection method
- Interface circuit between digital measuring tool and 51 microcontroller
- ISP2 using real USB chip and M8
- Remote temperature sensing circuit diagram
- 3 and 1/2 digit digital thermometer using diode as temperature sensor
- Temperature detection control circuit for vegetable greenhouses
- Motor thermal protection circuit controlled by 3UN2 (has a temperature sensor)
- High-low temperature sensor
- T-X type temperature sensor thermometer
- Temperature sensor used in crystal compensation circuit
- KTY87 temperature sensor microcontroller interface circuit
- AD22100 type voltage temperature sensor circuit with signal conditioning
- No temperature sensor, DC power supply linear charger circuit diagram