IoT-Based Poultry Farm Monitoring System Using ESP8266 and KiwisIoT

by ananthi rk in Circuits > Sensors

11 Views, 0 Favorites, 0 Comments

IoT-Based Poultry Farm Monitoring System Using ESP8266 and KiwisIoT

IoT Poultry Farm Monitoring System.png
  1. Poultry farming is an important part of modern agriculture. Maintaining suitable environmental conditions inside a poultry farm is essential for bird comfort, farm management, and day-to-day monitoring.
  2. Temperature, humidity, lighting, movement, and air conditions are important parameters to observe. Checking these conditions manually can be time-consuming, especially when continuous monitoring is required.
  3. This project presents an IoT-Based Poultry Farm Monitoring System using a NodeMCU ESP8266, four sensors, and the KiwisIoT platform.
  4. The system collects temperature and humidity readings using a DHT11 sensor, detects movement using a PIR sensor, reads the output of an MQ-2 gas and smoke sensor, and identifies bright or dark conditions using an LDR module.
  5. The ESP8266 connects to Wi-Fi and transmits sensor data to a KiwisIoT dashboard. Users can view the incoming readings through a connected device without needing to read every sensor directly.
  6. This project demonstrates how IoT technology can be used to build a basic remote environmental monitoring system for poultry farms.

Supplies

Hardware Components

  1. NodeMCU ESP8266 development board
  2. DHT11 temperature and humidity sensor
  3. HC-SR501 PIR motion sensor
  4. MQ-2 gas and smoke sensor module
  5. LDR light sensor module with digital output
  6. Jumper wires
  7. USB cable
  8. Suitable power supply
  9. Computer or laptop
  10. Wi-Fi connection

Software Requirements

  1. Arduino IDE
  2. ESP8266 board package
  3. DHT sensor library
  4. Adafruit Unified Sensor library, if required
  5. KiwisIoT Arduino library
  6. KiwisIoT account
  7. Web browser for dashboard access

Circuit Connections

Connect the sensors to the NodeMCU ESP8266 according to the following pin mapping.

DHT11

Sensor Pin NodeMCU Pin
VCC ---> 3V3
GND ---> GND
DATA ---> D4

PIR Motion Sensor

Sensor Pin NodeMCU Pin
VCC ---> Supply specified for the module
GND ---> GND
OUT ---> D5

MQ-2 Gas Sensor

Sensor Pin NodeMCU Pin
VCC ---> Supply specified for the module
GND ---> GND
AO ---> A0

LDR Digital Module

Sensor Pin NodeMCU Pin
VCC ---> 3V3, if supported
GND ---> GND
DO ---> D6

Connect all sensor grounds to a common GND.

Important electrical safety: MQ-2 modules may require 5V and may produce an analog output that exceeds the ESP8266 analog input limit. Verify the exact NodeMCU board's A0 range and the module's output voltage before connecting them. Use a suitable voltage divider or signal-conditioning circuit where required. Never apply an unsafe voltage to an ESP8266 input.

Arduino IDE Installation

Step 1: Install Arduino IDE

Download and install Arduino IDE on your computer.

Step 2: Install the ESP8266 Board Package

Open Arduino IDE and navigate to Boards Manager. Search for the ESP8266 platform and install it if it is not already installed.

Step 3: Select the Board

Connect the NodeMCU through USB.

Select the appropriate NodeMCU ESP8266 board and the COM port corresponding to your device.

Step 4: Install Sensor Libraries

Open Library Manager and install the DHT sensor library. Install Adafruit Unified Sensor if the selected DHT library requires it.

Step 5: Install the KiwisIoT Library

Install the appropriate KiwisIoT library and use the example supplied with that version to confirm its connection and data-sending functions.

Step 6: Configure the Program

Enter the Wi-Fi credentials and the actual KiwisIoT dashboard topic ID in the Arduino program.

Check that the pin definitions match the physical circuit.

Step 7: Compile and Upload

Click Verify to compile the code. If there are no errors, click Upload to flash the program to the NodeMCU.

Open Serial Monitor and select 115200 baud to observe the output.

KiwisIoT Platform Setup

KiwisIoT provides a dashboard interface for organizing panels, adding widgets, connecting hardware, and monitoring incoming sensor data.

Official links:

  1. Getting Started: https://www.kiwisiot.in/get-started
  2. Tutorials: https://www.kiwisiot.in/tutorial
  3. Help Center: https://www.kiwisiot.in/help-center

Step 1: Create an Account

Open the KiwisIoT website in your browser. https://www.kiwisiot.in/login

Create an account if you do not already have one. Complete any verification step required by the platform and sign in.

Step 2: Open My Panels

After signing in, navigate to the My Panels section.

Panels are workspaces where sensor widgets can be organized and connected to the relevant data source.

Step 3: Create a New Panel

Choose the option to create a panel or dashboard.

Enter the panel name: Poultry Farm Monitoring Dashboard

