DIY

Device for determining the ripeness of vegetables and fruits by their color

Device for determining the ripeness of vegetables and fruits by their color This device is designed to determine the ripeness of vegetables and fruits by comparing spectral analysis data with installed templates.
Such an analyzer, with some modifications, can be used, for example, on a farm.

Tools and materials: – Arduino Nano;
-Spectral sensor AS7341 or such;
-Raspberry Pi 3B + or 4;
-10K potentiometer;
-Potentiometer knob; -Tactile button – 4 pcs; -5 mm LED green; -5 mm LED red; -Breadboard; Step one: theory
Thanks to the developed human vision, it is not difficult for us to determine ripeness by the appearance of the fruit or vegetable. However, in case of mass cultivation, ripening control and subsequent sorting of ripe vegetables/fruits from unripe ones, without automation, is rather laborious.
The master decided to make this device to help food companies, grocery stores and farmers in sorting fruits and vegetables. With it, you can determine the stages of ripening by color using a neural network model. As fruits and vegetables ripen, they change color due to four groups of the pigment class:
chlorophyll (green)
carotenoids (yellow, red , orange)
flavonoids: anthocyanins + anthoxanthins (red, blue, purple)
betalains (red, yellow, purple)
These pigments are groups of molecular structures that absorb a specific set of wavelengths and reflect others. Unripe fruits (green) due to chlorophyll in their cells. As it matures, chlorophyll breaks down and is replaced by orange carotenoids and red anthocyanins. These compounds are antioxidants that keep the fruit from spoiling too quickly when exposed to air. Then there is an enzymatic darkening and discoloration – the formation of a brown color. Enzymes act as a catalyst for chemical reactions that cause phenols to discolor.
After doing some research on the processes of color change as fruits and vegetables ripen, the master decided to build an artificial neural network (ANN) to interpret the spectral color of various fruits and vegetables and predict the stages of ripening.
Before building and testing this neural network model, he developed a web application to compare the spectral color data of fruits and vegetables generated by the AS7341 visible light sensor. The master used the Arduino Nano to send the data generated by the visible light sensor to a web application. Based on his observations, he assigned a ripening stage (label) when obtaining spectral color data for each fruit and vegetable:
Early ripening
Partially ripe
Ripe
Overripe
 Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color Step two: web application development
The wizard has developed a web application (Vegetables and Fruits Data Logger) to retrieve spectral color data of fruits and vegetables from AS7341 sensor via Arduino Nano 33 IoT and set this data to a CSV file (spectral_color_database.csv) to create a stage table.
The web application includes one file (index.php) and requires these parameters to insert a new line (record) into the dataset:

  F1 F2 F3 F4 F5 F6 F7 F8 nir_1 nir_2 class  

Next, you need to check if all the necessary parameters are passed to Nano.
If yes, create a data array with the received parameters, including the current date.
We insert the newly created data array into the spectral_color_database.csv file as a new line using the fputcsv function.
Then we write: Data Inserted Successfully!
If there are gaps or no incoming data, we write: Waiting for data from the AS7341 sensor to insert

 # Check the incoming data packet & # 58; if (isset ($ _ GET & # 91; & # 34; F1 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F2 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F3 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F4 & # 34; & # 93;) & amp; & amp; isset ( $ _GET & # 91; & # 34; F5 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F6 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F7 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; F8 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91 ; & # 34; nir_1 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; nir_2 & # 34; & # 93;) & amp; & amp; isset ($ _ GET & # 91; & # 34; class & # 34; & # 93;)) & # 123; # Create the data array. $ data = array ($ _ GET & # 91; & # 34; F1 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F2 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F3 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F4 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F5 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F6 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F7 & # 34; & # 93 ;, $ _GET & # 91; & # 34; F8 & # 34; & # 93 ;, $ _GET & # 91; & # 34; nir_1 & # 34; & # 93 ;, $ _GET & # 91; & # 34; nir_2 & # 34; & # 93 ;, $ _GET & # 91; & # 34; class & # 34; & # 93 ;, date (& # 34; m/d & # 34;)); # Insert the recently generated data array into the CSV file as a new row. $ file = fopen (& # 34; spectral_color_database.csv & # 34 ;, & # 34; a & # 34;); fputcsv ($ file, $ data); fclose ($ file); //Print result & # 58; echo & # 34; Data Inserted Successfully! & # 34 ;; } else & # 123; echo & # 34; Waiting for data from the AS7341 sensor to insert ... & # 34 ;; } < br> First of all, extract the Vegetables_and_Fruits_Data_Logger.zip folder. 
