import machine
import time
import dht
# Initialize DHT11 sensor on GPIO15
dht11_sensor = dht.DHT11(machine.Pin(15))
# Initialize LDR on ADC pin GP26 (A0)
ldr = machine.ADC(machine.Pin(26)) # GPIO 26 is the ADC pin A0 on Pico
# Define calibrated baseline and thresholds for raw meat/fish
BASELINE_LDR = 800 # Calibrated baseline for fresh meat/fish
HUMIDITY_THRESHOLD = 80 # %RH for spoilage risk
TEMPERATURE_THRESHOLD = 25 # Celsius for spoilage risk
while True:
try:
temperature =int(input("Temperature:")) # Temperature in Celsius
humidity =int(input("Humidity:")) # Humidity in percentage
# LDR Reading
ldr_value =int(input("Ldr value:")) # Higher resolution reading
# Print sensor readings
print(f"Temperature: {temperature}°C")
print(f"Humidity: {humidity}%")
print(f"LDR Value: {ldr_value}")
# Spoilage Detection Logic
warnings = []
if humidity > HUMIDITY_THRESHOLD:
print("Warning: High Humidity Detected (Spoilage Risk)")
if temperature > TEMPERATURE_THRESHOLD:
print("Warning: High Temperature Detected (Spoilage Risk)")
if ldr_value < (BASELINE_LDR - 100): # Reduced reflectivity due to spoilage
print("Warning: Light Intensity Drop Detected (Possible Spoilage)")
# Print warnings
if warnings:
print("Warnings:")
for warning in warnings:
print(f"- {warning}")
else:
print("No spoilage detected.")
# Wait for a second before the next reading
time.sleep(1)
except Exception as e:
print(f"Error: {e}")