Arduino temperature and humidity control with fans

Photo of author

By Jackson Taylor

In today’s world, where technology plays a significant role in almost every facet of life, having precise control over environmental conditions can make a huge difference. Whether it’s for your garden, greenhouse, or even your home, maintaining optimal temperature and humidity is crucial. One of the most reliable ways to achieve this is through an Arduino-based temperature and humidity control system. This article will guide you step-by-step on how to set up a system using Arduino that can manage temperature and humidity while controlling fans to maintain the desired conditions.

What is Arduino Temperature and Humidity Control?

Arduino is an open-source electronics platform that allows users to create interactive projects. Temperature and humidity control with fans using Arduino involves programming the board to monitor and adjust the temperature and humidity levels. This is done by using sensors like the DHT11 or DHT22 and integrating fans that automatically activate when specific conditions are met.

Benefits of Arduino Temperature and Humidity Control Systems

Implementing Arduino temperature and humidity control comes with several advantages.

  1. Automation: Once set up, your system can run automatically, adjusting to changes in the environment without needing manual intervention.
  2. Efficiency: With precise control over the temperature and humidity, your systems, whether it’s a greenhouse or your home, will run more efficiently.
  3. Cost-Effective: Arduino boards are affordable, and the sensors are inexpensive, making it a budget-friendly solution for temperature and humidity control.

Setting Up the Arduino System for Temperature and Humidity Control

What You Will Need:

  1. Arduino Board (e.g., Arduino Uno or Arduino Nano)
  2. DHT11 or DHT22 Sensor (for temperature and humidity measurement)
  3. Relay Module (to control the fan)
  4. Fan (DC fan or any small fan suitable for your project)
  5. Breadboard and Jumper Wires
  6. Power Source (to power your Arduino and the fan)

Wiring the Components Together

First, you need to wire the components together:

  1. Connect the DHT11 or DHT22 sensor to the Arduino. This sensor typically has three pins: VCC, GND, and the data pin. Connect the VCC pin to 5V on the Arduino, the GND pin to the ground, and the data pin to a digital pin (e.g., Pin 7).
  2. Connect the relay module to the Arduino. The relay typically has three pins: IN (input pin), VCC, and GND. Connect VCC to 5V, GND to ground, and the IN pin to another digital pin (e.g., Pin 8).
  3. Attach the fan to the relay output. The relay will act as a switch, allowing the Arduino to control the fan’s power.
See also
Arduino self-driving car with remote control

Programming the Arduino for Temperature and Humidity Control

Once everything is wired up, it’s time to program the Arduino. This is where you’ll write code that reads the temperature and humidity from the DHT sensor and turns the fan on or off based on certain thresholds.

cpp
#include <DHT.h>

#define DHTPIN 7 // Pin where the DHT sensor is connected
#define DHTTYPE DHT11 // Type of the DHT sensor
#define FANPIN 8 // Pin where the relay is connected to control the fan

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
pinMode(FANPIN, OUTPUT);
}

void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Temperature: ");
Serial.print(t);
Serial.print("°C Humidity: ");
Serial.print(h);
Serial.println("%");

if (t > 30 || h > 70) {
digitalWrite(FANPIN, HIGH); // Turn the fan ON
Serial.println("Fan ON");
} else {
digitalWrite(FANPIN, LOW); // Turn the fan OFF
Serial.println("Fan OFF");
}

delay(2000); // Delay for 2 seconds
}

This code reads the temperature and humidity from the DHT sensor. If the temperature exceeds 30°C or the humidity exceeds 70%, the fan will turn on. If both conditions are below those thresholds, the fan will turn off.

Fine-Tuning the System for Optimal Control

Adjusting Temperature and Humidity Thresholds

In the code above, the fan is controlled based on simple temperature and humidity thresholds. You can adjust these values according to your specific needs. For example, if you’re controlling the environment in a greenhouse, you might want to adjust the temperature threshold to 25°C, and the humidity threshold to 60% for optimal plant growth.

Adding More Sensors for Better Accuracy

While the DHT11 and DHT22 sensors are affordable and relatively accurate, you can improve your setup by using more advanced sensors like the SHT31, which offers better precision. This is especially important if you are working with more sensitive environments, such as laboratories or data centers.

Integrating More Fans for Larger Areas

If you are controlling a larger space, you may need more than one fan. You can use additional relay modules and Arduino pins to control multiple fans, or even set up a more advanced system using a motor driver to control fan speed based on temperature and humidity levels.

Troubleshooting Common Issues

  1. Fan Not Turning On/Off: Double-check your wiring. Ensure the relay is correctly connected and that the Arduino is sending the signal to the fan.
  2. Sensor Failures: If you’re getting incorrect readings from the DHT sensor, check the connections. You can also try recalibrating or replacing the sensor.
  3. Temperature Fluctuations: If the temperature readings are fluctuating too much, try adding a capacitor near the sensor to stabilize the readings.

Enhancing the System with Cloud Integration

Using Wi-Fi with Arduino for Remote Monitoring

To make your system more powerful, consider integrating Wi-Fi capabilities using an ESP8266 or ESP32 board. With this setup, you can monitor and control the temperature and humidity remotely through your smartphone or computer.

Cloud Platforms for Real-Time Data Access

By uploading your data to platforms like Blynk or ThingSpeak, you can access real-time temperature and humidity data. These platforms also allow you to set up alerts and notifications for when conditions go beyond your set parameters.

Conclusion

Arduino-based temperature and humidity control systems offer a low-cost, customizable, and reliable solution for automating environmental management. By following the steps outlined in this article, you can set up your own system to control fans and maintain the perfect conditions for your needs. Whether you are a hobbyist, a gardener, or someone looking to automate your home, this DIY project is a great way to explore the world of Arduino and smart technology.