Step 4: Obtain the Panel Topic ID

  1. Open the created panel and locate its topic ID or connection information.
  2. The project code uses a topic in this general format:
  3. dash_XXXXXXXXXXXXX
  4. Copy the actual topic ID shown by your panel and replace the placeholder in the Arduino code.
  5. Do not use the sample topic as your real connection ID.

Step 5: Add Widgets

  1. Add the widgets supported by your KiwisIoT dashboard. Suggested widget types include gauges, numeric displays, charts, and status displays.
  2. Choose widgets according to the type of data being sent.

Step 6: Configure Data Sources

For each widget, choose the relevant panel or device data source. Set the appropriate channel or field mapping if the dashboard asks for it.

Save the configuration.

Step 7: Connect the ESP8266

  1. Configure the ESP8266 program with the same topic ID.
  2. The device must connect through the KiwisIoT library and protocol supported by the installed setup. Confirm that the platform receives the data before changing the widget layout.

Step 8: Verify the Dashboard

  1. Power on the device and wait for sensor readings to arrive.
  2. Compare the values displayed on the dashboard with those printed in the Arduino Serial Monitor.
  3. If the device sends readings but the dashboard remains empty, check the topic ID, connection status, widget data source, and channel mapping.

Dashboard Data Mapping

The Arduino program uses the following channel mapping.

Channel Data Example
0 ---> Temperature ---> 32.5 °C
1 ---> Humidity ---> 65%
2 ---> Motion Status ---> Detected / No Detection
3 ---> MQ-2 Raw Value ---> 420
4 ---> Light Status ---> Bright / Dark

The example readings are illustrative, not measured values from a particular poultry farm.

Recommended Widget Configuration

Temperature: Use a numeric value widget or gauge. Display the unit as °C.

Humidity: Use a numeric value widget or gauge. Display the unit as %.

Motion Status: Use a status or text widget that supports the values sent by the program.

Gas Sensor: Use a numeric widget or gauge to show the raw sensor reading. Do not label the raw reading as ppm unless a calibrated measurement system provides that unit.

Light Status: Use a status or text widget that displays Bright or Dark.

The exact widget names and data configuration fields may vary with the current platform interface.

Arduino Code


#include <ESP8266WiFi.h>
#include <KiwisIoT.h>

#include <DHT.h>

// Wi-Fi Details
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_PASSWORD";

// KiwisIoT Dashboard Topic ID
const char* topic = "dash_XXXXXXXXXXXXXX";

// Sensor Pins
#define DHT_PIN D4
#define DHT_TYPE DHT11
#define PIR_PIN D5
#define MQ2_PIN A0
#define LDR_PIN D6

// DHT11 Setup
DHT dht(DHT_PIN, DHT_TYPE);

// KiwisIoT Setup
KiwisIoT kiwisiot(ssid, password, topic);

// Timer
unsigned long previousMillis = 0;
const unsigned long interval = 5000;

void setup() {
Serial.begin(115200);

pinMode(PIR_PIN, INPUT);
pinMode(LDR_PIN, INPUT);

dht.begin();
kiwisiot.begin();

Serial.println();
Serial.println("================================");
Serial.println(" POULTRY FARM IoT MONITORING");
Serial.println("================================");
Serial.println("Initializing sensors...");
}

void loop() {
kiwisiot.run();

if (millis() - previousMillis >= interval) {
previousMillis = millis();

// Read DHT11
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();

// Read PIR Motion Sensor
int motion = digitalRead(PIR_PIN);

// Read MQ-2 Gas Sensor
int gasValue = analogRead(MQ2_PIN);

// Read LDR Digital Output
int lightValue = digitalRead(LDR_PIN);

Serial.println();
Serial.println("------ POULTRY FARM DATA ------");

// 1. Temperature
if (!isnan(temperature)) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

kiwisiot.send("0", temperature);
} else {
Serial.println("Temperature: Sensor Error");
}

// 2. Humidity
if (!isnan(humidity)) {
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");

kiwisiot.send("1", humidity);
} else {
Serial.println("Humidity: Sensor Error");
}

// 3. Motion Detection
if (motion == HIGH) {
Serial.println("Motion Status: Detected");

// Text support depends on your KiwisIoT library
kiwisiot.send("2", "Detected");
} else {
Serial.println("Motion Status: No Detection");

kiwisiot.send("2", "No Detection");
}

// 4. Gas / Smoke Sensor
Serial.print("Gas Sensor Raw Value: ");
Serial.println(gasValue);

kiwisiot.send("3", gasValue);

// 5. Light Status
// Assumption: LOW = Bright, HIGH = Dark
if (lightValue == LOW) {
Serial.println("Light Status: Bright");

kiwisiot.send("4", "Bright");
} else {
Serial.println("Light Status: Dark");

kiwisiot.send("4", "Dark");
}

Serial.println("-------------------------------");
}
}

How the Arduino Program Works

The program performs the following operations.

Initialization

