---
title: "PROJECT 36: TEMPERATURE-CONTROLLED COOLING SYSTEM"
description: "1. **[Introduction](http://Introduction)** Everyone prefers to work in a cool and comfortable environment, free from excessive heat. However, manually turning a cooling fan on and off based on the temperature can be inconvenient and time-consuming. This is why an automated temperature-controlled…"
url: "https://nedu.rw/documentation/project-36-temperature-controlled-cooling-system/"
updated: "2026-10-13"
category: InnoKit MPK A100 / Experiments you can do with MPK A100
---

# PROJECT 36: TEMPERATURE-CONTROLLED COOLING SYSTEM

1. **[Introduction](http://Introduction)**

Everyone prefers to work in a cool and comfortable environment, free from excessive heat. However, manually turning a cooling fan on and off based on the temperature can be inconvenient and time-consuming. This is why an automated temperature-controlled cooling system is highly beneficial.

1. **[Objectives](http://Objectives)**

- Monitoring the amount of temperature inside the room. 
- Turn on and off automatically the cooling  fan depending on the level of temperature inside the room.

1. **[Components to be used](http://Components to be used)**

- MPK kit
- Relay module
- DHT11 Sensor
- 12V Cooling fan
- 12V Voltage supply

| ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfPL1tOlZJsAu38FUCpdBPVPxRM5fC5vS9K8BygSIZyrlqxNUbQMuNJvSpG6V64GjTHF7Iq_oxGYgbfzvZoPMnbPHzm4e7DxGwyhwwi7IwPHrZAxlvDKb_HBZHa7816bb_Pb6UZByYOw1ddQjxm7Z8SMMcF0AKRQy_M1IQi690Fyh2L?key=EIFaBMwRIuJeDoZo9taXbw) | ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfDrhlYJRlLkfodeVMWycsMaox9WNfvbHc6qSZvUax3N8Uf4OPzQK8Yye6zCNcZekNb7YG6rZYAhf1vNhDSVpS6bYChKUavAgIY2dsxRWDQwcGr7mOsW8g0eLxIgV1v0h4cCpsbSwC2D2JpCh_Ss01B6tg-u81orKhQ6Qglsm97T2zO?key=EIFaBMwRIuJeDoZo9taXbw) |
| --- | --- |
| ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeQov2vfFELuAuYe_ARKuPkr2L-va7Vqy3B0zAD43mipOOlWpFiVO2fftki2PAnuxiCxq8Nn1ZRIdRKxNE3wfJ4Yp3XciqRSpaQEyxoGVnKtf4iwrFL0_N1LTOSsbGPH6qNIXLEwF_dBceEo_HvpAzL58ZSA2Xz3R2MhFEB3uhNiog?key=EIFaBMwRIuJeDoZo9taXbw) |  |
| ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXflwrElZQSItDTQ9ZBQU5VWRQ2vT9ye9JeDlqhnHO2gCo5gaRmceyme8oZaiMsS7oYT82hCa5sH3p6eVYLBABq19avehKKg6YTWjVeIcVq74ciLjlbGjf8ccWFTOcNg2O3KEyyYUo2LImRIYT_rw2kzUFsaHzR1XydL8PdwzjN9PNel?key=EIFaBMwRIuJeDoZo9taXbw) |  |

