Skip to content

Complete IoT Agricultural Monitoring System with Android APK and ESP32 sensors. Features real-time pie charts for temperature, humidity, and soil moisture data.

Notifications You must be signed in to change notification settings

stiggs1/iot-agricultural-android-esp32

Repository files navigation

IoT Agricultural Monitoring System

A complete IoT agricultural monitoring solution consisting of an Android APK and ESP32 sensor system that displays temperature, humidity, and soil moisture readings as interactive pie charts.

📱 Features

Android App

  • Real-time sensor monitoring with automatic 5-second refresh
  • Interactive pie charts for temperature, humidity, and soil moisture
  • ESP32 connection management with status indicators
  • Material Design UI with cards and professional styling
  • Configurable ESP32 IP address for easy setup
  • Manual refresh capability for instant data updates

ESP32 Sensor System

  • DHT22 sensor for temperature and humidity
  • Soil moisture sensor for agricultural monitoring
  • WiFi connectivity with HTTP API endpoints
  • JSON data format for easy integration
  • CORS support for cross-origin requests
  • Web interface for direct browser access

🔧 Hardware Requirements

ESP32 Setup

  • ESP32 development board
  • DHT22 temperature/humidity sensor
  • Soil moisture sensor
  • Breadboard and jumper wires
  • Power supply (USB or external)

Wiring Diagram

ESP32 → DHT22
GPIO 4 → Data Pin
3.3V → VCC
GND → GND

ESP32 → Soil Moisture Sensor
A0 → Analog Output
GPIO 7 → VCC (Power Control)
GND → GND

🚀 Installation & Setup

ESP32 Setup

  1. Install Arduino IDE and ESP32 board support

  2. Install Required Libraries:

    - WiFi (built-in)
    - WebServer (built-in)
    - DHT sensor library by Adafruit
    - ArduinoJson by Benoit Blanchon
    
  3. Upload the Code:

    • Open esp32-sensor-code/esp32_agricultural_sensors.cpp in Arduino IDE
    • Update WiFi credentials:
      const char* ssid = "YOUR_WIFI_SSID";
      const char* password = "YOUR_WIFI_PASSWORD";
    • Connect ESP32 and upload the code
    • Open Serial Monitor to see the IP address

Android App Setup

  1. Install Android Studio

  2. Open the Project:

    • Open the android-iot-agriculture folder in Android Studio
    • Sync Gradle files
    • Build the project
  3. Install APK:

    • Connect Android device with USB debugging enabled
    • Run the app from Android Studio, or
    • Build APK: Build → Build Bundle(s) / APK(s) → Build APK(s)
    • Install the generated APK on your device

📊 API Endpoints

The ESP32 provides the following HTTP endpoints:

Endpoint Method Description
/ GET Web interface with current readings
/status GET Device status and connection info
/data GET All sensor data in JSON format
/temperature GET Temperature data only
/humidity GET Humidity data only
/moisture GET Soil moisture data only

Example JSON Response (/data):

{
  "temperature": 25.6,
  "humidity": 62.3,
  "moisture": 45.2,
  "timestamp": 123456789,
  "unit_temp": "celsius",
  "unit_humidity": "percent",
  "unit_moisture": "percent"
}

📱 Using the Android App

  1. Launch the app on your Android device
  2. Enter ESP32 IP address (shown in ESP32 Serial Monitor)
  3. Tap "Connect to ESP32" to establish connection
  4. View real-time data in interactive pie charts:
    • Temperature Chart: Color-coded ranges (cold, optimal, warm, hot)
    • Humidity Chart: Current vs. remaining percentage
    • Moisture Chart: Soil condition (dry, optimal, wet)
  5. Auto-refresh every 5 seconds or tap "Refresh Data" manually

🎨 Chart Visualization

Temperature Pie Chart

  • Blue: Cold (< 10°C)
  • Green: Cool (10-25°C)
  • Yellow: Optimal (25-35°C)
  • Red: Hot (> 35°C)

Humidity Pie Chart

  • Blue: Current humidity percentage
  • Light Blue: Remaining to 100%

Soil Moisture Chart

  • Red: Dry soil (< 30%) - Needs water
  • Green: Optimal moisture (30-70%)
  • Blue: Wet soil (> 70%) - Excess water

🔧 Troubleshooting

Common Issues

  1. "Connection Failed" Error:

    • Verify ESP32 and Android device are on same WiFi network
    • Check ESP32 IP address in Serial Monitor
    • Ensure ESP32 is powered and running
  2. "No Sensor Data" Error:

    • Check sensor wiring connections
    • Verify DHT22 and moisture sensor are working
    • Check Serial Monitor for sensor reading errors
  3. App Crashes:

    • Ensure Android device has internet permission
    • Check for adequate memory/storage space
    • Restart the app and try again

Debug Tips

  • Use ESP32 Serial Monitor to see sensor readings and HTTP requests
  • Test ESP32 endpoints directly in a web browser
  • Check Android app logs in Android Studio

📋 Technical Specifications

Android App

  • Minimum SDK: 21 (Android 5.0)
  • Target SDK: 34 (Android 14)
  • Libraries: MPAndroidChart, OkHttp3, Gson
  • Permissions: Internet, Network State, WiFi State

ESP32 System

  • Sensor Accuracy: DHT22 (±0.5°C, ±2-5% RH)
  • Update Frequency: 2 seconds
  • WiFi: 802.11 b/g/n
  • Power: 3.3V operation
  • Operating Range: -40°C to +80°C

🔮 Future Enhancements

  • Data logging and historical charts
  • Push notifications for threshold alerts
  • Multiple ESP32 device support
  • Cloud data storage integration
  • Advanced analytics and trends
  • Weather forecast integration

📄 License

This project is open source and available under the MIT License.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📞 Support

For issues and support, please open an issue in the project repository.


Happy Farming! 🌱

About

Complete IoT Agricultural Monitoring System with Android APK and ESP32 sensors. Features real-time pie charts for temperature, humidity, and soil moisture data.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published