Then move the application folder (Vegetables_and_Fruits_Data_Logger) to the apache server (/var/www/html).
 sudo mv/home/pi/Downloads/Vegetables_and_Fruits_Data_Logger//var/www/html/ 

If the required parameters are not set or found, the web application will write: Waiting for data from the AS7341 sensor to insert ... (Waiting for data from AS7341 sensor to insert)

  http & # 58; //localhost/Vegetables_and_Fruits_Data_Logger/ 

Otherwise, the web application inserts the incoming data as a new line into the CSV file (dataset), appending the current date, and prints: Data Inserted Successfully! (Data inserted successfully!)

  http & # 58; //localhost/Vegetables_and_Fruits_Data_Logger /? F1 = 13 & amp; F2 = 12 & amp; F3 = 12 & amp; F4 = 12 & amp; F5 = 12 & amp; F6 = 12 & amp; F7 = 12 & amp; F8 = 12 & amp; nir_1 = 12 & amp; nir_2 = 9 & amp; class = 0  

Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color Step four: setting up the Arduino Nano
Next, you need to download the necessary drivers - Arduino SAMD Core - as described in this guide.
To be able to connect to Wi-Fi, you need to download the WiFiNINA library.
Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color To be able to receive color data from the AS7341 sensor, you need to install the DFRobot AS7341 library.
Next, you need to enable the necessary libraries and define the WiFi settings.

 char ssid & # 91; & # 93; = & # 34; SSID & # 34 ;; //your network SSID (name) char pass & # 91; & # 93; = & # 34; PASSWORD & # 34 ;; //your network password (use for WPA, or use as key for WEP) int keyIndex = 0; //your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; //Enter the IPAddress of your Raspberry Pi. IPAddress server (192, 168, 1, 20); //Initialize the Ethernet client library WiFiClient client;/* WiFiSSLClient client; */ 

Define the AS7341 visible light sensor settings and objects

  //Define the AS7341 object. DFRobot_AS7341 as7341; //Define AS7341 data objects & # 58; DFRobot_AS7341 & # 58; & # 58; sModeOneData_t data1; DFRobot_AS7341 & # 58; & # 58; sModeTwoData_t data2;  

Detect if I2C can communicate properly while (as7341.begin ()! = 0) & # 123; Serial.println (& # 34; I2C init failed, please check if the wire connection is correct & # 34;); delay (1000); } //Enable the built-in LED on the AS7341 sensor. as7341.enableLed (true);
Test WiFi module to test the connection.

 if (WiFi.status () == WL_NO_MODULE) & # 123; Serial.println (& # 34; Connection Failed! & # 34;); while (true); } //Attempt to connect to the WiFi network & # 58; while (status! = WL_CONNECTED) & # 123; Serial.println (& # 34; Attempting to connect to WiFi !!! & # 34;); //Connect to WPA/WPA2 network. Change this line if using open or WEP network & # 58; status = WiFi.begin (ssid, pass); //Wait 10 seconds for connection & # 58; delay (10000); }  

Read the values ​​of the potentiometer and four class buttons in the read_controls function.

 void read_controls () & # 123; //Potentiometer & # 58; pot_val = analogRead (pot); //Class Buttons & # 58; class_1_val = digitalRead (class_1); class_2_val = digitalRead (class_2); class_3_val = digitalRead (class_3); class_4_val = digitalRead (class_4); }  

In the adjust_brightness function, set the output current for brightness control (from 1 to 20 – corresponds to 4 mA, 6 mA, 8 mA, 10 mA, 12 mA, …… , 42 mA) built-in LED on the AS7341 sensor.
To measure spectrum with AS7341 sensor and read the value of sensor data channel 0 ~ 5 in the following channel display modes:

  eF1F4ClearNIR eF5F8ClearNIR  

