🌏
Quality Assured Publisher
Serving Researchers Since 2012

IoT-Based Food Spoilage Detection System using Ammonia Sensing and Environmental Monitoring

DOI : 10.17577/IJERTV15IS042618
Download Full-Text PDF Cite this Publication

Text Only Version

IoT-Based Food Spoilage Detection System using Ammonia Sensing and Environmental Monitoring

Tushar Mumbre

Student, B.Tech. Dept. of Electronics and Telecommunication Engg. K. J. Somaiya Institute of Technology, Mumbai, India

Tejas Salunkhe

Student, B.Tech. Dept. of Electronics and Telecommunication Engg. K. J. Somaiya Institute of Technology, Mumbai, India

Prof. Rupali Kadu

Professor, Dept. of Electronics and Telecommunication Engg. K. J. Somaiya Institute of Technology, Mumbai, India

Abstract – Unsafe food reaching consumers due to unnoticed spoilage remains a major issue in todays food supply chain, leading to both health concerns and financial losses. Traditional laboratory-based methods for checking food quality are often destructive and do not support continuous, real-time monitoring. This paper presents an IoT-based food spoilage detection system developed using an ESP32 microcontroller, an MQ137 ammonia gas sensor, and a DHT22 temperature and humidity sensor. A key aspect of this system is its self-contained web dashboard, which is hosted directly on the ESP32 via Wi-Fi, removing the need for any external cloud platforms. In addition, the system periodically sends sensor data to a Google Sheets document every 15 seconds using a Google Apps Script, enabling remote access and long-term data storage. Experimental testing with curd samples stored at different temperatures showed a clear and consistent increase in ammonia levels as spoilage progressed. This confirms that ammonia (NH) can be effectively used as an indicator of food freshness in real time. Overall, the proposed system is cost-effective, easy to deploy, and suitable for applications in food storage, transportation, and retail environments.

