Temperature and Humidity Control System Using Arduino

by BeholderABC in Circuits > Arduino

38 Views, 0 Favorites, 0 Comments

Temperature and Humidity Control System Using Arduino

FNZRH3GLXHK5E8K.jpg
F7NYBV7LXHK5EC4.jpg

This project details the design and implementation of a temperature and humidity control system using Arduino. The system is designed to monitor and regulate the environment using a DHT11 temperature and humidity sensor, a 4x4 membrane keypad, a 128x64 pixel OLED display, a heater, and a fan. This system can be applied in various fields such as agricultural greenhouses, indoor climate control, and server room monitoring.

Supplies

14d1217c21c93e938d53454a7a2fcec.jpg

- Arduino UNO R3: The microcontroller board used for controlling all operations.

- DHT11: Temperature and Humidity Sensor: Used to measure the ambient temperature and humidity.

- 4x4 Membrane Keypad: Allows user input to set desired temperature and humidity levels.

- 128x64 Pixel OLED Display: Displays the sensor readings and user-set parameters.

- Heater: Used to increase the temperature when it falls below the desired level.

- Fan: Used to decrease the temperature or humidity when they exceed the desired levels.

- Enclosure: To house all the components securely.

- Bread Board: To connect the Hardwares

Hardware Connections

F7LEE6MLXHK5E9A.jpg

1.1 Connecting the DHT11 Sensor

- Connect the VCC pin of the DHT11 sensor to the 5V pin on the Arduino.

- Connect the GND pin to the GND on the Arduino.

- Connect the data pin to a digital pin on the Arduino (e.g., D12).

1.2 Connecting the 4x4 Membrane Keypad

- Connect the keypad to the Arduino using digital pins. Each row and column of the keypad should be connected to a different digital pin on the Arduino.

1.3 Connecting the OLED Display

- Connect the VCC and GND pins of the OLED display to the 5V and GND pins on the Arduino, respectively.

- Connect the SCL and SDA pins of the OLED to the corresponding SCL and SDA pins on the Arduino (A5 and A4 on the UNO).

1.4 Connecting the Heater and Fan

- Connect the heater and fan to digital pins on the Arduino (e.g., D10 for the heater and D11 for the fan) through appropriate transistors or relays to control them safely.

Programming

2. Programming

2.1 Setting Up the Arduino IDE

- Download and install the Arduino IDE.

- Connect the Arduino UNO to the computer and select the correct port and board model.

2.2 Libraries Required

- Install the necessary libraries for the DHT11 sensor and the OLED display. This can be done via the Arduino IDE's library manager.


#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>

#define DHTPIN 12    
#define DHTTYPE DHT11 

DHT dht(DHTPIN, DHTTYPE);

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int setTemperature = 25;
int setHumidity = 50;
int heaterPin = 10;
int fanPin = 11;

void setup() {
  pinMode(heaterPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  Serial.begin(9600);
  dht.begin();
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
}

void loop() {
  char key = keypad.getKey();
  if (key){
    if (key == 'A') {
      int temp = 0;
      key = 0;
      while(key != '#'){
        temp = (10 * temp) + (key -'0');
        key = keypad.getKey();
      }
      setTemperature = temp;
    }
    else if(key == 'B'){
      int temp = 0;
      key = 0;
      while(key != '#'){
        temp = (10 * temp) + (key -'0');
        key = keypad.getKey();
      }
      setHumidity = temp;
    }
    else if (key = '*'){
      setTemperature = 25;
      setHumidity = 50;
    }
  }
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  display.clearDisplay();
  display.setCursor(0,0);
  display.print("Temp: "); display.print(t); display.print(" C");
  display.setCursor(0,10);
  display.print("Humid: "); display.print(h); display.print(" %");
  display.setCursor(0,20);
  display.print("Set Temp: "); display.print(setTemperature); display.print(" C");
  display.setCursor(0,30);
  display.print("Set Humid: "); display.print(setHumidity); display.print(" %");
  display.display();
  if(t < setTemperature) {
    digitalWrite(heaterPin, HIGH);
  } else {
    digitalWrite(heaterPin, LOW);
  }
  if(h > setHumidity) {
    digitalWrite(fanPin, HIGH);
  } else {
    digitalWrite(fanPin, LOW);
  }
  delay(20);
}

Uploading the Code to the Board

connect the Arduino UNO board to the computer and upload the code to the Arduino UNO board.

Testing and Calibration

- Use the keypad to input the desired temperature and humidity levels.

  • Press 'A' to input the desired temperature
  • Press 'B' to input thedesired humidity.
  • Press '#' to finish input.
  • Press '*' to clear any input and reset the desired temperature and humidity levels to default value.

- Observe the OLED display for real-time temperature and humidity readings.

- Ensure the heater and fan operate correctly based on the set parameters.