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.
- 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
- 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
- ESP32 development board
- DHT22 temperature/humidity sensor
- Soil moisture sensor
- Breadboard and jumper wires
- Power supply (USB or external)
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
-
Install Arduino IDE and ESP32 board support
-
Install Required Libraries:
- WiFi (built-in) - WebServer (built-in) - DHT sensor library by Adafruit - ArduinoJson by Benoit Blanchon
-
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
- Open
-
Install Android Studio
-
Open the Project:
- Open the
android-iot-agriculture
folder in Android Studio - Sync Gradle files
- Build the project
- Open the
-
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
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 |
{
"temperature": 25.6,
"humidity": 62.3,
"moisture": 45.2,
"timestamp": 123456789,
"unit_temp": "celsius",
"unit_humidity": "percent",
"unit_moisture": "percent"
}
- Launch the app on your Android device
- Enter ESP32 IP address (shown in ESP32 Serial Monitor)
- Tap "Connect to ESP32" to establish connection
- 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)
- Auto-refresh every 5 seconds or tap "Refresh Data" manually
- Blue: Cold (< 10°C)
- Green: Cool (10-25°C)
- Yellow: Optimal (25-35°C)
- Red: Hot (> 35°C)
- Blue: Current humidity percentage
- Light Blue: Remaining to 100%
- Red: Dry soil (< 30%) - Needs water
- Green: Optimal moisture (30-70%)
- Blue: Wet soil (> 70%) - Excess water
-
"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
-
"No Sensor Data" Error:
- Check sensor wiring connections
- Verify DHT22 and moisture sensor are working
- Check Serial Monitor for sensor reading errors
-
App Crashes:
- Ensure Android device has internet permission
- Check for adequate memory/storage space
- Restart the app and try again
- 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
- Minimum SDK: 21 (Android 5.0)
- Target SDK: 34 (Android 14)
- Libraries: MPAndroidChart, OkHttp3, Gson
- Permissions: Internet, Network State, WiFi State
- 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
- 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
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and support, please open an issue in the project repository.
Happy Farming! 🌱