The problem
A dairy barn is a workplace for cows, and its air decides how much milk they give: heat plus humidity cuts how much cows eat and rest, while ammonia from manure irritates their lungs and eyes. This project builds a Smart Dairy Farm Climate Monitor using ESP32: a DHT22 reads temperature and humidity, an MQ-137 reads ammonia, and the readings become the temperature-humidity index (THI), dairy's heat-stress number, shown live with zones, curves, a log. Builder note: the MQ-137 heater needs over 48 hours of warm-up before readings settle (Winsen datasheet preheat), so it is powered first, mounted 1.2 m above the floor at cow-nose height, reading the air the animals breathe, not the cleaner air near the roof. In the demo, 26.4 °C at 52% humidity gives THI 73.8 — just inside mild stress — while the same temperature at 80% humidity gives THI 77.2, so humidity alone deepens the stress and the fans and misters act automatically.
Reads barn temperature and humidity every 2 seconds.
Follow the working sequence
How it works
Air moves through the system in a short loop: sense, compute, decide, act, display. DHT22 modules in three barn zones sample temperature and humidity every 2 seconds, the fastest the sensor's datasheet allows, while the MQ-137 near the manure alley reads ammonia after its long warm-up. The ESP32 takes those numbers, computes the THI with the NRC formula, and compares THI and ammonia against the configured thresholds. When a threshold is crossed, relay outputs switch the exhaust fans or misters, and the same readings travel over Wi-Fi to the barn dashboard, where they appear as live cards, per-zone rows, 24-hour curves and log entries, while the 16x2 LCD mirrors the headline numbers at the barn door. Alerts are raised the moment a threshold is crossed rather than on a schedule, so a rising ammonia reading reaches the farmer while the fans are already responding.
- DHT22 sensors in the milking area, resting area and feed alley measure air temperature (−40 to +80 °C, ±0.5 °C) and relative humidity (0–100% RH, ±2% RH typical), one sample every 2 seconds.
- The MQ-137 ammonia sensor near the manure alley reads NH3 across its 5–500 ppm datasheet range; its heater runs continuously after the initial 48-hour warm-up so readings stay stable.
- The ESP32 reads all sensors, computes THI from temperature and humidity with the NRC (1971) formula, and compares THI and NH3 against the thresholds (fan at THI 72, mister at THI 78, NH3 alert at 25 ppm).
- When a threshold is crossed, the ESP32 drives the relay module: exhaust fans start, and misters run 30-second bursts with 5-minute gaps above THI 78.
- Readings, THI, zone values and relay states are sent over Wi-Fi to the barn dashboard, which draws the 24-hour climate curves, the per-zone table and the event log, and records every threshold crossing.
- The 16x2 LCD at the barn door shows the current temperature, humidity, NH3 and THI, and the dashboard raises a visible alert whenever ammonia passes 25 ppm or THI enters the moderate band.
Tech stack:
- ESP32 dual-core microcontroller with Wi-Fi
- DHT22 temperature-humidity sensor
- MQ-137 ammonia sensor module
- Arduino IDE with C++ firmware
- 16x2 LCD display
- Relay module with 12 V exhaust fans
- HTML · CSS · JavaScript dashboard
- DS18B20 temperature probe (optional)
| Parameter | Value |
|---|---|
| Controller | ESP32 dual-core microcontroller with Wi-Fi |
| Temperature sensor | DHT22, −40 to +80 °C, ±0.5 °C (datasheet values) |
| Humidity sensor | DHT22, 0–100% RH, ±2% RH typical, ±5% RH maximum (datasheet values) |
| Ammonia sensor | MQ-137, 5–500 ppm NH3, heater 5.0 V ±0.1 V, ≤900 mW (datasheet values) |
| THI formula | NRC (1971): THI = (1.8 × T + 32) − (0.55 − 0.0055 × RH) × (1.8 × T − 26) |
| THI bands | Below 72 no stress · 72–79 mild · 80–89 moderate · 90–98 severe (reference values) |
| Fan trigger | Exhaust fans ON at THI above 72 or NH3 above 25 ppm (configurable) |
| Mister trigger | Misters ON at THI above 78, 30 s on / 5 min off cycle (configurable) |
| Display | 16x2 LCD showing temperature, humidity, NH3 and THI |
| Dashboard | Web dashboard with 3 zones, 24-hour curves and event log |
| Sampling interval | 1 reading every 2 s per DHT22 (datasheet limit) |
| Power | 5 V USB for ESP32 and sensors · 12 V DC for exhaust fans (separate supply) |
| Zones monitored | 3 zones (milking area, resting area, feed alley) plus manure-alley NH3 point |
Project features
The monitor's strongest capabilities are the ones a dairy farmer checks first. Ammonia sensing is the headline: the MQ-137 watches NH3 from manure continuously and raises an alert at 25 ppm, with a critical level at 50 ppm, because ammonia is the barn gas that most directly harms cows and workers. Second is the THI heat-stress index, computed live from the DHT22 readings with the NRC (1971) formula, so the dashboard shows not just temperature but what the heat actually feels like to a cow, with the familiar bands — below 72 no stress, 72–79 mild, 80–89 moderate. Third is automatic ventilation: exhaust fans start when THI crosses 72 or ammonia crosses 25 ppm, and misters run in short cycles above THI 78. Fourth is the barn dashboard itself, with three zones, 24-hour climate curves and an event log, plus a 16x2 LCD at the barn door for readings without a phone.
- [Ammonia (NH3) monitoring] The MQ-137 sensor reads barn ammonia across its 5–500 ppm datasheet range, with a dashboard alert at 25 ppm and a critical alert at 50 ppm; the sensor is mounted 1.2 m above the floor near the manure alley.
- [THI heat-stress index] The ESP32 computes the temperature-humidity index live from DHT22 readings using the NRC (1971) formula, and bands it as no stress below 72, mild at 72–79 and moderate at 80–89 (reference values).
- [Automatic exhaust fans] Two 12 V exhaust fans switch on through a relay module when THI crosses 72 or ammonia crosses 25 ppm, and switch off when conditions recover, with manual override from the dashboard.
- [Mister / fogger control] Misters run in 30-second bursts with 5-minute gaps when THI crosses 78, cooling the air without soaking the bedding; the cycle timing is configurable in firmware.
- [Barn dashboard with zones and curves] A web dashboard shows live readings, three zones (milking area, resting area, feed alley), 24-hour temperature, humidity and THI curves, and an event log of alerts and fan starts.
- [16x2 LCD at the barn] A character LCD at the barn door shows temperature, humidity, NH3 and THI at a glance, so the reading is visible without opening the dashboard.
- [Optional add-on — DS18B20 probe] An optional waterproof DS18B20 temperature probe can be added for a fourth measurement point, such as water-trough temperature; it is not part of the base build and is fitted only on request.
What is included
- Working ESP32-based barn climate monitor prototype (sensors, LCD, relay and fans wired on breadboard)
- Firmware (Arduino IDE, C++) with THI computation, thresholds and relay logic
- Barn dashboard web app with live readings, zones, curves and event log
- Wiring diagram, component list and sensor placement guide (MQ-137 height and warm-up notes)
- Project abstract PDF (10 sections) and demonstration guidance
- Viva Q&A preparation document (THI, ammonia sensing, sensor limits)
Limitations & prerequisites
- MQ-137 readings are indicative, not laboratory-grade: the sensor needs over 48 hours of heater warm-up and clean-air calibration, and it also responds to other amines, so readings are approximate.
- DHT22 accuracy is ±0.5 °C and ±2% RH typical (±5% RH maximum); THI inherits that uncertainty and is a guidance index, not a veterinary diagnosis.
- The prototype monitors one barn section with 3 zones; a full commercial shed would need more sensor nodes and a weatherproof enclosure, which are not included.
- Wi-Fi is required for the dashboard; without it, only the LCD and automatic fan/mister control keep working.
- Misters cool by evaporation and raise humidity, so in already-humid weather they can push THI up instead of down; the 30-second cycle is a design target, not a measured cooling figure.
- The build is an academic prototype, not a certified farm system; ventilation and animal-welfare decisions should be confirmed with a veterinarian or dairy extension adviser.
Frequently Asked Questions
How is this different from the ESP32 vertical farm projects?
It is a different project for a different subject: this monitor watches a cattle barn, while the vertical farm projects grow plants on racks. The vertical farm pages use LED grow lights, irrigation pumps, soil-moisture sensors and pH/EC nutrient dosing for plants; this project has none of those. Instead it senses ammonia from manure with an MQ-137, computes the THI heat-stress index for cows, and drives exhaust fans and misters to keep the animals comfortable — different sensors, different actuators and a milk-yield purpose, so the two projects share only the ESP32 controller.
Is this project suitable for a final-year project?
Yes — it fits Electronics & Telecommunication, Electrical, Instrumentation and IoT & Embedded programmes very well. It demonstrates sensor interfacing, embedded C firmware, a real dairy-science metric (THI), relay-based actuator control and a web dashboard in one build, which gives plenty of viva material. The project also has honest limits to discuss, such as MQ-137 calibration and DHT22 accuracy, which examiners expect students to understand.
What is THI and why does it matter for cows?
THI is the temperature-humidity index, a single number that combines air temperature and relative humidity to say how stressful the heat feels to a cow, computed here with the NRC (1971) formula. Dairy references put no stress below THI 72, mild stress at 72–79 and moderate stress at 80–89, with milk yield falling as THI rises. The ESP32 computes THI live from the DHT22 readings, so the dashboard shows heat stress directly instead of leaving the farmer to guess from temperature alone.
Why is ammonia sensing the key sensor here?
Ammonia comes from manure and urine, builds up fastest near the floor where cows breathe, and irritates their lungs and eyes while also bothering farm workers. The MQ-137 detects ammonia across 5–500 ppm (datasheet range), and this build alerts at 25 ppm and boosts the exhaust fans, which is the single most useful barn-air action. Temperature and humidity matter too, but they are already covered by the DHT22; ammonia is the reading a basic weather station cannot give.
Does the system work without internet or Wi-Fi?
Partly: the sensing, THI computation, fan and mister control and the LCD display all run on the ESP32 itself and keep working with no network at all. Only the web dashboard needs Wi-Fi, since readings travel to it over the local network. If the barn has no Wi-Fi, the system still protects the cows automatically and shows live readings on the LCD; the dashboard can be added later when connectivity is available.
Can this be customised for a real dairy farm?
Yes, within realistic limits: more DHT22 zones can be added for larger sheds, a GSM module can send SMS alerts where there is no Wi-Fi, and the thresholds can be tuned for the local breed and climate. A DS18B20 probe can also log water-trough temperature. What cannot be added by tweaking alone is a claim the system is certified for commercial farm use — that would need calibrated sensors, a weatherproof enclosure and veterinary sign-off.
Components & software requirements
- ESP32 dual-core microcontroller with Wi-Fi
- DHT22 temperature-humidity sensor
- MQ-137 ammonia sensor module
- Arduino IDE with C++ firmware
- 16x2 LCD display
- Relay module with 12 V exhaust fans
- HTML · CSS · JavaScript dashboard
- DS18B20 temperature probe (optional)
Delivery information
Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.
Support terms
Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.
Download free synopsis (PDF)
Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.