Version 1.8.0 - Production Ready

ESP32 Smart Farming System

Revolutionary setup system with production-ready optimization

Automated irrigation with IoT connectivity and modular design

What's New in Version 1.8.0

Revolutionary improvements that make smart farming accessible to everyone

30-Second Setup

Choose from 5 pre-configured options for instant deployment

50% Smaller Code

Production-optimized firmware with debug cleanup

Visual Pin Guide

ESP32 pinout diagram with connection examples

Enterprise Ready

Advanced error handling and production deployment guides

Quick Start Guide

1. Test Hardware

Run the hardware test code to verify all connections and components are working properly.

2. Revolutionary Setup

Choose from 5 pre-configured setup types - complete configuration in just 30 seconds!

3. Detailed Configuration

Use our dedicated configuration guides for comprehensive setup options

4. Upload Code

Choose between offline or online version and upload to your ESP32.

Project Overview

Key Features

Automated Irrigation

Intelligent watering based on soil moisture levels with configurable thresholds.

Light Level Monitoring

Optional LDR sensor for ambient light detection with configurable thresholds for day/night cycles.

IoT Connectivity

WiFi connectivity with dual cloud service integration (ThingSpeak & Adafruit IO).

Safety Mechanisms

Watchdog timer, emergency stop, and pump runtime protection.

Modular Design

Flexible display options and configurable sensor combinations.

Project Structure

smart_farming/
├── MainCode/                    # Main smart farming system
│   ├── offline/                     # Offline version (standalone)
│   │   ├── offline.ino              # Main offline sketch
│   │   ├── config.h                 # Offline configuration
│   │   └── README.md                # Offline documentation
│   ├── online/                      # Online version (IoT with cloud)
│   │   ├── online.ino               # Main online sketch
│   │   ├── config.h                 # Online configuration
│   │   └── README.md                # Online documentation
│   └── README.md                    # Main code documentation
├── TestCode/                    # Testing and validation
│   ├── hardware/                    # Hardware testing
│   │   ├── hardware_test.ino        # Comprehensive hardware test
│   │   └── README.md                # Hardware test documentation
│   ├── communication/               # Communication testing
│   │   ├── communication.ino        # Communication test suite
│   │   └── README.md                # Communication test documentation
│   └── README.md                    # Test code documentation
├── docs/                        # Web documentation
│   ├── index.html               # Main documentation page
│   ├── styles.css               # Custom CSS styles
│   ├── script.js                # Interactive JavaScript
│   └── README.md                # Documentation guide
├── configuration.md            # Comprehensive configuration guide
├── wiring_diagram.md           # Wiring instructions with Mermaid
├── libraries.txt              # Required Arduino libraries
├── LICENSE                     # MIT License
└── README.md                  # Main documentation

Revolutionary Features (v1.8.0)

Game-changing innovations that make smart farming accessible to everyone

DHT Auto-Disable System

Automatically disables faulty DHT sensors and performs periodic health checks for automatic recovery

  • • Smart sensor management
  • • Periodic health checks
  • • Automatic recovery
  • • Graceful degradation

WiFi Fallback with AP Mode

Creates local WiFi network when internet fails, ensuring continuous control

  • • Bulletproof connectivity
  • • Local WiFi network
  • • Visual status indicators
  • • Configurable AP settings

EEPROM Persistence

Saves critical settings and state across power failures and reboots

  • • Power failure protection
  • • State recovery
  • • Data integrity validation
  • • Automatic saving

Enhanced Error Handling

Advanced sensor validation, automatic recovery, and comprehensive error logging

  • • Advanced validation
  • • Automatic recovery
  • • Comprehensive logging
  • • System health monitoring

Smart Status Monitoring

Real-time system health monitoring with detailed status indicators

  • • Real-time status
  • • Operating mode display
  • • Network diagnostics
  • • Performance metrics

Network Reliability

Bulletproof WiFi reconnection and cloud service recovery

  • • Enhanced reconnection
  • • Cloud service recovery
  • • Network diagnostics
  • • Graceful degradation

Hardware Requirements

Essential Components

ESP32 Development Board

ESP32-WROOM-32 or similar

Main controller with WiFi and ADC support

Soil Moisture Sensor

Analog capacitive sensor

0-3.3V output range

Relay Module

5V SPDT relay

Pump control with current handling

Water Pump

12V DC submersible

Irrigation system

Power Supply

5V/3.3V adapter

Minimum 2A capacity

