Mushroom farm automation using CO2, humidity, and light control creates the precise environmental conditions required for profitable mushroom cultivation in India. Oyster, button, and shiitake mushrooms require tight control of CO2 (below 1000 ppm), humidity (85-95%), temperature (15-28 degrees C), and photoperiod — parameters that are difficult and labour-intensive to manage manually. This guide covers building a complete automated mushroom growing chamber controller with ESP32.
Table of Contents
- Indian Mushroom Market and Opportunity
- Critical Growing Parameters by Species
- Components Required
- Circuit and Wiring
- ESP32 Mushroom Controller Code
- Fruiting Stage Automation
- Indian Mushroom Cultivation Context
- Frequently Asked Questions
Indian Mushroom Market and Opportunity
India’s mushroom production has grown from 0.04 million tonnes (2000) to 0.13 million tonnes (2022), with the market valued at Rs 1,200 crore and growing at 15% annually. Key growth drivers:
- Rising middle-class health consciousness (mushrooms as protein-rich, low-calorie food)
- Export demand for button and exotic mushrooms (EU, Middle East)
- Low land requirement: 100 square feet produces Rs 8,000-12,000/month in oyster mushrooms
- NABARD and state government subsidies for mushroom cultivation units
Inconsistent environmental control is the primary reason for crop failure — automation is the key to profitability at scale.
Critical Growing Parameters by Species
| Species | Temp (degrees C) | Humidity (%) | CO2 (ppm) | Light |
|---|---|---|---|---|
| Oyster (Pleurotus) | 18-28 | 85-95 | Below 1000 | 12h/day (indirect) |
| Button (Agaricus) | 14-18 | 80-90 | Below 800 | Darkness preferred |
| Shiitake | 10-25 | 80-95 | Below 1500 | 8-12h/day |
| Milky (Calocybe) | 25-35 | 80-90 | Below 1200 | 12h/day |
Components Required
Environmental Sensors from Zbotic
- GY-BME280 3.3V Temperature, Humidity, Pressure Sensor — for growing room climate monitoring
- 5V/12V Relay Control Module — for controlling humidifier, fan, heater, and lights
Full system components:
- ESP32 development board
- BME280 temperature and humidity sensor (more accurate than DHT22 for tight humidity control)
- MHZ-19B CO2 sensor (NDIR, essential for monitoring ventilation)
- 4-channel relay module (5V)
- Ultrasonic mist maker (12V, 5-disc for larger rooms)
- AC axial fan (ventilation, 230V)
- LED grow light panel (12V, 10W, 3000-4000K spectrum)
- Optional: PTC heater for winter temperature maintenance
- DS3231 RTC module (for light cycle timing)
- OLED 128×64 display
Circuit and Wiring
Connections:
- BME280 SDA -> GPIO21, SCL -> GPIO22
- MHZ-19B TX -> GPIO16 (RX2), RX -> GPIO17 (TX2)
- DS3231 SDA -> GPIO21, SCL -> GPIO22 (I2C shared)
- Relay IN1 -> GPIO26 (mist maker/humidifier)
- Relay IN2 -> GPIO27 (ventilation fan)
- Relay IN3 -> GPIO25 (LED grow light)
- Relay IN4 -> GPIO33 (heater, if used)
- OLED SDA -> GPIO21, SCL -> GPIO22
ESP32 Mushroom Controller Code
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
#include <HardwareSerial.h>
#include <RTClib.h>
Adafruit_BME280 bme;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
HardwareSerial co2Serial(2);
RTC_DS3231 rtc;
#define MIST_RELAY 26
#define FAN_RELAY 27
#define LIGHT_RELAY 25
#define HEAT_RELAY 33
// Mushroom profile: Oyster
const float TEMP_MIN = 20.0;
const float TEMP_MAX = 26.0;
const float HUMID_MIN = 87.0;
const float HUMID_MAX = 95.0;
const int CO2_MAX = 1000; // ppm
const int LIGHT_ON_HOUR = 7;
const int LIGHT_OFF_HOUR = 19;
int readCO2() {
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
co2Serial.write(cmd, 9);
delay(500);
if (co2Serial.available() >= 9) {
byte r[9];
co2Serial.readBytes(r, 9);
if (r[0] == 0xFF && r[1] == 0x86) return (r[2] << 8) | r[3];
}
return -1;
}
void updateOLED(float temp, float humid, int co2) {
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0, 0); oled.print("Mushroom Controller");
oled.setCursor(0, 12); oled.print("Temp: "); oled.print(temp, 1); oled.print("C");
oled.setCursor(0, 22); oled.print("RH: "); oled.print(humid, 0); oled.print("%");
oled.setCursor(0, 32); oled.print("CO2: "); oled.print(co2); oled.print(" ppm");
bool fanOn = !digitalRead(FAN_RELAY);
bool mistOn = !digitalRead(MIST_RELAY);
oled.setCursor(0, 44);
oled.print("Fan:"); oled.print(fanOn ? "ON " : "off");
oled.print(" Mist:"); oled.print(mistOn ? "ON" : "of");
oled.display();
}
void setup() {
Serial.begin(115200);
co2Serial.begin(9600, SERIAL_8N1, 16, 17);
Wire.begin(21, 22);
bme.begin(0x76);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
rtc.begin();
for (int p : {MIST_RELAY, FAN_RELAY, LIGHT_RELAY, HEAT_RELAY}) {
pinMode(p, OUTPUT);
digitalWrite(p, HIGH); // All off
}
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0, 20);
oled.print("Mushroom Farm Auto");
oled.display();
delay(2000);
}
void loop() {
float temp = bme.readTemperature();
float humid = bme.readHumidity();
int co2 = readCO2();
DateTime now = rtc.now();
// Humidity control
if (humid < HUMID_MIN) {
digitalWrite(MIST_RELAY, LOW); // Mist ON
} else if (humid > HUMID_MAX) {
digitalWrite(MIST_RELAY, HIGH); // Mist OFF
}
// CO2 and ventilation control
if (co2 > 0 && co2 > CO2_MAX) {
digitalWrite(FAN_RELAY, LOW); // Fan ON
} else if (co2 > 0 && co2 < CO2_MAX - 200) {
// Only turn off fan if humidity is maintained
if (humid < HUMID_MAX) {
digitalWrite(FAN_RELAY, HIGH); // Fan OFF
}
}
// Temperature control
if (temp < TEMP_MIN) {
digitalWrite(HEAT_RELAY, LOW); // Heater ON
} else if (temp > TEMP_MAX) {
digitalWrite(HEAT_RELAY, HIGH); // Heater OFF (and fan helps cool)
if (temp > TEMP_MAX + 2) digitalWrite(FAN_RELAY, LOW); // Extra cooling
}
// Light cycle based on RTC
int hr = now.hour();
if (hr >= LIGHT_ON_HOUR && hr < LIGHT_OFF_HOUR) {
digitalWrite(LIGHT_RELAY, LOW); // Light ON
} else {
digitalWrite(LIGHT_RELAY, HIGH); // Light OFF
}
updateOLED(temp, humid, co2);
Serial.printf("T:%.1f H:%.0f%% CO2:%d ppm | Mist:%s Fan:%s Light:%sn",
temp, humid, co2,
!digitalRead(MIST_RELAY) ? "ON" : "off",
!digitalRead(FAN_RELAY) ? "ON" : "off",
!digitalRead(LIGHT_RELAY) ? "ON" : "off");
delay(30000); // Check every 30 seconds
}
Fruiting Stage Automation
Mushroom growth has distinct stages requiring different conditions:
- Spawn run / colonisation (7-21 days): High CO2 (1500-2000 ppm acceptable), 90-95% RH, no light needed, 22-25 degrees C. Misting only, no ventilation (CO2 promotes mycelium growth).
- Pinning initiation: Drop CO2 below 800 ppm (increase ventilation), maintain 90% RH, add 12h light cycle, drop temp by 2-3 degrees C.
- Fruiting / maturation: CO2 below 1000 ppm, 85-92% RH, full 12h light, harvest before veil breaks.
Automate stage transitions using RTC-timed profiles stored in ESP32 EEPROM — farmer inputs spawn date, system automatically transitions between stages.
Indian Mushroom Cultivation Context
- Oyster mushrooms (North India, up to 28 degrees C): Most suitable species for Indian plains — tolerates higher temperatures, grows on wheat straw (abundant and cheap)
- Milky mushroom (South India, Tamil Nadu, Andhra Pradesh): Tropical species, thrives at 28-35 degrees C, ideal for summer cultivation
- Button mushrooms (Himachal Pradesh, cooler regions): Requires 14-18 degrees C — natural conditions in hills reduce heating costs dramatically
- Shiitake (export market): Higher value (Rs 400-600/kg fresh), requires oak/hardwood substrate, growing in Uttarakhand and Himachal
Frequently Asked Questions
What is the most critical parameter for oyster mushroom yield in India?
Humidity is most critical — drops below 80% cause pinheads to abort and caps to crack. The second most critical is CO2: above 1200 ppm produces elongated, trumpet-shaped mushrooms with small caps, reducing market value significantly. Proper ventilation scheduling is the key automation challenge.
Can I use a household humidifier instead of an ultrasonic mist maker?
Household humidifiers (evaporative or warm-mist types) are less efficient and don’t produce fine enough droplets for mushroom cultivation. Use 16mm or 20mm ultrasonic mist maker discs (available for Rs 150-300) driven by a 12V power supply, controlled by the relay module. Replace disc annually.
How do I prevent contamination from high humidity conditions?
Sanitise growing room with 2% bleach solution between batches. Add air filtration (HEPA filter on ventilation inlet). Ensure water used for misting has chlorine residual below 0.5 ppm (beneficial bacteria are also harmed by chlorine). Keep humidity cycles cycling (not constant misting) to allow surface drying.
Is mushroom cultivation viable in small urban spaces in Indian cities?
Very viable. A 200 square feet room in Mumbai, Bangalore, or Delhi can produce 200-400 kg of oyster mushrooms per month, generating Rs 40,000-80,000 revenue at local restaurant/retail rates of Rs 150-250/kg. The ESP32 automation system prevents the need for constant manual monitoring — critical for urban farmers with day jobs.
Add comment