HWK F5: Arduino - Meat Spoilage Detector
Building an Arduino system that signals risk of meat spoilage by recording temperature over storage and transportation time.
Alright, let's get techy. Today we quickly go over my dirty and quick-hand Arduino project.
The Idea
I used to tinker with my personal 30$ Arduino set during Covid lockdown out of boredom. Frankly, I never explored all the sensors and tools that the kit has, so there is always something new to try and test. I could make a voice-controlled device to trigger my iphone to take pictures using a servo motor and voice sensor. Or I could build a system to move a light rod along one axis using two stepper motors and a joystick to illuminate objects of interest at different angles.
However, since I am responsible for building prototype electronics for my group’s project to explore challenges and determine what to include in the buying list, I decided to focus on building the spoilage detection system based on temperature.
The Sensors & Elements
I only used the temperature sensor DHT11. It is also capable of sensing humidity, but we don’t have any scientific data to support the effect of humidity on spoilage, so we decided not to include humidity data at this point. This sensor measures temperature best at 0-50 °C temperature range with +-2 °C accuracy. It is a good, low-cost sensor for prototyping in the early stage, but clearly I will need a better sensor with wider working range and higher accuracy within 0.5°C.
To display data, I used both LED lamps and an LCD screen. As a proof of concept, LED lights have green, yellow, and red colors equivalent to an item that is safe to consume, warning when an item needs to be consumed soon, and alert that item is spoiled respectively.
Wiring Diagrams
This project has multiple components that are easier to analyze if they are split into subparts.



Final Design
The spoilage risk is determined by the area under the temperature curve over time with the assumption that there is a linear relationship between temperature and meat spoilage rate. However, this is not the case in real life, so additional research is necessary to determine and code non-linear spoilage thresholding.
In the meantime, I used the area under the curve of storing temperature over advised storage time by FDA. In particular, meat can be stored for 5 days at 40F (fridge temperature), so I used the area is the threshold of spoiling. This is a temporary solution as we are still researching a better way of estimating spoilage using temperature data.



Challenges
I, hate, C language! It was painful working float, int, long int, etc. data types to get calculation accuracy to some extend and prevent unnecessary rounding. Also, some data types are not supported by the display screen, so figuring a workaround was not a simple task as well. I ended up dividing float values by 1000 to not exceed float memory limit.
Hot Takes
I wish I had an Arduino when I was in middle or high school. I was in Vietnam, so kits like this were not popular nor introduced at my schools. It is relatively simple to use and has infinite possible designs and applications that are only limited by my imagination and budget. I find it amazing to use to prototype ideas and to quickly build necessary tools for engineering and research in a cheap and dirty way. The wiring is an annoying part of it since wires are either too long or too large, but it is an acceptable tradeoff for its simplicity.
I don’t like the fact that till now Arduino still doesn’t support Python or some simpler coding interface since C language is extremely time consuming when one has to deal with data types and storage. But I can always use a raspberry Pi that is Python based, but it certainly comes with its own drawbacks.
Relevant Datasheets
Honestly, I did not use any datasheet to figure out wiring components, I used the wiring diagrams that I found from cited sources.
Sources
Arduino LCD Set Up and Programming Guide (circuitbasics.com): LCD set up reference
How to Set Up the DHT11 Humidity Sensor on an Arduino (circuitbasics.com): DTH11 sensor reference
Arduino Traffic Light Simulator - Arduino Project Hub: LEDs setup reference
Potential uses
Well, this device can be used to monitor meat spoilage risks as it is stored and transported (wow!). Storage temperature can vary over time due to power outages or transportation of meat. Ideally, meat should be stored below -18 degree Celsius for 12 months for best freshness and quality, but in reality not all family fridges can reach that temperature, and many households leave meat in the fridge at 4 degree Celsius (40 Fahrenheit) for convenience and tend to forget how long it has been there (at least that was the case for me and other people whom we interviewed). So the ability to monitor temperature over time as meat is stored can be utilized to nonlinearly determine risk of meat spoilage at a point of time.
Code
// calculate area under the curve over second increment until that area reaches
#include <dht.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht DHT;
#define DHT11_PIN 7
// LEDs
int GREEN = 8;
int YELLOW = 9;
int RED = 10;
// designed to work for an hour with 100 data points, recording every time interval, only include data if change T >0.5
int TIME_INTERVAL = 5000; // minute or 30s
float sum = 0;
float MIN_TEMP = -18.0; // reference temperature at which meat can be stored indefinitely
// max area value, using beef value for 5 days at 4.5C at 1 second interval
float MAX_BEEF = (4.5-MIN_TEMP)*86400; //5 days * 24 hours * 60 * 12 intervals per minute
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop(){
int chk = DHT.read11(DHT11_PIN);
float curr_temp = DHT.temperature;
// update sum
sum = (sum + (curr_temp-MIN_TEMP)); // getting area under the curve
Serial.println(000000000);
Serial.println(sum);
Serial.println(curr_temp);
lcd.setCursor(0,0);
lcd.print("Curr Temp ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Score ");
lcd.print(sum/1000.0);
lcd.print("/");
lcd.print(MAX_BEEF/1000.0);
if (sum >= MAX_BEEF) {
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
else if (sum >= MAX_BEEF / 2.0) {
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}
else {
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
delay(TIME_INTERVAL);
}