The ESP8266 starts Serial communication, initializes the DHT11 sensor, configures the PIR and LDR pins, and initializes the KiwisIoT library.

Sensor Reading

At each scheduled update, the program reads temperature, humidity, motion status, gas sensor output, and light status.

Data Validation

The DHT11 values are checked to ensure the reading is valid before sending the temperature and humidity.

Status Conversion

The PIR digital value is converted to a readable status:

  1. HIGH becomes Detected.
  2. LOW becomes No Detection.

The LDR digital value is converted to Bright or Dark according to the assumed module logic.

Data Transmission

The program sends each reading using the corresponding channel ID and KiwisIoT library method.

Repeated Updates

The program uses a five-second interval to schedule sensor readings and updates. This is the intended sampling interval; actual dashboard arrival times can vary with network and platform latency.

Testing Procedure

Arduino IDE Serial Monitor Dashboard.png
Analysis output 1.png

Test 1: Temperature Monitoring

  1. Place the DHT11 in the test environment and power on the NodeMCU.
  2. Observe the temperature value in the Serial Monitor. Confirm that the dashboard displays the corresponding value.

Test 2: Humidity Monitoring

Check the relative humidity reading and compare it with the dashboard display.

Test 3: Motion Detection

  1. Move within the PIR sensor's detection area.
  2. Confirm that the program displays Detected when movement is detected and No Detection when its output returns LOW.
  3. Allow sufficient time for PIR initialization after power-up.

Test 4: Gas Sensor Reading

  1. Allow the MQ-2 module to warm up according to its specifications.
  2. Observe the raw reading under normal conditions and compare it with the value received by the dashboard.
  3. Do not deliberately release hazardous gas or smoke for testing. This project is not a certified gas-safety detector.

Test 5: Light Detection

  1. Expose the LDR module to bright light and then cover it.
  2. Check whether the status changes between Bright and Dark. If the labels are reversed, update the program to match the module's actual output.

Test 6: IoT Dashboard

  1. Keep the ESP8266 connected to Wi-Fi.
  2. Confirm that all five channel values appear in their respective dashboard widgets. Check the Serial Monitor and dashboard side by side if a value is missing.

13. Sample Output

Example Serial Monitor output:

------ POULTRY FARM DATA ------
Temperature: 32.5 C
Humidity: 65.0 %
Motion Status: Detected
Gas Sensor Raw Value: 420
Light Status: Bright
-------------------------------

The values shown above are examples. Actual readings depend on the environment, sensor calibration, module behavior, and installation.

Dashboard

kiwisiot_poultry_dashboard_832x551.png
kiwisiot_dashboard_832x551.png

Dashboard Interpretation

The dashboard helps the user observe five categories of information.

  1. Temperature provides a reading of the surrounding air temperature.
  2. Humidity indicates the relative moisture level in the air.
  3. Motion Status indicates whether the PIR sensor currently reports movement.
  4. Gas Sensor Value displays the MQ-2 raw analog reading.
  5. Light Status indicates whether the LDR module classifies the surroundings as bright or dark.

GitHub Repository

The complete source code for this KiwisIoT project is available on GitHub. You can access the code, review the sensor connections, and modify it according to your project requirements.

GitHub Source Code: https://github.com/Kiwistron/KiwisIoT-Projects


Troubleshooting

Problem: Dashboard Values Are Missing

Check the Wi-Fi connection, topic ID, library configuration, and widget data source. Confirm that the device is transmitting readings using the method supported by the installed KiwisIoT library.

Problem: Temperature or Humidity Shows an Error

Check the DHT11 wiring, DATA pin, library installation, and sensor type definition.

Problem: Motion Is Always Detected

Allow the PIR sensor to initialize. Check the OUT pin, power supply, sensitivity, and delay settings.

Problem: Bright and Dark Are Reversed

Test the LDR module and reverse the label mapping if its digital output behaves differently from the program's assumption.

Problem: MQ-2 Reading Is Unstable

Check the sensor supply, warm-up period, grounding, and analog input voltage. Do not treat raw readings as calibrated gas concentrations.

Problem: Arduino Code Does Not Compile

Verify the ESP8266 board selection and library installation. If a KiwisIoT function differs from the code, compare it with the example supplied by the installed library version.



Applications

  1. Poultry farm environmental monitoring
  2. Temperature and humidity observation
  3. Motion monitoring
  4. Gas and smoke sensor observation
  5. Light condition monitoring
  6. Smart agriculture prototypes
  7. Educational IoT projects
  8. Embedded systems experimentation


Conclusion

  1. The ESP8266 Poultry Farm IoT Monitoring System demonstrates how multiple sensors can be combined with a Wi-Fi-enabled microcontroller and the KiwisIoT platform.
  2. The system monitors temperature, humidity, motion, gas-sensor output, and light status, then presents the readings through an IoT dashboard.
  3. This project provides a foundation for learning connected sensor systems and developing more advanced agricultural monitoring solutions.