Keywords – Food Spoilage Detection, Internet of Things (IoT), Ammonia Sensor, MQ137, DHT22, ESP32, Web Dashboard, Google Sheets, Real-Time Monitoring.

  1. INTRODUCTION

    Globally, an estimated one-third of all food produced for human consumption is lost or wasted each year, with microbial spoilage during post-harvest handling being a primary contributor [1]. Beyond the direct economic burden, spoiled food entering the supply chain introduces serious public health hazards, particularly through foodborne pathogens that proliferate during protein degradation.

    Assessing whether food is still fit for consumption has long relied on labour-intensive laboratory procedures. Microbiological culture tests, chemical titration, and trained sensory panels provide accurate results but are unsuitable for deployment in warehouses, refrigerated trucks, or retail cold chains where decisions must be made quickly and non-destructively [2]. The absence of continuous, automated monitoring means deterioration often goes unnoticed until spoilage is visually or aromatically obvious.

    When proteins break down under microbial action, a characteristic suite of volatile gases is produced. NH is one of the earliest and most reliably detectable of these biomarkers, with its atmospheric concentration climbing steadily as bacterial colonies expand [4]. This property makes ammonia sensing a particularly attractive approach for non-invasive food quality assessment, since measurements can be taken repeatedly without disturbing the food sample.

    The rapid maturation of low-power microcontrollers, affordable MEMS gas sensors, and ubiquitous Wi-Fi connectivity has made it practical to embed continuous monitoring capability directly into food storage environments

    [8]. The present work exploits these advances by building a compact, self-hosted monitoring node on an ESP32 platform. Uniquely, all data visualisation is handled by a browser-accessible dashboard generated by the ESP32 itself, and every sensor reading is automatically archived in Google Sheets for downstream analysiswith no subscription-based cloud infrastructure required.

  2. RELATED WORK

    The intersection of chemical sensing and food safety has generated a substantial body of literature over the past two decades [2], [3]. Resistive metal oxide semiconductor (MOS) transducers have become a favoured building block in this space because their fabrication costs are modest, their sensitivity to trace VOCs is high, and they interface readily with standard microcontroller ADC peripherals [6].

    Investigations into ammonia and biogenic amine markers have repeatedly validated their predictive power for estimating shelf life in seafood and meat products [4]. Researchers found that measured gas concentrations track bacterial load closely across distinct freshness categories, establishing a practical calibration basis for threshold-based alert systems. A recurring limitation in single-sensor designs, however, is their inability to account for the accelerating effect that elevated temperature and relative humidity exert on microbial proliferation [12].

    Networked food monitoring platforms that transmit data to centralised cloud dashboards have been widely reported, with a typical focus on cold-store temperature logging [8]. While such systems perform well for bulk storage auditing, they do not provide chemical indicators of actual spoilage

    onset, and their reliance on commercial cloud subscriptions introduces both cost and privacy considerations. At the high end of detection sophistication, e-nose arrays paired with machine-learning classifiers [3], [9], [10] achieve excellent discrimination between freshness grades but remain too complex and costly for routine deployment.

    The design presented here occupies a practical middle ground: a single, well-characterised ammonia sensor is combined with ambient condition monitoring on a commodity Wi-Fi module [7]. The key architectural departure from prior work is the elimination of cloud middlementhe ESP32 itself serves the monitoring interface and delegates long-term storage to Google Sheets, which is universally accessible and requires no dedicated server infrastructure.

  3. SYSTEM ARCHITECTURE

    Fig. 1 depicts the overall structure of the proposed platform. Data originates at two sensor nodes, passes through the ESP32 for conditioning and classification, and is then made available concurrently through a local web interface and a remote spreadsheet. The design is partitioned into three functional tiers: data acquisition, edge processing with connectivity, and end-user presentation.

    Fig. 1. System architecture showing DHT22 and MQ137 sensors connected to the ESP32 controller (WiFi + ADC), with custom web dashboard and buzzer alert outputs.

    1. Sensing Layer

      Gas-phase NH is sampled by the MQ137 chemiresistive sensor, whose resistance varies inversely with ammonia concentration, producing a raw voltage at the ESP32 ADC input. Ambient temperature and relative humidity are captured simultaneously by the calibrated DHT22 digital sensor, providing the environmental context needed to interpret gas readings accurately.

    2. Processing and Communication Layer

      Acting as the systems central node, the ESP32 handles ADC sampling, applies a piecewise linear conversion to derive PPM estimates, evaluates readings against user-defined alarm boundaries, and manages Wi-Fi connectivity. A lightweight HTTP server embedded in firmware delivers the monitoring dashboard to any browser on the local network, removing the requirement for external hosting.

    3. Data Visualization and Alert Layer

    The ESP32-hosted dashboard renders nimated gauge dials, scrolling trend charts, and a colour-coded spoilage status panel. Users can adjust threshold values and toggle the alert buzzer directly from the browser. In parallel, a background task assembles a structured HTTPS payload every 15 seconds and forwards it to Google Sheets, where each entry is timestamped and appended as a new row for long-term trending.

  4. METHODOLOGY

    System operation follows the workflow illustrated in Fig.

    2. Sensor signals are acquired every two seconds, digitised, converted to engineering units, and assessed against configurable limits. Results are then pushed simultaneously to the local dashboard and, at a slower cadence, to the cloud spreadsheet.

    Fig. 2. Operational workflow showing sensor acquisition, ESP32 processing, custom web dashboard serving, and Google Sheets data logging.

    1. Sensor Interfacing and Data Acquisition

      The MQ137 is wired to GPIO 32, where the ESP32s 12-bit SAR ADC digitises the output over a 04095 count range. Raw counts are linearly scaled to yield an NH estimate in parts-per-million. The DHT22 on GPIO 4 delivers pre-calibrated temperature (°C) and relative humidity (%) figures via a proprietary single-wire protocol. A 2-second polling interval was chosen to balance responsiveness against processor load.

    2. Custom Web Dashboard

      The monitoring interface is a single-page web application compiled into the ESP32 firmware as a PROGMEM constant. When a client browser opens the devices IP address, the ESP32 streams the page, after which the browser polls a lightweight JSON endpoint at /data every two seconds to refresh the display. Implemented features include:

      • Semi-circular animated gauges showing live temperature, humidity, and NH readings

      • Scrolling canvas charts for all three parameters with configurable y-axis scaling

      • Colour-coded status banner: green (Normal), amber (Moderate), red (Danger)

      • In-browser threshold editor with instant firmware-side update via GET request

      • Buzzer override panel supporting manual ON, manual OFF, and automatic mode

      • Running statistics panel: session minimum, maximum, and mean per channel

      • Wi-Fi diagnostic section showing SSID, IP address, and RSSI signal bars

      • Google Sheets sync panel with live connection status and one-click sheet link

      • Persistent dark/light theme preference saved in browser storage

    3. Google Sheets Integration

      A Google Apps Script deployed as a web app receives sensor data and writes it to a designated spreadsheet. The ESP32 forms an HTTPS GET URL that encodes twelve parameters: temperature, humidity, ammonia PPM, alarm flag, buzzer state, three threshold values, Wi-Fi SSID, local IP, and RSSI. The Apps Script handler parses these query parameters and appends a row with an automated timestamp. A 15-second dispatch interval was selected to limit data volume while still capturing short-term trends.

    4. Spoilage Classification

      NH thresholds for classifying food condition were derived from repeated curd and protein sample trials:

      • 010 ppm: Fresh gas levels within background range; food suitable for consumption

      • 10 30 ppm: Borderline elevated microbial activity detected; consume with caution

      • Above 30 ppm: Spoiled significant decomposition confirmed; discard recommended

        Threshold values are stored as runtime variables, allowing operators to tighten or relax alarm boundaries through the dashboard without reflashing the device. Crossing any threshold simultaneously activates the buzzer and updates the dashboard banner, ensuring alerts are visible both locally and remotely.

    5. Sensor Calibration

    Before deployment, the MQ137 was exposed to reference gas mixtures to establish a voltage-to-PPM mapping curve. DHT22 readings were cross-checked against a certified hygrometer and thermometer pair. A software correction factor compensates for the sensitivity drift that occurs when ambient temperature deviates significantly from the sensors rated operating point.

  5. RESULTS AND DISCUSSION

    To validate the sensing platform, fresh curd samples were placed in two environments: an open room held at approximately 25°C, and a refrigerator maintaining 4°C. NH readings were recorded every 2 seconds and logged to Google Sheets over a 14-day observation window. The resulting spoilage curves for both conditions are plotted in Fig. 3.

    Fig. 3. Curd spoilage comparison: NH concentration over 14 days at room temperature (25°C) vs. refrigerated (4°C), showing Normal, Moderate, and Dangerous zones.

    Under ambient conditions the sample transitioned out of the fresh zone within 24 hours. A reading of roughly 24 ppm on day 3 triggered the moderate-level alert, and the dangerous threshold of 30 ppm was breached on day 4. By the seventh day the measured concentration had climbed to approximately 82 ppm, well above any safe consumption threshold.

    Refrigeration dramatically extended the fresh window. The curd remained below 10 ppm through day 6 and did not cross into the moderate zone until around day 10. The 30 ppm spoilage boundary was reached near day 12, and the 14-day endpoint reading of 52 ppm confirmed spoilagethough the progression rate was roughly three times slower than at room temperature.

    These contrasting trajectories directly reflect the relationship between thermal environment and microbial kinetics captured by the DHT22 data stream. Elevated temperature and humidity consistently coincided with steeper NH accumulation gradients, reinforcing the value of monitoring both chemical and environmental parameters together rather than relying on gas sensing alone.

    Throughout the trial the web dashboard updated reliably at 2-second intervals and the Google Sheets log accumulated approximately 3,750 rows per day without connection failures. Operators were able to modify alert thresholds mid-experiment through the browser interface; the firmware applied the new limits on the next polling cycle with no restart required. This live configurability was a practical advantage not present in the earlier Arduino IoT Cloud prototype, which also required an active internet connection and a subscription account.

  6. CONCLUSION AND FUTURE WORK

    A compact, self-contained food spoilage monitor has been developed using commodity IoT hardware. By replacing cloud middleware with a firmware-embedded web server and coupling it with Google Sheets for archival logging, the system achieves genuine operational independence while still supporting remote data access. The ammonia-based detection scheme was validated through a 14-day curd experiment that clearly separated fresh, borderline, and spoiled states across

    two storage temperatures. Going forward, the authors intend to broaden chemical coverage by adding hydrogen sulfide and CO sensors, investigate lightweight on-device neural networks for multi-gas spoilage prediction, and explore LoRaWAN backhaul for deployments in locations where Wi-Fi is unavailable.

  7. ACKNOWLEDGEMENT

