
Description
Even though food irradiation improves food hygiene, spoilage reduction, and extension of shelf-life, it should be regulated strictly to avoid any health risks and nutritional value drops. However, small businesses in the food industry lack a budget-friendly and simple way to detect food irradiation doses after treating food with ionizing energy, especially for animal (livestock) feed. Therefore, I decided to build an AI-driven IoT device predicting food irradiation doses based on weight, color (visible light), and emitted ionizing radiation. Ionizing radiation is a nonthermal process utilized to achieve the preservation of food. At a maximum commercial irradiation dose of 10 kGy, irradiation does not impart heat to the food, and the nutritional quality of the food is generally unaffected. The irradiation process can reduce the microbial contamination of food, resulting in improved microbial safety as well as the extended shelf-life of the food[^1]. Irradiation also benefits the consumer by reducing the risk of severe health issues caused by foodborne illnesses. Food irradiation has three categories: low-dose (radurization), medium-dose (radicidation), and high-dose (radappertization). Low dose irradiation (under 1 kGy) inhibits the sprouting of produce (onion, potato, and garlic); retards the ripening and fungi deterioration of fruits and vegetables (strawberry, tomato, etc.), and promotes insect disinfestations in cereals and vegetables. Medium dose irradiation (between 1 and 10 kGy) controls the presence of pathogenic organisms, especially in fruit juices; retards the deterioration of fish and fresh meat; and reduces Salmonella in poultry products, similar to pasteurization. High dose irradiation (over 10 kGy) is rather significant to the sterilization of health and personal hygiene products[^2]. Since foods treated with ionizing radiation should be adequately labeled under the general labeling requirements, consumers can make their own free choice between irradiated and non-irradiated food. However, unfortunately, some countries do not apply strict regulations for irradiated foods, especially for animal feed. Therefore, detecting proper irradiation doses can be arduous for small businesses in the food industry due to governments not incentivizing strictly regulated food irradiation processes. Since irradiation can engender certain alterations that can modify the chemical composition and nutritive values of food, depending on the factors such as irradiation dose, food composition, packaging, and processing conditions such as temperature and atmospheric oxygen saturation[^2], unsupervised food irradiation portends health issues. After scrutinizing recent research papers on food irradiation, I decided to utilize ionizing radiation, weight, and visible light (color) measurements denoting the applied irradiation dose so as to create a budget-friendly and accessible device to predict food irradiation dose levels in the hope of assisting small businesses in checking compliance with existing regulations on food irradiation. Although ionizing radiation, weight, and visible light (color) measurements provide insight into detecting food irradiation doses, it is not possible to conclude and interpret food irradiation doses precisely by merely employing limited data without applying complex algorithms since food irradiation dose levels fluctuate depending on processing techniques, food characteristics, and equipment. Therefore, I decided to build and train an artificial neural network model by utilizing the theoretically assigned food irradiation dose classes to predict food irradiation dose levels based on ionizing radiation, weight, and visible light (color) measurements. Since I could not apply ionizing radiation directly to foods by emitting Gamma rays, X-rays, or electron beams, I exposed foods to sun rays as a natural source of radiation for estimated periods. Since Beetle ESP32-C3 is an ultra-small size development board intended for IoT applications, that can easily collect data and run my neural network model after being trained to predict food irradiation doses, I decided to employ Beetle ESP32-C3 in this project. To obtain the required measurements to train my model, I utilized a Geiger counter module (Gravity), an I2C weight sensor (Gravity), and an AS7341 11-channel visible light sensor (Gravity). Since Beetle ESP32-C3 is equipped with an expansion board providing the GDI display interface, I connected an SSD1309 OLED transparent screen (Fermion) to display the collected data. After collecting data successfully, I developed a PHP web application that obtains the transmitted data from Beetle ESP32-C3 via HTTP GET requests, logs the received measurements in a given MySQL database table, and lets the user create appropriately formatted samples for Edge Impulse. After completing my data set and creating samples, I built my artificial neural network model (ANN) with Edge Impulse to make predictions on food irradiation dose levels (classes) based on ionizing radiation, weight, and visible light (color) measurements. Since Edge Impulse is nearly compatible with all microcontrollers and development boards, I had not encountered any issues while uploading and running my model on Beetle ESP32-C3. As labels, I employed the theoretically assigned food irradiation dose classes for each data record while collecting and logging data:- Regulated
- Unsafe
- Hazardous

image

image

image

image

image

image
image
Step 1: Designing and printing a Hulk-inspired structure
Since this project is for detecting irradiation doses of foods treated with ionizing radiation, I got inspired by the most prominent fictional Gamma radiation expert, Bruce Banner (aka, The Incredible Hulk), to design a unique structure so as to create a robust and compact device flawlessly operating while collecting data from foods. To collect data with the visible light sensor at different angles, I added a movable handle to the structure, including a slot and a hook for hanging the sensor. I designed the structure and its movable handle in Autodesk Fusion 360. You can download their STL files below.image
image
image
image
image
image
image
image
- eMarble Natural
- Peak Green

