edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
Chuk Joseph
Published

Ysigen's Spoilage Detection PoC

This project looks at the problem of food spoilage, specifically temperature and humidity and serves as a precursor to ongoing R&D.

BeginnerWork in progress48
Ysigen's Spoilage Detection PoC

Things used in this project

Story

Read more

Code

Smart Crop Guard: Raspberry Pi Code and Setup

Python
This Python script is the core of the "Smart Crop Guard" project, designed to run on a Raspberry Pi and monitor environmental conditions using a DHT-series temperature and humidity sensor. It implements the critical logic for detecting conditions that could lead to food spoilage.

Prerequisites

Before running the code, you must install the necessary library on your Raspberry Pi.

1.
Install Python Development Tools: ```bash sudo apt-get update sudo apt-get install build-essential python3-dev ```

2.
Install the Adafruit DHT Sensor Library: This library handles the communication with the sensor. ```bash pip3 install Adafruit_DHT ```
while True:
    # Attempt to read sensor data
    # read_retry handles occasional sensor read failures
    humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, GPIO_PIN)

    if humidity is not None and temperature is not None:
        # Data successfully read
        current_time = datetime.datetime.now().strftime("%H:%M:%S")
        
        print(f"[{current_time}] Temp: {temperature:.1f}°C | Humidity: {humidity:.1f}%")

        # Check for threshold breach (Humidity > 4% AND Temp > 12°C)
        if humidity > HUMIDITY_THRESHOLD and temperature > TEMP_THRESHOLD:
            trigger_alert(temperature, humidity)
        
    else:
        # Failed to read sensor data
        print("Error: Failed to retrieve data from sensor. Check wiring.")

    # Wait for 60 seconds before the next reading
    time.sleep(60)

Credits

Chuk Joseph
2 projects • 0 followers
Software and Hardware development for COE Farming and Ysigen

Comments