Then you need to print the spectral data about color generated by the sensor:

 //Start spectrum measurement & # 58; //Channel mapping mode & # 58; 1.eF1F4ClearNIR as7341.startMeasure (as7341.eF1F4ClearNIR); //Read the value of sensor data channel 0 ~ 5, under eF1F4ClearNIR data1 = as7341.readSpectralDataOne (); //Channel mapping mode & # 58; 2.eF5F8ClearNIR as7341.startMeasure (as7341.eF5F8ClearNIR); //Read the value of sensor data channel 0 ~ 5, under eF5F8ClearNIR data2 = as7341.readSpectralDataTwo (); //Print data & # 58; Serial.print (& # 34; F1 (405-425nm) & # 58; & # 34;); Serial.println (data1.ADF1); Serial.print (& # 34; F2 (435-455nm) & # 58; & # 34;); Serial.println (data1.ADF2); Serial.print (& # 34; F3 (470-490nm) & # 58; & # 34;); Serial.println (data1.ADF3); Serial.print (& # 34; F4 (505-525nm) & # 58; & # 34;); Serial.println (data1.ADF4); Serial.print (& # 34; F5 (545-565nm) & # 58; & # 34;); Serial.println (data2.ADF5); Serial.print (& # 34; F6 (580-600nm) & # 58; & # 34;); Serial.println (data2.ADF6); Serial.print (& # 34; F7 (620-640nm) & # 58; & # 34;); Serial.println (data2.ADF7); Serial.print (& # 34; F8 (670-690nm) & # 58; & # 34;); Serial.println (data2.ADF8); //CLEAR and NIR & # 58; Serial.print (& # 34; Clear_1 & # 58; & # 34;); Serial.println (data1.ADCLEAR); Serial.print (& # 34; NIR_1 & # 58; & # 34;); Serial.println (data1.ADNIR); Serial.print (& # 34; Clear_2 & # 58; & # 34;); Serial.println (data2.ADCLEAR); Serial.print (& # 34; NIR_2 & # 58; & # 34;); Serial.println (data2.ADNIR); Serial.print (& # 34;  n ------------------------------  n & # 34;); delay (1000);  