Optional Components

DHT Sensor

DHT11 or DHT22

LDR Sensor

Light Dependent Resistor

LCD Display

1602 or 2004 I2C

LEDs

Status indicators

Rotary Encoder

Menu control

Emergency Stop

Safety button

ESP32 Development Board Pinout

Official ESP32 development board pinout diagram for easy hardware connections:

ESP32 Development Board Pinout

ESP32 Development Board - Pin Configuration

Essential Connections

Soil Moisture GPIO 36
Relay Control GPIO 19
LCD SDA GPIO 21
LCD SCL GPIO 22

Optional Connections

DHT Sensor GPIO 5
LDR Sensor GPIO 39
Green LED GPIO 18
Red LED GPIO 23
Blue LED GPIO 2

Software Features

Offline Version

  • Local operation without internet
  • Configurable serial output for monitoring
  • LED status indicators
  • Automatic irrigation control
  • Fail-safe mechanisms

Online Version

  • WiFi connectivity
  • Cloud data logging
  • Web interface
  • OTA firmware updates
  • JSON API for integration

Configuration Options

Display Options

  • LCD 1602 (16x2)
  • LCD 2004 (20x4)
  • Headless (Serial only)

Control Options

  • Rotary Encoder
  • Potentiometer
  • Automated Only

Sensor Options

  • DHT11
  • DHT22
  • LDR Sensor
  • None (Soil only)

Serial Output Configuration

Configuration

// Serial Output Settings
#define SERIAL_OUTPUT_ENABLED true        // Enable/disable serial output
#define SERIAL_BAUD_RATE 115200           // Serial communication speed

Use Cases

Development & Testing

Full debugging output with detailed status messages

Production Deployment

No serial output for optimal performance

Remote Monitoring

Essential serial output for remote debugging

Performance Impact

When Enabled
  • • ~2-5% CPU overhead
  • • ~1-2KB additional memory
  • • Comprehensive status messages
  • • Real-time sensor data
When Disabled
  • • No serial overhead
  • • Optimal performance
  • • Reduced memory usage
  • • Production ready

Configuration Reference

Comprehensive guide to all configuration parameters available in config.h files for both offline and online versions.

Serial Communication Settings
Serial Output Enabled true
Serial Baud Rate 115200
Description:

Controls serial communication output for debugging and monitoring. When enabled, provides detailed system status and sensor readings via serial port.

Display Configuration
Display Type DISPLAY_LCD_1602
LCD I2C Address 0x27
Description:

Configures the display type and I2C address for the LCD screen. Supports various LCD sizes and I2C addresses.

Control Configuration
Control Type CONTROL_ROTARY_ENCODER
Rotary Encoder CLK Pin 18
Rotary Encoder DT Pin 19
Rotary Encoder SW Pin 21
Description:

Configures manual control interface. Supports rotary encoder for menu navigation and system control.

Sensor Configuration
DHT Sensor Type DHT22
DHT Pin 4
Soil Moisture Pin 34
LDR Pin 39
Description:

Configures sensor pins and types for temperature, humidity, soil moisture, and light detection.

Actuator Configuration
Pump Pin 2
LED Red Pin 5
LED Green Pin 17
LED Blue Pin 16
Description:

Configures actuator pins for water pump and status LED indicators.

IoT Services Configuration
IoT Services Enabled true
Web UI Only Mode false
ThingSpeak Enabled true
Adafruit IO Enabled true
Description:

Controls IoT cloud services integration. Can disable individual services or all services for web UI only mode.

Threshold Configuration
Soil Moisture Threshold 30%
Temperature Threshold 35°C
Humidity Threshold 20%
Light Threshold 500 lux
Description:

Sets threshold values for automatic irrigation and system alerts based on sensor readings.

Timing Configuration
Irrigation Duration 5000ms
Sensor Read Interval 1000ms
Display Update Interval 2000ms
Watchdog Timeout 30s
Description:

Configures timing intervals for system operations, sensor readings, and display updates.

Setup Guide

1

Hardware Assembly

Connect all sensors, actuators, and display components according to the wiring diagram.

TestCode/hardware/hardware_test.ino
2

Communication Testing

Test WiFi and cloud connectivity (for online version only).

TestCode/communication/communication.ino
3

Software Installation

Install Arduino IDE and required libraries for the smart farming system.

Arduino IDE 2.0+ | ESP32 Board Package | Required Libraries
4

Configuration Setup

Configure system parameters according to your hardware setup and requirements.