image

image

image

image

image

image

image

image
image
image
Step 1.1: Assembling the structure and making connections & adjustments

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image
Step 2: Developing a web application in PHP to collate data on food irradiation doses
To be able to log and process data packets transmitted by Beetle ESP32-C3, I decided to develop a web application in PHP named food_irradiation_data_logger. As shown below, the web application consists of two folders and five files:- /assets
-
- class.php
-
- icon.png
-
- index.css
- /data
- get_data.php
- index.php
- Regulated.training.sample_101.csv
- Unsafe.training.sample_542.csv
- Hazardous.training.sample_152.csv
image
image
image
image
image
image
Step 3: Setting up a LAMP web server on Raspberry Pi
Since I decided to host my web application on a Raspberry Pi 3, I needed to set up a LAMP web server. :hash: First of all, open a terminal window by selecting Accessories ➡ Terminal from the menu. :hash: Then, install the apache2 package by typing the following command into the terminal and pressing Enter: sudo apt-get install apache2 -y
image

image

image

image

image
- upload_max_filesize
- max_file_uploads

image
Step 3.1: Creating a MySQL database in MariaDB
Since I needed to log measurements transmitted by Beetle ESP32-C3 so as to create appropriately formatted samples for Edge Impulse, I also set up a MariaDB server on Raspberry Pi 3. :hash: First of all, install the MariaDB (MySQL) server and PHP-MySQL packages by entering the following command into the terminal: sudo apt-get install mariadb-server php-mysql -y
image

image

image
Step 3.2: Setting and running the web application on Raspberry Pi
As discussed above, I set up a LAMP web server on my Raspberry Pi 3 to run the web application, but you can run it on any server as long as it is a PHP server. :hash: First of all, install and extract the food_irradiation_data_logger.zip folder.
image

image

image

image

image

image

image

image

image

image

image

image

image
Step 4: Setting up Beetle ESP32-C3 on the Arduino IDE
Before proceeding with the following steps, I needed to set up Beetle ESP32-C3 on the Arduino IDE and install the required libraries for this project. If your computer cannot recognize Beetle ESP32-C3 when plugged in via a USB cable, connect Pin 9 to GND (pull-down) and try again. :hash: To add the ESP32-C3 board package to the Arduino IDE, navigate to File ➡ Preferences and paste the URL below under Additional Boards Manager URLs. https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package\_esp32\_index.json.png?fit=max&auto=format&n=577XzA-QE9Zpi0WI&q=85&s=6853fd172baa059e47a927f8c42cfc1c)
image

image
.png?fit=max&auto=format&n=577XzA-QE9Zpi0WI&q=85&s=d9dd78144a45783d7aace0861d02bf67)
image
.png?fit=max&auto=format&n=577XzA-QE9Zpi0WI&q=85&s=2f71270f8dbe72f085f3089b2d45f44a)
image

image

image
Step 4.1: Displaying images on the SSD1309 transparent OLED screen
To display images (monochrome) on the SSD1309 transparent OLED screen successfully, I needed to convert PNG or JPG files into the XBM (X Bitmap Graphic) file format. :hash: First of all, download GIMP. :hash: Then, upload an image (black and white) and go to Image ➡ Scale Image… to resize the uploaded image.
image

image

image

image

image

image
Step 5: Collecting and storing food irradiation data w/ Beetle ESP32-C3
After setting up Beetle ESP32-C3 and installing the required libraries, I programmed Beetle ESP32-C3 to collect ionizing radiation, weight, and visible light (color) measurements in order to store them on the MySQL database and create appropriately formatted samples for Edge Impulse.- CPM (Counts per Minute)
- nSv/h (nanoSieverts per hour)
- μSv/h (microSieverts per hour)
- Weight (g)
- F1 (405 - 425 nm)
- F2 (435 - 455 nm)
- F3 (470 - 490 nm)
- F4 (505 - 525 nm)
- F5 (545 - 565 nm)
- F6 (580 - 600 nm)
- F7 (620 - 640 nm)
- F8 (670 - 690 nm)
- Control Button (A) ➡ Regulated
- Control Button (B) ➡ Unsafe
- Control Button (C) ➡ Hazardous
- eF1F4ClearNIR
- eF5F8ClearNIR
image
image
image
image
image
Step 5.1: Logging the collected data into the MySQL database
After uploading and running the code for collecting data and transmitting data packets to the web application on Beetle ESP32-C3: ☢:bento: The device waits for the Wi-Fi module to connect to the given Wi-Fi network.
image
- WEIGHT (g)
- F1 (405 - 425 nm)
- CPM (Counts per Minute)

image

image

image
- Control Button (A) ➡ Regulated [0]
- Control Button (B) ➡ Unsafe [1]
- Control Button (C) ➡ Hazardous [2]

image

image
image
image
image

