This project outlines the construction of a closed-loop thermal management system. Using an LM35 temperature sensor and an ATmega328P microcontroller, the system regulates a DC fan's speed via Pulse Width Modulation (PWM). It features user interaction through two potentiometers, allowing you to set a custom temperature trigger point and a maximum fan speed.
Automated Fan Cooling System Project Overview
The primary goal of this embedded application is to maintain a stable environment by dynamically adjusting fan speed through real-time feedback. The system continuously reads ambient temperature via an analog sensor and compares it to a user-defined threshold. When the temperature exceeds this limit, the firmware instructs the fan to ramp up to the pre-set speed using a high-frequency PWM signal, ensuring smooth motor operation and reduced mechanical stress.
Hardware Architecture
As a classic embedded system, the hardware is organized into three functional blocks: Sensing, Processing, and Actuation.
1. Sensing and User Input (Analog Interface)
LM35 Sensor: This component provides an analog voltage directly proportional to the Fahrenheit temperature at a scale of 10mV/°F.
Threshold Potentiometer: This allows the user to manually dial in the temperature at which the cooling fan should activate.
Speed Potentiometer: This defines the maximum duty cycle, essentially capping the fan's top speed between 0% and 100%.
2. Processing Unit (ATmega328P)
ADC (Analog-to-Digital Converter): The microcontroller converts the analog signals from the sensor and both potentiometers into digital values for software processing.
Timer1 (16-bit): This hardware timer is configured in Fast PWM Mode to generate a stable 1 kHz signal on the OC1B pin.
3. Actuation (Fan Drive)
Switching Element: A logic-level MOSFET (like the IRLZ44N) is used to handle the high current required by the fan motor, as the microcontroller pins cannot drive the motor directly.
Isolation: An optocoupler (such as the 4N25) is often integrated into the design to separate the noisy motor circuit from the sensitive digital logic, preventing electrical interference.
Circuit Diagram
Operational Logic
The firmware follows a continuous control loop, a fundamental characteristic of embedded systems, to ensure the fan responds naturally to thermal changes.
Data Acquisition: The ADC samples the LM34 sensor, the Threshold Pot, and the Speed Pot in sequence.
Comparison: The code performs a logical check: is the Current Temperature greater than the Threshold Temperature?
PWM Ramping:
Fan ON: If the threshold is exceeded, the duty cycle gradually increases (ramps) until it matches the Speed Pot setting. This avoids sudden current spikes in the circuit.
Fan OFF: Once the temperature drops below the threshold, the fan is gradually slowed down to a complete stop.
User Feedback: The system updates a 16x2 LCD in 4-bit mode to display real-time statistics, including the current temperature, set threshold, and fan status.
Technical Specifications
| Feature | Detail |
| Microcontroller | ATmega328P (8-bit AVR Architecture) |
| PWM Frequency | 1 kHz (Ideal for most standard DC cooling fans) |
| Control Method | Software-based Pulse Width Modulation |
| Display Interface | 16x2 Character LCD (4-bit Parallel) |
| Power Efficiency | High (PWM minimizes power wasted as heat) |
Design Recommendation
To prevent the fan from "stuttering" or rapidly clicking on and off when the temperature is exactly at the threshold, it is best practice in embedded design to implement Hysteresis. For example, you might program the fan to turn ON at 80°F but wait until the temperature drops to 77°F before turning it back OFF. This creates a much more stable and professional cooling environment.
Watch Video Demonstration
Download Code:
Related Tutorials:
- Building an Automatic Temperature Controller Using Arduino and a PID Algorithm
- Closed-loop Temperature Controller with Arduino
- High-Precision Temperature Monitoring: ADS1115, LM35, and I2C LCD with Arduino
