DIY Stale Food Detector Using Arduino UNO
by Innovator_Abhishek in Living > Health
359 Views, 4 Favorites, 0 Comments
DIY Stale Food Detector Using Arduino UNO
In our fast-moving world, it is not rare that people, particularly those with demanding jobs, may sometimes forget if their food has gone bad. It is a problem often faced by medical practitioners doing long shifts at hospitals, such as interns. Prolonged work tends to numb human senses, especially smell making it difficult for them to tell when food has gone bad. This can cause diseases like food poisoning.
The birth of this project, The Stale Food Detector, occurred after an incident where a trainee doctor fell sick unknowingly ingesting spoilt food from his tiffin carrier. An emergency situation that showed something that urgently needed attention – how could you ever know whether your meal was fresh because at times you might be just too tired to determine this?
The Stale Food Detector addresses this issue. It’s a specially made tiffin with the capability of detecting and indicating if its content is stale so as to prevent possible health problems in return.
Supplies
- Arduino UNO ( or any Arduino)
- LEDs (Two pin *Preferably red*
- MQ-4 ( Methane gas sensor )
- DHT-11 (Temperature and humidity sensor)
Knowing the Principle
As food decays, it releases gases such as ethanol, and methane which are detectable by the MQ3 sensor, and the MQ4 respectively. These sensors translate gas concentration into a corresponding voltage output. This voltage output is then fed to the Arduino's analog pin, utilizing its built-in ADC to convert the analog value into a digital format for further processing. Through these sensors, we are trying to measure the value of Methane concentration in the tiffin box and then determine if the food is safe for consumption. According to some research, it is observed that food articles with methane activity above 250 ppm is not safe for consumption. There are 3 LEDs in this module instead of attaching a display. It is programmed such that if all three LEDs light up the methane concentration in the box is above 250ppm, If two LEDs light up the methane value is more than 170ppm two LEDs will glow, and if the methane value is 150ppm, only one LED will glow. These values were chosen on basis of observations done for weeks.
P.S.:- The LEDs are connected in an unconventional manner due to a soldering error, which is accounted for in the code logic.
Here is a video for its demonstration
Downloads
Connection of Pins
The circuit can be attached to any tiffin box with pins as
- GND: Connected to the GND pins of the MQ-2 and DHT-22 sensors.
- 3.3V: Powers the DHT-22 sensor and all three red LEDs.
- 5V: Powers the MQ-2 sensor.
- A0: Receives the analog output from the MQ-2 sensor.
- D4: Connected to the DATA pin of the DHT-22 sensor.
- A5, A4, A3: Connected to the cathodes of the three red LEDs.
MQ-4 Gas Sensor
- Vcc: Connected to the 5V output on the Arduino UNO.
- GND: Connected to the GND on the Arduino UNO.
- AO: Connected to the A0 pin on the Arduino UNO.
DHT-11 Sensor
- VCC: Connected to the 3.3V output on the Arduino UNO.
- GND: Connected to the GND on the Arduino UNO.
- DATA: Connected to the D4 pin on the Arduino UNO.
LED: Two Pin (red)
- Anode: All anodes are connected to the 3.3V output on the Arduino UNO.
Cathode: Each cathode is connected to a separate pin on the Arduino UNO (A5, A4, A3).
Writing Code
//I have accidently soldered the positive pole of LED togeather and opposite the normal configuration
// Apologies for the incovinience if you solder them correctly *just replace the LOW with HIGH and HIGH with LOW*
#include <DHT11.h>
DHT11 DHT11(4);
const int AO_Pin = 0; // Connect the AO of MQ-4 sensor with analog channel 0 pin (A0) of Arduino
const int ledpin1 = A5;
const int ledpin2 = A4;
const int ledpin3 = A3; // Connecting led to analog pin
int Methane; // Create a variable to store the analog output of the MQ-4 sensor
int delayT = 100;
// Set up
void setup() {
pinMode(AO_Pin, INPUT);
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, LOW);
digitalWrite(ledpin3, LOW);
delay(delayT);
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, HIGH);
digitalWrite(ledpin3, HIGH);
delay(delayT);
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, LOW);
digitalWrite(ledpin3, LOW);
delay(delayT);
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, HIGH);
digitalWrite(ledpin3, HIGH);
delay(delayT);
// Whenever you start the Smart tiffin LED blinks for two times
Serial.begin(9600); // Initialize serial monitor using a baud rate of 9600
}
// Main loop
void loop() {
int temperature = 0;
int humidity = 0;
int result = DHT11.readTemperatureHumidity(temperature, humidity);
{
Serial.print("Temperature:");
Serial.print(temperature);
Serial.print("°C\tHumidity:");
Serial.print(humidity);
Serial.println("%");
Methane = analogRead(AO_Pin); // Read the analog output measurement sample from the MQ4 sensor's AO pin
Serial.print("Methane Conentration:"); // Print out the text "Methane Concentration: "
Serial.println(Methane);
}
if (Methane > 250) {
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, LOW);
digitalWrite(ledpin3, LOW); //Whenever food produces methane above 250 the food is not edible
// Whenever Methane levels are above 250 all three leds will glow
} else {
if (170 < Methane ) {
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, LOW);
digitalWrite(ledpin3, HIGH);
// Whenever Methane levels are above 170 two leds will glow
} else {
if (150 < Methane) {
digitalWrite(ledpin1, LOW);
digitalWrite(ledpin2, HIGH);
digitalWrite(ledpin3, HIGH);
} else {
digitalWrite(ledpin1, HIGH);
digitalWrite(ledpin2, HIGH);
digitalWrite(ledpin3, HIGH); // If methane level is more than 150 one led will glow and if it is below 150 no led will glow
//If no led glows it shows that food is edible
//all three leds glowing means the food is inedible
//two leds means it is on the verge of getting spoiled
}
}
}
delay(100);
}
Future
Next Steps for Stale Food Checker Project
The Stale Food Checker, a new way to keep food safe, has lots of room for more work. Here are some ways to make it even better:
More Sensors: Adding new and better sensors could help find stale food more accurately. Sensors that can find changes in pH or some types of germs could give a fuller look at how fresh the food is.
Guessing the Future: We could add machine learning that learns to guess when the food will go bad. This would help people plan meals and keep safe from bad food.
Humidity and Heat Info: Heat and wet air can change how fresh food is. If we put info from humidity and temperature sensors in the device, we could give better news on food freshness for each place.
Food-Specific Plans: Each kind of food spoils in a different way and time. If we make plans that think about the type of food, we could find bad food more well.
Easy News: The device could tell the user through their phone when the food is bad. This means the user can know at once, even if they are not near the food.
These new plans want to make the Stale Food Checker a strong tool for food safety and help folks eat better and be well. The future of this work can change how we eat and think of food, and has lots of fun stuff in store.