MainCode/offline/config.h # For offline version
MainCode/online/config.h # For online version

Quick Configuration Examples

Development Setup
// Enable serial output
#define SERIAL_OUTPUT_ENABLED true
#define SERIAL_BAUD_RATE 115200

// Enable display and control
#define DISPLAY_TYPE DISPLAY_LCD_1602
#define CONTROL_TYPE CONTROL_ROTARY_ENCODER

// Fast intervals for testing
#define SENSOR_READ_INTERVAL 1000
#define DISPLAY_UPDATE_INTERVAL 2000
Production Setup
// Disable serial for production
#define SERIAL_OUTPUT_ENABLED false

// Headless operation
#define DISPLAY_TYPE DISPLAY_NONE
#define CONTROL_TYPE CONTROL_NONE

// Longer intervals for efficiency
#define SENSOR_READ_INTERVAL 2000
#define DISPLAY_UPDATE_INTERVAL 3000
5

Code Upload

Upload the appropriate sketch to your ESP32 board.

MainCode/offline/offline.ino # For offline version
MainCode/online/online.ino # For online version
6

System Testing

Test all system functions including sensors, actuators, and connectivity.

TestCode/system/system_test.ino
7

Monitor System

Use configurable serial output or web interface to monitor system operation.

Serial Monitor (if enabled) | Web Interface (online version)

💡 Tip: Disable serial output in production for better performance and power efficiency.

Troubleshooting

Common Issues

Sensor Not Reading

Check wiring connections and pin assignments in config.h

Display Not Working

Verify I2C address and display type configuration

WiFi Connection Failed

Check credentials and network availability

Performance Tips

Optimize Intervals

Adjust sensor reading and display update intervals for your needs

Disable Unused Features

Turn off serial output and unused sensors in production

Monitor Memory Usage

Use web interface to monitor system performance and memory

Setup Guide

1

Hardware Testing

Start by running the hardware test code to verify all connections and components.

TestCode/hardware/hardware_test.ino
2

Communication Testing

Test WiFi and cloud connectivity (for online version only).

TestCode/communication/communication.ino
3

Install Libraries

Install all required libraries via Arduino IDE Library Manager.

See libraries.txt for complete list
4

Open Project in Arduino IDE

Open the appropriate sketch file for your chosen version.

MainCode/offline/offline.ino # For offline version
MainCode/online/online.ino # For online version
TestCode/hardware/hardware_test.ino # For hardware testing
TestCode/communication/communication.ino # For communication testing
5

Configure System

Edit the configuration file to match your hardware setup and requirements.

MainCode/offline/config.h # For offline version
MainCode/online/config.h # For online version

Configuration Examples (Based on Actual Code)

These examples are taken directly from the actual config.h files and can be copied to your configuration.

1. Basic Offline Setup
// Basic offline configuration - Copy to MainCode/offline/config.h

// Display Configuration
#define DISPLAY_TYPE DISPLAY_LCD_1602
#define LCD_ADDRESS 0x27

// Control Configuration (no manual control)
#define CONTROL_TYPE CONTROL_NONE

// Sensor Configuration
#define DHT_SENSOR_TYPE DHT_TYPE_22
#define DHT_PIN 5
#define SOIL_MOISTURE_PIN 36

// Irrigation Settings
#define SOIL_MOISTURE_THRESHOLD 30
#define IRRIGATION_DURATION 5000
#define MAX_DAILY_IRRIGATIONS 10

// System Settings
#define SERIAL_OUTPUT_ENABLED true
#define WATCHDOG_ENABLED true

Best for: Basic automated irrigation with DHT22 sensor and LCD display

2. Advanced Offline Setup
// Advanced offline configuration - Copy to MainCode/offline/config.h

// Display Configuration (larger display)
#define DISPLAY_TYPE DISPLAY_LCD_2004
#define LCD_ADDRESS 0x27

// Control Configuration (rotary encoder for menu)
#define CONTROL_TYPE CONTROL_ROTARY_ENCODER
#define ENCODER_CLK_PIN 16
#define ENCODER_DT_PIN 17
#define ENCODER_SW_PIN 4

// Sensor Configuration (all sensors)
#define DHT_SENSOR_TYPE DHT_TYPE_22
#define DHT_PIN 5
#define SOIL_MOISTURE_PIN 36
#define LDR_SENSOR_TYPE LDR_TYPE_ENABLED
#define LDR_PIN 39

