Back to Home

Greenhouse Automation on ESP32: Sensors and Hidden Pins

Practical Guide to Creating a Home Greenhouse Monitoring System on ESP32. Describes Typical Errors, Including ADC2 and Wi-Fi Conflict, Sensor Calibration Methods, and Data Visualization Techniques.

ESP32 as Your Personal Agronomist: Secrets of Stable Operation
Advertisement 728x90

# ESP32 as an Agronomist: Automating a Windowsill Farm Accounting for the Chip's Hidden Quirks

The ESP32, costing just 500 rubles, became the central element of the monitoring and control system for a windowsill micro-greenhouse. The key task—replace human guesses with objective sensor data to ensure optimal growing conditions for strawberries, basil, lettuce, and peppers. Initial experiments showed: without measurements, it's easy to overwater, skimp on light, or miss nighttime temperature stress. The solution—continuous collection of data on soil moisture, light levels, temperature, and air humidity.

System Architecture: Sensors, Microcontroller, Cloud

The system is built around the ESP32 DevKit V1. The choice was driven by three factors: low cost, built-in Wi-Fi support, and availability of analog inputs. Four main sensors are connected:

  • FC-28—measures soil resistance, indirectly indicating moisture levels.
  • BH1750—digital light sensor that outputs values in lux.
  • DHT22—tracks air temperature and relative humidity.
  • Photoresistor—analog sensor for backup light intensity monitoring.

Data is read every 5 seconds and output to the Serial Monitor for initial debugging. Initial measurements revealed critical issues: nighttime temperature drops to 18°C during ventilation, insufficient lighting (just 3000–4500 lux instead of the required 8000+), and uneven watering. After adjustments—moving pots closer to the window, adding a second lamp, tweaking the watering schedule—yield subjectively increased by 40%.

Google AdInline article slot

Cloud Storage Integration and Visualization

Local monitoring via Serial Monitor quickly becomes inconvenient. For long-term analysis, data is sent to a personal server via HTTP GET requests. Example request:

/sensorData.php?login=eug&sensor_id=1&val=1842&json=1

On the server side, a PHP script saves the values to a database. This enables time-series graphs: soil moisture dynamics after watering, daily temperature fluctuations, and stability of light output from grow lamps. Visualization turns raw numbers into clear trends—for example, soil moisture drops from 2100 mV to 800 mV three days after watering, signaling the need for another cycle.

Hidden Pitfall: ADC2 and Wi-Fi Conflict

After enabling Wi-Fi, the system suddenly stopped transmitting data from analog sensors. ADC values went to zero, even though wiring and code were unchanged. The cause—using GPIO2, which belongs to ADC2. In the ESP32 architecture, the radio module (Wi-Fi/Bluetooth) uses ADC2 for internal calibration and blocks it for user applications. The fix—switch to ADC1 pins, which operate independently of the wireless interface.

Google AdInline article slot

Safe pins for analog sensors with Wi-Fi active:

  • GPIO32, GPIO33, GPIO34, GPIO35, GPIO36 (VP), GPIO39 (VN)

Dangerous pins (ADC2):

  • GPIO0, GPIO2, GPIO4, GPIO12, GPIO13, GPIO14, GPIO15, GPIO25, GPIO26, GPIO27

The fix took a minute: changing const int analogPin = 2; to const int analogPin = 34; and rewiring the connection. The system worked immediately.

Google AdInline article slot

Practical Tips for Reliable Operation

For the system to run stably for months, follow these rules:

  • Sensor Calibration. For the FC-28, measure output voltage in two extremes: bone-dry soil (~800 mV) and water-saturated (~2200 mV). Normal is around 1500 mV.
  • Moisture Protection. The ESP32 is sensitive to condensation. Seal all connections in a waterproof box or pot them in hot glue.
  • External Power. A laptop USB port often can't handle peak draw from the Wi-Fi module and pump. Use a 5V/2A power supply.
  • Local Data Storage. Don't lose data during server outages. Implement buffering via SPIFFS or LittleFS, then send in batches.
  • Notifications. Set up a Telegram bot or email alerts for parameters going out of bounds (e.g., soil moisture < 1000 mV).

Philosophy and Results: Technology as Servant, Not Master

In three months of operation, the first cherry tomatoes were harvested, lettuce is cut regularly, basil grows "like a weed," and peppers are gearing up to flower. The key takeaway—technology doesn't replace understanding nature; it enhances it. Data reduces guesswork: no more wondering when to water or turn on the lights. That said, even with perfect sensor readings, plants can act unpredictably—a reminder that biology is more complex than any algorithm.

What's Important

  • ESP32 isn't just an Arduino replacement—it's a full IoT node with Wi-Fi and Bluetooth.
  • ADC2 pins (GPIO0, 2, 4, 12–15, 25–27) are unusable with Wi-Fi active.
  • Sensor calibration is mandatory—factory values don't account for your soil.
  • Local data storage is critical for resilience.
  • Notifications via Telegram or email make management more convenient.

Total project budget—around 900 rubles. Components are available on AliExpress and local electronics shops. The system is scalable: add pump control via relay, Home Assistant integration, or compare data with other smart farms to find optimal settings.

— Editorial Team

Advertisement 728x90

Read Next