1. **[Circuit diagram](http://Circuit diagram)**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXe17wEuCZ01Ts8ACaRiXmoFmX5AXzxSI9KPbqIYqniXrFvq81ReMXa7UjQkB_Cjk8MOfDYTX-PzGMK85OFzqve69YOmEAmbWj5--ApuKkfTX46CS0HGgETe0DpL4_ILNufqaHHLpzNmEUj6oBztIeMC7I8bH7OJoQBgEe-aFDu0NKfp?key=EIFaBMwRIuJeDoZo9taXbw)

***Figure: Components used to make connection on the board***

1. **[Arduino codes](http://Arduino Codes)**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdF5BpzFhOo_GZKS-DR8R9X49vIA4uEV_X3wgDFaC9fLg7OtNT7r7zPgzDhiVLjsukHUrfkdXfD0wnSJRWfl3ptlsCS5bVBetYIPOUJvXXxksu1qHIv262bTThiAerEbWzGxr0sAGi6DqNp?key=EIFaBMwRIuJeDoZo9taXbw)

***Figure: DHT11 sensor and relay connection***

    12
345678910 111213
14151617181920 212223242526272829303132    #includeDHT.h> #define FAN_PIN 6 // The Arduino Nano pin connected to relay which drives the fan #define DHT_PIN 8 // The Arduino Nano pin connected to DHT11 sensor #define DHT_TYPE DHT11 const int THRESHOLD_ON = 30; // upper threshold of temperature, change to your desire value const int THRESHOLD_ON = 28; // upper threshold of temperature, change to your desire value
 DHTdht(DHT_PIN, DHT_TYPE); float temperature; // temperature in Celsius voidsetup() { Serial.begin(9600); // Initialize the Serial to communicate with the Serial Monitor. dhtbegin(); // initialize the sensor pinMode(FAN_PIN, OUTPUT); // initialize digital pin as an output  } voidloop(){ // wait a few seconds between measurements. delay(2000); temperature = dhtreadTemperature();; // read temperature in Celsius if(isnan(temperature)) {  Serial.println("Failed to read from DHT sensor!"); }else{ if(temperature > THRESHOLD_ON){   Serial.println("The fan is turned on");  digitalWrite(FAN_PIN, HIGH); // turn on }else if(temperature  Serial.println("The fan is turned off");   digitalWrite(FAN_PIN, LOW); // turn on } } }

1. **[Code knowledge](http://Code knowledge)**

    5678   const int THRESHOLD_ON = 25; // upper threshold of temperature, change to your desire value (temperature to turn fan on) const int THRESHOLD_OFF = 20; // lower threshold of temperature, change to your desire value (temperature to turn fan off)

**THRESHOLD_ON**and**THRESHOLD_OFF**are constants for temperature control. The fan will turn on if the temperature is above 25°C and turn off if it drops below 20°C.

    10 11   DHTdht(DHT_PIN, DHT_TYPE); float temperature; // temperature in Celsius

- **DHT dht(DHT_PIN, DHT_TYPE);**Creates a**DHT** object using **DHT_PIN** and **DHT_TYPE**, allowing temperature readings.
- **float temperature;**Declares a variable to store temperature data.

    21222324252627282930    if(isnan(temperature)) {  Serial.println("Failed to read from DHT sensor!"); }else{ if(temperature > THRESHOLD_ON){   Serial.println("The fan is turned on");  digitalWrite(FAN_PIN, HIGH); // turn on }else if(temperature  Serial.println("The fan is turned off");   digitalWrite(FAN_PIN, LOW); // turn on }

**Error Check:**If temperature returns NaN (not a number), it indicates a failed reading, and an error message is printed.

**Fan Control:**If **temperature** is above **THRESHOLD_ON** (25°C), the fan is turned on; if it falls below **THRESHOLD_OFF** (20°C), the fan is turned off.

**Serial.println(...)**statements print whether the fan is on or off, providing real-time feedback to the Serial Monitor.

1. **[Results](http://Results)**

This project uses a DHT11 temperature sensor and a relay to control a fan based on the measured temperature. Here's what to expect:

***1. Serial Monitor Output***

The Serial Monitor will provide real-time updates based on the temperature readings and fan status.

- When the temperature is above the upper threshold (30°C), the serial monitor shows: 

*The fan is turned on*

- When the temperature is below the lower threshold (28°C), the serial monitor shows:

*The fan is turned off*

- If the temperature is between 28°C and 30°C: No change in fan state, and the Serial Monitor doesn't display any message for this.

***2. Visible Output***

The fan (connected via the relay) will:

- Turn ON when the temperature exceeds 30°C.
- Turn OFF when the temperature drops below 28°C.
- Maintain its current state if the temperature is between 28°C and 30°C to prevent rapid switching.