// Safety Features
#define WATCHDOG_ENABLED true
#define EMERGENCY_STOP_ENABLED true
#define PUMP_RUNTIME_PROTECTION true

Best for: Full-featured offline system with manual control and all sensors

3. Basic Online Setup
// Basic online configuration - Copy to MainCode/online/config.h

// WiFi Configuration
#define WIFI_SSID "YOUR_WIFI_SSID"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"

// IoT Services
#define IOT_SERVICES_ENABLED true
#define THINGSPEAK_ENABLED true
#define THINGSPEAK_API_KEY "YOUR_API_KEY"
#define ADAFRUIT_IO_ENABLED false

// Display & Sensors (same as offline)
#define DISPLAY_TYPE DISPLAY_LCD_1602
#define DHT_SENSOR_TYPE DHT_TYPE_22
#define DHT_PIN 5
#define SOIL_MOISTURE_PIN 36

// LED Configuration
#define LED_GREEN_PIN 18   // System OK
#define LED_RED_PIN 23     // Pump Active
#define LED_BLUE_PIN 2     // WiFi Connected

Best for: WiFi-enabled monitoring with ThingSpeak data logging

4. Web UI Only Setup
// Web UI only configuration - Copy to MainCode/online/config.h

// WiFi Configuration
#define WIFI_SSID "YOUR_WIFI_SSID"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"

// IoT Services (web UI only mode)
#define IOT_SERVICES_ENABLED false
#define WEB_UI_ONLY_MODE true

// Web Server Configuration
#define WEB_SERVER_PORT 80
#define ENABLE_WEB_AUTH true
#define WEB_USERNAME "admin"
#define WEB_PASSWORD "smartfarm123"

// Control Configuration
#define CONTROL_TYPE CONTROL_ROTARY_ENCODER
#define ENCODER_CLK_PIN 16
#define ENCODER_DT_PIN 17
#define ENCODER_SW_PIN 4

Best for: Local network monitoring without external cloud dependencies

Configuration Tips:
  • • Copy the configuration block to your config.h file
  • • Replace YOUR_WIFI_SSID and YOUR_API_KEY with actual values
  • • Test hardware with TestCode before using MainCode
  • • Start with basic configuration and add features gradually
  • • Use SERIAL_OUTPUT_ENABLED=false in production

Key Configuration Options

Serial Output
#define SERIAL_OUTPUT_ENABLED true
Enable/disable serial monitor output
IoT Services
#define IOT_SERVICES_ENABLED true
Enable/disable IoT cloud services
Display Type
#define DISPLAY_TYPE DISPLAY_LCD_1602
Choose LCD or headless mode
Control Type
#define CONTROL_TYPE CONTROL_ROTARY_ENCODER
Manual control or automated only
Sensor Type
#define DHT_SENSOR_TYPE DHT22
Temperature and humidity sensor
6

Upload Code

Choose between offline or online version and upload to your ESP32.

MainCode/offline/offline.ino # For offline version
MainCode/online/online.ino # For online version
7

Monitor System

Use configurable serial output or web interface to monitor system operation.

Serial Monitor (115200 baud) or Web Interface

💡 Tip: Disable serial output (SERIAL_OUTPUT_ENABLED false) for production deployments to improve performance.

🌐 IoT Services: Set WEB_UI_ONLY_MODE true to disable all IoT services and use only the built-in web interface.

API Documentation

REST API Endpoints

GET /api/status

Get current system status and sensor readings

{
  "systemOK": true,
  "soilMoisture": 45,
  "temperature": 25.3,
  "humidity": 60.2,
  "pumpActive": false,
  "uptime": 3600
}
POST /api/pump

Control pump manually

{
  "action": "start" | "stop",
  "duration": 30
}
GET /api/config

Get current system configuration

POST /api/config

Update system configuration

Troubleshooting & Support

Common Issues

System Not Starting

  • • Check power supply (minimum 2A)
  • • Verify all connections
  • • Run hardware test first

Sensors Not Reading

  • • Check wiring connections
  • • Verify power supply voltage
  • • Check sensor configuration
  • • LDR: Verify 10kΩ pull-down resistor
  • • LDR: Check GPIO 39 connection

WiFi Not Connecting

  • • Check WiFi credentials
  • • Verify signal strength
  • • Ensure 2.4GHz network

Get Support

GitHub Repository

Report issues and contribute

Documentation

Comprehensive guides and examples

Open Source

MIT License - Free to use and modify