image
Step 5.2: Creating samples from data records with the web application
After logging ionizing radiation, weight, and visible light (color) measurements in the MySQL database from a motley collection of foods, exposed to sun rays as a natural source of radiation for estimated periods, I elicited my data set with eminent validity. 📌Foods:- Pasta
- Corn kernel
- Herb
- Apple
- Wheat
- Animal (livestock) feed

image

image

image

image

image

image

image
image
image
image
image
image
image
image
image
image
Step 6: Building a neural network model with Edge Impulse
When I completed collating my food irradiation dose data set and assigning labels, I had started to work on my artificial neural network model (ANN) to make predictions on food irradiation dose levels (classes) based on ionizing radiation, weight, and visible light (color) measurements. Since Edge Impulse supports almost every microcontroller and development board due to its model deployment options, I decided to utilize Edge Impulse to build my artificial neural network model. Also, Edge Impulse makes scaling embedded ML applications easier and faster for edge devices such as Beetle ESP32-C3. Even though Edge Impulse supports CSV files to upload samples, the data type should be time series to upload all data records in a single file. Therefore, I needed to follow the steps below to format my data set so as to train my model accurately:- Data Scaling (Normalizing)
- Data Preprocessing
- 0 — Regulated
- 1 — Unsafe
- 2 — Hazardous
Step 6.1: Uploading samples to Edge Impulse
After generating training and testing samples successfully, I uploaded them to my project on Edge Impulse. :hash: First of all, sign up for Edge Impulse and create a new project.image

image

image
image
image
image
image
image
image
Step 6.2: Training the model on food irradiation dose levels
After uploading my training and testing samples successfully, I designed an impulse and trained it on food irradiation dose levels (classes). An impulse is a custom neural network model in Edge Impulse. I created my impulse by employing the Raw Data block and the Classification learning block. The Raw Data block generate windows from data samples without any specific signal processing. The Classification learning block represents a Keras neural network model. Also, it lets the user change the model settings, architecture, and layers. :hash: Go to the Create impulse page. Then, select the Raw Data block and the Classification learning block. Finally, click Save Impulse.image
image
image
image
image
image
- Number of training cycles ➡ 50
- Learning level ➡ 0.0006
- Validation set size ➡ 10
- Dense layer (64 neurons)
- Dense layer (32 neurons)
image
image
Step 6.3: Evaluating the model accuracy and deploying the model
After building and training my neural network model, I tested its accuracy and validity by utilizing testing samples. The evaluated accuracy of the model is 96.30%. :hash: To validate the trained model, go to the Model testing page and click Classify all.image
image
image
image
image
image
Step 7: Setting up the Edge Impulse model on Beetle ESP32-C3
After building, training, and deploying my model as an Arduino library on Edge Impulse, I needed to upload and run the Arduino library on Beetle ESP32-C3 directly so as to create an easy-to-use and capable device operating with minimal latency and power consumption. Since Edge Impulse optimizes and formats signal processing, configuration, and learning blocks into a single package while deploying models as Arduino libraries, I was able to import my model effortlessly to run inferences. :hash: After downloading the model as an Arduino library in the ZIP file format, go to Sketch > Include Library > Add .ZIP Library… :hash: Then, include the IoT_AI-driven_Food_Irradiation_Classifier_inferencing.h file to import the Edge Impulse neural network model.- Press ➡ Run Inference
- Regulated
- Unsafe
- Hazardous
image
image
image
image
image
Step 8: Running the model on Beetle ESP32-C3 to make predictions on food irradiation doses
When the features array (buffer) is full with data items, my Edge Impulse neural network model predicts possibilities of labels (food irradiation dose classes) for the given features buffer as an array of 3 numbers. They represent the model’s “confidence” that the given features buffer corresponds to each of the three different food irradiation dose levels (classes) based on ionizing radiation, weight, and visible light (color) measurements [0 - 2], as shown in Step 6:- 0 — Regulated
- 1 — Unsafe
- 2 — Hazardous
- WEIGHT (g)
- F1 (405 - 425 nm)
- CPM (Counts per Minute)

image

image
- Regulated
- Unsafe
- Hazardous

image

image

image
image
image

image
Videos and Conclusion
Data Collection | IoT AI-driven Food Irradiation Dose Detector w/ Edge Impulse Experimenting with the model | IoT AI-driven Food Irradiation Dose Detector w/ Edge Impulse After completing all steps above and experimenting, I have employed the device to predict and detect food irradiation dose levels of various foods and food packaging so as to check whether they conform to health and safety standards regarding food irradiation.
image
Further Discussions
By applying neural network models trained on ionizing radiation, weight, and visible light (color) measurements in detecting food irradiation dose levels, we can achieve to[^3]: ☢:bento: prevent changes to the packaging that might affect integrity as a barrier to microbial contamination, ☢:bento: avert producing radiolysis products that could migrate into food, affecting odor, taste, and possibly the safety of the food, ☢:bento: preclude inadvertent radiation effects on polymers in food packaging due to competing crosslinking or chain scission reactions.
image