Back to All Blog Posts
Tutorial EltroNerd Engineering

Smart Greenhouse Climate Controller

Smart Greenhouse Climate Controller using ESP32, BME280, DHT22, and soil moisture sensor. This is a great IoT project for students to learn environmental monitoring and automation.

Smart Greenhouse Climate Controller using ESP32

Managing a greenhouse requires monitoring temperature, humidity, and soil moisture to ensure plants grow optimally.
In this project, we will build a smart greenhouse controller using ESP32, BME280, DHT22, and a soil moisture sensor, with the ability to control devices like fans, water pumps, and heaters automatically.


🛠️ Hardware Requirements

  • ESP32 Development Board
  • BME280 Sensor (temperature, humidity, pressure)
  • DHT22 Sensor (temperature & humidity backup)
  • Soil Moisture Sensor
  • Relay Modules (to control fan, water pump, or heater)
  • Jumper wires, breadboard, and USB cable
  • Power supply for ESP32 and relay module

⚡ Working Principle

  1. Sensors Monitoring:

    • BME280 measures temperature, humidity, and atmospheric pressure.
    • DHT22 provides backup humidity and temperature readings.
    • Soil moisture sensor checks water content of the soil.
  2. Decision Making:

    • ESP32 reads all sensor data.
    • Based on thresholds, it can:
      • Turn on/off fans to regulate temperature/humidity.
      • Activate water pump if soil is too dry.
      • Trigger heater or misting system for climate control.
  3. Remote Monitoring:

    • Data can be sent to Wi-Fi dashboard or MQTT broker.
    • Users can monitor and control the greenhouse remotely.

💻 Arduino Code Example

This example uses Adafruit BME280 and DHT library.

c
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <DHT.h>

#define DHTPIN 15
#define DHTTYPE DHT22
#define MOISTURE_PIN 34
#define FAN_RELAY 23
#define PUMP_RELAY 22

DHT dht(DHTPIN, DHTTYPE);
Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);

  pinMode(FAN_RELAY, OUTPUT);
  pinMode(PUMP_RELAY, OUTPUT);
  digitalWrite(FAN_RELAY, LOW);
  digitalWrite(PUMP_RELAY, LOW);

  dht.begin();
  if (!bme.begin(0x76)) {
    Serial.println("BME280 not found!");
    while (1);
  }

  Serial.println("Smart Greenhouse Controller Ready!");
}

void loop() {
  // Read sensors
  float temp_bme = bme.readTemperature();
  float hum_bme = bme.readHumidity();
  float temp_dht = dht.readTemperature();
  float hum_dht = dht.readHumidity();
  int soilMoisture = analogRead(MOISTURE_PIN);

  Serial.printf("Temp(BME): %.2f °C, Hum(BME): %.2f %%\n", temp_bme, hum_bme);
  Serial.printf("Temp(DHT): %.2f °C, Hum(DHT): %.2f %%\n", temp_dht, hum_dht);
  Serial.printf("Soil Moisture: %d\n", soilMoisture);

  // Climate control logic
  if (temp_bme > 30.0) digitalWrite(FAN_RELAY, HIGH); // turn on fan
  else digitalWrite(FAN_RELAY, LOW);

  if (soilMoisture < 1000) digitalWrite(PUMP_RELAY, HIGH); // water plants
  else digitalWrite(PUMP_RELAY, LOW);

  delay(5000); // 5 seconds loop
}

How to Use

Connect the BME280 to ESP32:

  • VCC → 3.3V

  • GND → GND

  • SDA → GPIO21

  • SCL → GPIO22

Connect DHT22 to GPIO15. Connect soil moisture sensor analog output to GPIO34. Connect relay modules to ESP32 GPIO pins controlling fan/pump/heater.

Upload the code to ESP32 and open Serial Monitor.

Try this project in your browser

Compile code and simulate hardware output with EltroNerd Cloud IDE.

Launch Cloud IDE