{"slug": "ai-based-agricultural-anomaly-detection-using-kiwisiot", "title": "AI-Based Agricultural Anomaly Detection Using kiwisiot", "summary": "A project tutorial published with the KiwisIoT platform shows how an ESP32 microcontroller paired with a DHT22 temperature/humidity sensor, a BH1750 light sensor and an analog soil-moisture probe can flag agricultural anomalies and publish readings to the KiwisIoT dashboard over Wi-Fi and MQTT. The Arduino sketch samples sensors every 5000 milliseconds, maps raw soil readings between DRY_VALUE 3000 and WET_VALUE 1200 into a 0-100 percentage, and raises an anomaly when soil moisture falls below 20, temperature exceeds 40 C, or humidity drops below 30. The code sends soil, temperature, humidity, light and a binary anomaly flag to KiwisIoT channels 0, 1, 2, 6 and 7, which the tutorial labels a proposed channel mapping.", "body_md": "Project introduction\n\nAI-Based Agricultural Anomaly Detection is a smart farming project that monitors agricultural conditions using an ESP32 and different sensors.\n\nThe system continuously monitors:\n\n- Soil moisture level.\n- Temperature.\n- Air humidity.\n- Light intensity.\n\nAI-based anomaly detection identifies unusual readings, such as extremely dry soil, unusually high temperature, or abnormal humidity.\n\nThe ESP32 sends sensor data to the KiwisIoT dashboard, where farmers can monitor agricultural conditions and identify abnormal situations.\n\nMain objective: Detect unusual agricultural conditions early and help farmers protect their crops.\n\nStep 1: Install Arduino IDE\n\nDownload: Arduino IDE\n\nStep 2: Install ESP32 board\n\n1. Open Arduino IDE.\n\n2. Go to Boards Manager.\n\n3. Search for ESP32.\n\n4. Install Espressif ESP32.\n\n5. Select your ESP32 Dev Module board.\n\nStep 3: Install libraries\n\nOpen Library Manager and install:\n\n- DHT sensor library by Adafruit.\n- Adafruit Unified Sensor.\n- BH1750 by Christopher Laws.\n\nInstall the KiwisIoT library manually:\n\n1. Visit KiwisIoT.\n\n2. In Arduino IDE, select Sketch → Include Library → Add.ZIP Library.\n\nThe KiwisIoT SDK supports ESP32, Wi-Fi, MQTT communication and sensor-data publishing.\n\n7. Complete ESP32 program\n\nThis code:\n\n- Reads all three sensors.\n- Converts soil readings into a percentage.\n- Detects abnormal conditions.\n- Sends sensor values to KiwisIoT.\n- Sends anomaly status to the dashboard.\n\nCode:\n\n#include <WiFi.h>\n\n#include <Wire.h>\n\n#include <KiwisIoT.h>\n\n#include <DHT.h>\n\n#include <BH1750.h>\n\n// WiFi details\n\nconst char* ssid = \"YOUR_WIFI_NAME\";\n\nconst char* password = \"YOUR_WIFI_PASSWORD\";\n\n// KiwisIoT panel topic ID\n\nconst char* topic = \"YOUR_PANEL_TOPIC_ID\";\n\nKiwisIoT kiwisiot(ssid, password, topic);\n\n// Sensor pins\n\n#define SOIL_PIN 34\n\n#define DHT_PIN 4\n\n#define DHTTYPE DHT22\n\nDHT dht(DHT_PIN, DHTTYPE);\n\nBH1750 lightMeter;\n\n// Soil calibration values.\n\n// Replace these after testing your own sensor.\n\nconst int DRY_VALUE = 3000;\n\nconst int WET_VALUE = 1200;\n\nunsigned long lastSend = 0;\n\nconst unsigned long interval = 5000;\n\nvoid setup() {\n\nSerial.begin(115200);\n\ndht.begin();\n\nWire.begin(21, 22);\n\nlightMeter.begin();\n\nkiwisiot.begin();\n\nSerial.println(\"Agricultural Monitoring Started\");\n\n}\n\nvoid loop() {\n\nkiwisiot.run();\n\nif (millis() - lastSend >= interval) {\n\nlastSend = millis();\n\n// Read soil moisture\n\nint soilRaw = analogRead(SOIL_PIN);\n\nint soil = map(\n\nsoilRaw,\n\nDRY_VALUE,\n\nWET_VALUE,\n\n0,\n\n100\n\n);\n\nsoil = constrain(soil, 0, 100);\n\n// Read temperature and humidity\n\nfloat temperature = dht.readTemperature();\n\nfloat humidity = dht.readHumidity();\n\n// Read light intensity\n\nfloat light = lightMeter.readLightLevel();\n\n// Check sensor validity\n\nif (isnan(temperature) ||\n\nisnan(humidity) ||\n\nlight < 0) {\n\nSerial.println(\"Sensor reading error\");\n\nreturn;\n\n}\n\n// Anomaly detection\n\nbool anomaly = false;\n\nif (soil < 20) {\n\nanomaly = true;\n\nSerial.println(\"ALERT: Soil is too dry\");\n\n}\n\nif (temperature > 40) {\n\nanomaly = true;\n\nSerial.println(\"ALERT: High temperature\");\n\n}\n\nif (humidity < 30) {\n\nanomaly = true;\n\nSerial.println(\"ALERT: Low humidity\");\n\n}\n\n// Send data to KiwisIoT\n\nkiwisiot.send(\"0\", soil);\n\nkiwisiot.send(\"1\", temperature);\n\nkiwisiot.send(\"2\", humidity);\n\nkiwisiot.send(\"6\", light);\n\nkiwisiot.send(\"7\", anomaly ? 1 : 0);\n\n// Serial output\n\nSerial.println(\"---------------------\");\n\nSerial.print(\"Soil Moisture: \");\n\nSerial.print(soil);\n\nSerial.println(\"%\");\n\nSerial.print(\"Temperature: \");\n\nSerial.print(temperature);\n\nSerial.println(\" C\");\n\nSerial.print(\"Humidity: \");\n\nSerial.print(humidity);\n\nSerial.println(\"%\");\n\nSerial.print(\"Light: \");\n\nSerial.print(light);\n\nSerial.println(\" lux\");\n\nSerial.print(\"Anomaly: \");\n\nSerial.println(anomaly ? \"DETECTED\" : \"NORMAL\");\n\nSerial.println(\"---------------------\");\n\n}\n\n}\n\nImportant: The code uses the KiwisIoT send(channel, value) pattern documented in its agriculture example. The channel numbers above are the proposed channel mapping for this project. Configure the dashboard widgets to match them.\n\nKiwisIoT+1\n\n8. KiwisIoT dashboard setup\n\n3insys.com\n\nStep 1: Create an account\n\nOpen KiwisIoT and sign in.\n\nStep 2: Create a panel\n\n1. Open My Panels.\n\n2. Click Create New Panel.\n\n3. Enter the panel name:\n\nAI Agricultural Anomaly Detection\n\n4. Save the panel.\n\nStep 3: Add dashboard widgets\n\nCreate these widgets and connect them to the matching channels.\n\nWidget name Channel Display\n\nSoil Moisture 0 Gauge\n\nTemperature 1 Gauge\n\nHumidity 2 Gauge\n\nLight Intensity 6 Gauge\n\nAnomaly Status 7 Indicator\n\nAlso add charts for soil moisture, temperature and humidity.\n\nStep 4: Connect ESP32\n\n1. Copy the dashboard topic ID.\n\n2. Paste it into the YOUR_PANEL_TOPIC_ID section of the code.\n\n3. Enter your Wi-Fi name and password.\n\n4. Connect ESP32 using USB.\n\n5. Select the correct COM port.\n\n6. Upload the program.\n\nStep 5: Monitor readings\n\nOpen your KiwisIoT dashboard. You should see live sensor values when the ESP32 successfully connects and publishes data.\n\nAdvantages\n\n1. Helps identify dry soil conditions.\n\n2. Detects abnormal environmental readings.\n\n3. Supports remote farm monitoring.\n\n4. Reduces the need for continuous manual checking.\n\n5. Can be extended with automatic irrigation.\n\n6. Can be upgraded using machine learning.\n\nProject Summary:\n\n[Read more](<javascript:void(0)>)", "url": "https://wpnews.pro/news/ai-based-agricultural-anomaly-detection-using-kiwisiot", "canonical_source": "https://www.hackster.io/yuvansris2002/ai-based-agricultural-anomaly-detection-using-kiwisiot-2b82ec", "published_at": "2026-11-16 13:00:49+00:00", "updated_at": "2026-11-16 13:20:14.288264+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-tools", "ai-infrastructure"], "entities": ["KiwisIoT", "ESP32", "Espressif", "Arduino IDE", "DHT22", "BH1750", "Adafruit"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/ai-based-agricultural-anomaly-detection-using-kiwisiot", "markdown": "https://wpnews.pro/news/ai-based-agricultural-anomaly-detection-using-kiwisiot.md", "text": "https://wpnews.pro/news/ai-based-agricultural-anomaly-detection-using-kiwisiot.txt", "jsonld": "https://wpnews.pro/news/ai-based-agricultural-anomaly-detection-using-kiwisiot.jsonld"}}