Temperature-Controlled Automatic Cooling System
Auto fan control based on a temperature threshold
Aim
To design a system that measures ambient temperature with a sensor and automatically switches a fan (or any cooling device) ON or OFF according to a set threshold.
Overview
An analog temperature sensor module (NTC thermistor based, e.g. LM35 or an NTC module) outputs a voltage proportional to the room temperature. The Arduino reads this value on an analog input, converts it to degrees Celsius, and compares it with a user-defined threshold. When the temperature rises above the threshold, the controller drives a relay/transistor that powers the cooling fan. When the temperature falls back below the threshold (with a small hysteresis band to avoid rapid switching), the fan is turned OFF.
Components Required
- Arduino Uno
- NTC temperature sensor module (or LM35)
- Relay module (or transistor driver, e.g. 2N2222 + diode)
- DC fan (5V/12V)
- Green LED + 220 ohm resistor (fan ON indicator)
- Breadboard and jumper wires
Circuit Connections
| From | To | Note |
|---|---|---|
| Sensor VCC | Arduino 5V | - |
| Sensor GND | Arduino GND | - |
| Sensor AO (analog out) | Arduino A0 | Analog voltage 0-5V |
| Relay IN | Arduino D8 | Drives the fan through the relay |
| LED anode (via 220R) | Arduino D9 | Fan status indicator |
| LED cathode | Arduino GND | - |
| Fan + | Relay NO contact and external supply | - |
| Fan - | Common ground | - |
Interactive Circuit Diagram
Simulate the circuit: adjust the sensor inputs below and watch the outputs react according to the control logic.
Working
- Sensor continuously outputs a voltage proportional to temperature.
- Arduino samples the analog channel every second and smooths it by averaging a few readings.
- The averaged value is converted to Celsius using the sensor's transfer function.
- If temperature > THRESHOLD + HYST, the relay pin is driven HIGH and the fan runs.
- If temperature < THRESHOLD - HYST, the relay pin is driven LOW and the fan stops.
- The status LED mirrors the relay state so the fan state is visible even when the fan is not connected.
Control Logic
Arduino Code
1// Practical 1: Temperature-Controlled Automatic Cooling System2const int SENSOR_PIN = A0; // Analog output of the temperature sensor3const int RELAY_PIN = 8; // Relay / driver input for the fan4const int LED_PIN = 9; // Fan status LED56const float T_HI = 30.0; // Fan turns ON above this temperature7const float T_LO = 28.0; // Fan turns OFF below this temperature89float readTemperature() {10 // Average 10 samples for a stable reading11 long sum = 0;12 for (int i = 0; i < 10; i++) {13 sum += analogRead(SENSOR_PIN);14 delay(5);15 }16 float adc = sum / 10.0; // 0..102317 float volts = adc * 5.0 / 1023.0; // 0..5 V18 return volts * 100.0; // LM35: 10 mV per degree C19}2021void setup() {22 pinMode(RELAY_PIN, OUTPUT);23 pinMode(LED_PIN, OUTPUT);24 Serial.begin(9600);25}2627void loop() {28 float tempC = readTemperature();29 Serial.print("Temp: ");30 Serial.print(tempC);31 Serial.print(" C -> ");3233 if (tempC > T_HI) { // Hot: start cooling34 digitalWrite(RELAY_PIN, HIGH);35 digitalWrite(LED_PIN, HIGH);36 Serial.println("FAN ON");37 } else if (tempC < T_LO) { // Cooled down: stop fan38 digitalWrite(RELAY_PIN, LOW);39 digitalWrite(LED_PIN, LOW);40 Serial.println("FAN OFF");41 }42 delay(1000);43}