The authors acknowledge the support of the Department of Electronics and Telecommunication Engineering, K. J. Somaiya Institute of Technology, Mumbai, for access to laboratory facilities and resources that enabled this work. Guidance provided by faculty members throughout the project is gratefully recognised.

REFERENCES

  1. Food and Agriculture Orgaization of the United Nations (FAO), Global Food Losses and Food Waste Extent, Causes and Prevention, Rome, Italy, 2019.

  2. J. Wang, X. Chen, and Y. Guo, Gas sensor technologies for food quality monitoring: A review, Sensors, vol. 20, no. 18, pp. 123, 2020.

  3. A. Loutfi et al., Electronic noses for food quality: A review, Journal of Food Engineering, vol. 144, pp. 103111, 2015.

  4. M. S. Rahman, M. M. Islam, and M. A. Hossain, Ammonia gas sensing techniques for meat freshness evaluation, Food Control, vol. 109, pp. 106114, 2020.

  5. S. Marco and A. Gutierrez-Galvez, Signal and data processing for machine olfaction and chemical sensing, IEEE Sensors Journal, vol. 12, no. 11, pp. 31893214,

    Nov. 2012.

  6. L. Cheng, Y. Zhang, and X. Li, Application of metal oxide semiconductor gas sensors in food quality monitoring, IEEE Access, vol. 8, pp. 152165, 2020.

  7. Espressif Systems, ESP32 Technical Reference Manual, Shanghai, China, 2022.

  8. A. K. Mishra, A. Dey, and S. Roy, IoT-based smart food monitoring system using gas and environmental sensors, International Journal of Distributed Sensor Networks, vol. 16, no. 5, pp. 112, 2020.

  9. D. G. James et al., Chemical sensors for electronic nose systems, Microchimica Acta, vol. 149, no. 12, pp. 1

    17, 2005.

  10. M. Arshak et al., A review of gas sensors employed in electronic nose applications, Sensor Review, vol. 24, no. 2, pp. 181198, 2004.

  11. K. G. Ong et al., Wireless, passive, resonant-circuit sensors for monitoring food quality, IEEE Sensors Journal, vol. 8, no. 11, pp. 19982004, Nov. 2008.

  12. A. Kumar and G. P. Hancke, Energy efficient environment monitoring system based on the Internet of Things, IEEE Access, vol. 2, pp. 367378, 2014.