Now you need to set a label/number for each class:
0 – Early ripe
1 – Partially ripe
2 – Ripe
3 – Overripe

 if (! class_1_val) make_a_get_request (& # 34;/Vegetables_and_Fruits_Data_Logger/& # 34 ;, & # 34; 0 & # 34;); if (! class_2_val) make_a_get_request (& # 34;/Vegetables_and_Fruits_Data_Logger/& # 34 ;, & # 34; 1 & # 34;); if (! class_3_val) make_a_get_request (& # 34;/Vegetables_and_Fruits_Data_Logger/& # 34 ;, & # 34; 2 & # 34;); if (! class_4_val) make_a_get_request (& # 34;/Vegetables_and_Fruits_Data_Logger/& # 34 ;, & # 34; 3 & # 34;);  

Connect to the application, set maturity marks and connect red LED.

 void make_a_get_request (String application, String _class) & # 123; //Connect to the web application named Vegetables_and_Fruits_Data_Logger. Change & # 39; 80 & # 39; with & # 39; 443 & # 39; if you are using SSL connection. if (client.connect (server, 80)) & # 123; //If successful & # 58; Serial.println (& # 34;  n  nConnected to the server! & # 34;); //Create the query string & # 58; String query = application + & # 34;? F1 = & # 34; + data1.ADF1 + & # 34; & amp; F2 = & # 34; + data1.ADF2 + & # 34; & amp; F3 = & # 34; + data1.ADF3 + & # 34; & amp; F4 = & # 34; + data1.ADF4 + & # 34; & amp; F5 = & # 34; + data2.ADF5 + & # 34; & amp; F6 = & # 34 ; + data2.ADF6 + & # 34; & amp; F7 = & # 34; + data2.ADF7 + & # 34; & amp; F8 = & # 34; + data2.ADF8 + & # 34; & amp; nir_1 = & # 34; + data1.ADNIR + & # 34; & amp; nir_2 = & # 34; + data2.ADNIR + & # 34; & amp; class = & # 34; + _ class; //Make an HTTP Get request & # 58; client.println (& # 34; GET & # 34; + query + & # 34; HTTP/1.1 & # 34;); client.println (& # 34; Host & # 58; 192.168.1.20 & # 34;); client.println (& # 34; Connection & # 58; close & # 34;); client.println (); } else & # 123; Serial.println (& # 34; Server Error! & # 34;); digitalWrite (red, HIGH); } delay (2000); //Wait 2 seconds after connection ... //If there are incoming bytes available, get the response from the web application. String response = & # 34; & # 34 ;; while (client.available ()) & # 123; char c = client.read (); response + = c; } if (response! = & # 34; & # 34;) & # 123; Serial.println (response); Serial.println (& # 34;  n & # 34;); //Check whether the transferred data is inserted successfully or not & # 58; if (response.indexOf (& # 34; Data Inserted Successfully! & # 34;) & gt; 0) & # 123; digitalWrite (green, HIGH); } else & # 123; digitalWrite (red, HIGH); }} //Turn off LEDs & # 58; delay (3000); digitalWrite (green, LOW); digitalWrite (red, LOW); }  

Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color Step Five: Create a Spectral Color Maturation Stages Dataset
To train this neural network model on spectral color ripening stages, you had to collect spectral color data for various fruits and vegetables. The master uses the AS7341 sensor for this.
This sensor uses the new generation AS7341 spectral sensor chip from the renowned AMS company. It has eight channels for visible light, one channel for near infrared (NIR), one channel without filter (Clear) and an additional channel distributed by the flicker of ambient light (Flicker). In addition, it has six parallel 16-bit ADC channels for signal and data processing. With two built-in dimmable LEDs, it can collect data even in the dark.
After doing some research, the wizard collected the parameters below using the AS7341 visible light sensor:
F1 (405-425nm)
F2 (435-455nm)
F3 (470-490nm)
F4 (505-525nm )
F5 (545-565nm)
F6 (580-600nm)
F7 (620-640nm)
F8 (670-690nm)
Clear_1
NIR_1
Clear_2 < br> NIR_2
As explained in the previous step, the wizard connected an AS7341 sensor to the Arduino Nano 33 IoT to send parameters and assigned maturation marks to the web application. After receiving the data, the web application inserts the required parameters by adding the current date parameter to the spectral_color_database.csv file (dataset) under these lines:
F1
F2
F3
F4
F5
F6
F7
F8
NIR_1
NIR_2
Ripeness
Date
After finishing programming and assembling the device, he chose eleven different fruits and vegetables to collect their spectral ripeness classes. color.
The device allows the user to send data to the web application and assign a ripeness class (label) by pressing one of the four class buttons:
0 – Early ripe
1 – Partially ripe
2 – Ripe
3 – Overripe
For each fruit and vegetable, he compared the spectral color data and the assigned ripeness class for ten days, three times a day.
The device allows the user to adjust the brightness of the built-in LED on the AS7341 sensor using a potentiometer.
If the transferred data has been successfully inserted into the data record, the green LED on the device will light up. Otherwise, the red LED will turn on.
Finally, after collecting ripeness classes by spectral color three times a day for ten days, he extracted a dataset (spectral_color_database.csv) to train the neural network.
 Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color Step Six: Create an Artificial Neural Network (ANN) with TensorFlow
Next, the wizard creates and trains a neural network for this device. Its purpose is to teach the device not only to determine ripeness, but also to predict the stages of ripening. More details about this step can be found here.
The complete code can be downloaded here.
Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color Step seven: connection and adjustment
First, the wizard installs on the Arduino Nano 33 IoT development board. It then sets up four class buttons to assign a maturity class (Early Ripe, Parically Ripe, Ripe, Decay) when sending data to the web application. The wizard used a potentiometer to adjust the brightness of the built-in LED on the AS7341 sensor. Finally, he installed 5mm green and red LEDs.
The wiring diagram is as follows:

 //Connections //Arduino Nano 33 IoT & # 58; //AS7341 11-Channel Spectral Color Sensor //3.3V --------------------------- + //GND ------ --------------------- - //A5 ------------------------- - C //A4 --------------------------- D //10K Potentiometer //A0 --------- ------------------ S //Class Button_1 (6x6) //D2 --------------------- ------ //Class Button_2 (6x6) //D3 --------------------------- //Class Button_3 (6x6) //D4 --------------------------- //Class Button_4 (6x6) //D5 ---------- ----------------- //5mm Green LED //D6 ------------------------- - //5mm Red LED //D7 ---------------------------  

Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color After assembling the circuit, he installed the breadboard and AS7341 sensor on the old bookshelf using glue gun.
Device for determining the ripeness of vegetables and fruits by their color Device for determining the ripeness of vegetables and fruits by their color The device is assembled and ready for testing.
 Device for determining the ripeness of vegetables and fruits by their color  Device for determining the ripeness of vegetables and fruits by their color

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button