Arduino Automatic Room Ventilation System
Build an Arduino-based ventilation controller that monitors room temperature and humidity and automatically switches a fan when preset limits are exceeded.
Project Design
- Measure room temperature and humidity.
- Decide when additional ventilation is needed.
- Switch a ventilation fan safely.
- Avoid unnecessary relay switching.
The final system consists of an Arduino Uno as the controller, a DHT11 for temperature and humidity measurement, a 5 V single-channel relay module, and a ventilation fan.
Keeping sensing, control, and load switching separate also makes the prototype easier to troubleshoot.
Components
- Arduino Uno
- DHT11 temperature and humidity sensor module
- 5 V single-channel relay module
- Ventilation fan
- Breadboard
- Jumper wires
- External power supply where required by the fan
- USB cable for programming the Arduino
Connecting the DHT11
- VCC → Arduino 5 V
- GND → Arduino GND
- DATA → Arduino digital pin 2
If you are using a bare DHT11 sensor instead of a breakout module, check its datasheet and wiring requirements before connecting it.
Connecting the Relay
- VCC → Arduino 5 V
- GND → Arduino GND
- IN → Arduino digital pin 8
The fan was connected through the relay's Normally Open (NO) contact so that it remains off when the relay is not energized.
Before connecting a fan, it is worth testing the relay separately. Different relay modules do not always use the same input logic.
How the Control Logic Works
- Read temperature and humidity from the DHT11.
- Compare both readings with preset limits.
- Turn the fan on if either limit is exceeded.
- Turn the fan off when the readings are below the limits.
- Wait before taking the next measurement.
- Temperature: 30 °C
- Humidity: 70% RH
Temperature > 30 °C OR Humidity > 70%
A three-second delay is used between measurements.
This is intentionally simple. The project was intended as practical room automation rather than precision environmental control.
Arduino Code
#include <DHT.h>
#define DHTPIN 2 #define DHTTYPE DHT11 #define RELAY_PIN 8
float tempThreshold = 30.0; float humidityThreshold = 70.0;
DHT dht(DHTPIN, DHTTYPE);
void setup() { Serial.begin(9600);
pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, HIGH); // Relay OFF (active-LOW)
dht.begin();
Serial.println("Automatic Ventilation System Started"); }
void loop() { float humidity = dht.readHumidity(); float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) { Serial.println("Sensor reading failed"); delay(2000); return; }
Serial.print("Temperature: "); Serial.print(temperature); Serial.print(" °C | Humidity: "); Serial.print(humidity); Serial.println(" %");
if (temperature > tempThreshold || humidity > humidityThreshold) { digitalWrite(RELAY_PIN, LOW); // Fan ON Serial.println("Fan: ON"); } else { digitalWrite(RELAY_PIN, HIGH); // Fan OFF Serial.println("Fan: OFF"); }
Serial.println("----------------------"); delay(3000); }
Testing the System
You should see temperature and humidity readings followed by the current fan state.
For example:
Temperature: 27.00 °C | Humidity: 55.00 % Fan: OFF ----------------------
Temperature: 31.00 °C | Humidity: 58.00 % Fan: ON ----------------------
For example:
float tempThreshold = 25.0;
The same test can be performed for humidity by temporarily changing humidityThreshold.
What Changed During Real-World Testing
- The DHT11 Responds Slowly
Taking readings too frequently simply produced repeated values rather than useful new information. Increasing the interval between readings made the output easier to work with and was more than adequate for room ventilation, where environmental conditions normally change slowly.
The final program therefore waits three seconds between normal readings.
- The Threshold Needed Adjustment
During testing, this caused the fan to switch more frequently than necessary. The value was eventually adjusted to 30 °C, which provided more stable behavior for the room where the prototype was tested.
Thresholds are therefore not universal values.
A bedroom, workshop, laboratory, bathroom, or equipment room may need different limits.
- Short Humidity Changes Can Trigger the Fan
Using a longer sampling interval and a sensible threshold reduced unnecessary reactions.
For a more advanced version, averaging several readings or requiring the threshold to remain exceeded for a certain period would make the controller less sensitive to short spikes.
- Relay Logic Can Be Confusing
In this project:
digitalWrite(RELAY_PIN, LOW);
digitalWrite(RELAY_PIN, HIGH);
Verifying this behavior before connecting the load prevents a surprising situation where the fan starts when you expected it to remain off.
- Frequent Switching Should Be Avoided
During the prototype tests, reducing unnecessary switching made the system quieter and reduced relay activity.
This is another reason not to sample an environmental sensor as if it were a high-speed control input.
What Could Be Improved?
The DHT11 could be replaced with a DHT22 or another more accurate environmental sensor.
An LCD or OLED display could show temperature, humidity, and fan status without requiring a connected computer.
Replacing the Arduino Uno with an ESP32 would make Wi-Fi monitoring and remote control possible.
Another useful software improvement would be hysteresis, using different thresholds for switching the fan on and off. This would reduce switching when readings remain close to the trigger point.
The project could also be expanded beyond temperature and humidity by adding sensors for CO₂ or other indoor-air-quality parameters.
Final Thoughts
The Arduino simply measures two environmental variables and makes a decision based on predefined thresholds. What made the system work reliably was not adding more code, but testing the prototype and adjusting the sampling interval, thresholds, and relay behavior to match the real environment.
It also demonstrates an important limitation of prototype sensors such as the DHT11: they are perfectly useful for basic room monitoring, but they should not be treated as precision or high-speed devices.
For a beginner, the project provides a complete introduction to sensor input, decision logic, and relay control. It can then be expanded with better sensors, displays, wireless connectivity, or more sophisticated control logic.
Source and Full Project
The complete article includes additional background, testing observations, FAQs, and discussion of possible project upgrades.
Full project: DIY Automatic Room Ventilation System with Arduino
Want to build a project?
Bring your design to life with the Elektor PCB Service, powered by Eurocircuits. Upload the project files and order professionally manufactured PCBs or assembled boards through a proven European production platform.
Supporting KiCad, Eagle, Gerber, and ODB++ formats, the service is suitable for everything from prototypes and validation builds to series production and volume manufacturing.
Made in Europe. Fast. Reliable. Professional.

Discussie (0 opmerking(en))