A low cost spectroscopy with Raspberry Pi for soil macronutrient monitoring

Soil spectroscopy measurement is widely used to determine the macronutrients content in the soil. Spectrometer is costly equipment and commonly used to determine the transmittance, absorbance or reflectance level of various liquids and opaque solids by measuring the intensity of light as a light source passes through a sample chemical substance. This paper is reported on a low cost experimental assessment of soil macronutrient for soil spectroscopy utilizing Raspberry Pi (RPI) module in visible and near-infrared (NIR) wavelength. The sensitivity measurements are mainly due to the concentration level and the intensity of light emitting diode (LED) light source. The work is focusing on the absorbance spectroscopy particularly on linear relationship to determine the Nitrogen (N), Phosphorus (P) and Potassium (K) content level in soil using colour-developing reagent. The development of low cost and portable RPI based spectrophotometer has created new possibilities to measure the concentration level of the existed soil macronutrient within visible and infrared light wavelength of light sources. The absorbance of light was computed based on Beer-Lambert Law. The low cost RPI based spectrometer costs 80% less than the spectrometer available in the market and is capable of recording the absorbance measurements up to 5 samples. The performance of this prototype shows that it is possible to build the spectrometer using open-source software and hardware by considering the limiting factors such as light transfer to the sample, spectral filtering and the sensitivity due to the signal-to-noise ratio.


Introduction
Spectroscopy is the study of the interaction between matters and electromagnetic radiation [1]. Although coloured or colourless biochemical substances can be measured using colorimetric procedures [2][3][4], these substances can also be measured by designing the instrument to measure the light transmittance or diffusivity on any suitable light spectrum ranges which typically cover around 200 nm to 2500 nm in wavelength using different calibrations and controls. The spectrometer is one of the essential parts for these systems.
Spectroscopy can be applied to several fields of study that are beneficial to human. Researchers have done a great amount of work figuring out its performance and possible applications. Optical spectroscopy sensing systems are capable to improve the efficiency and ease the work in agriculture [5], food processing [6] and biomedical [7][8][9]. Recently, spectroscopy, which is followed the principal of optical techniques has been increasingly used in agricultural and food industries. The spectroscopy is used in agriculture to detect nutrients in sample soil. In food processing, spectroscopy can be used to detect defects in certain food products such as milk product. Soil macronutrients, N, P and K are important nutrients in agriculture for plant growth and health [1][2][3][4][5][6][7][8][9]. NPK fertilizer is the most common fertilizer available in the market. Excessive use of fertilizer can lead to surface and ground water pollution, which affect the plant production quality. The quantity of NPK varies depending on the type of crops and plant growth level. Therefore, the volume of fertilizer has to be monitored carefully for optimum production [2][3][4][5][6]. Nutrient contents monitoring in soils is essential to proper use of fertilizers in order to minimize the environmental impact of wrong pattern fertilization practice. For increasing crop production, soil testing is highly required for recommending the type of fertilizer and its quantity to be added to the soil. This testing would also help farmer to determine the quantity and the exact location to apply the fertilizers by measuring the concentrations of soil nutrients, especially N, P and K [7][8][9][10].
The conventional soil testing methods, the soils characterizations are time consuming, which require the farmers to collect soil samples from their crop field and send to the specialized soil analysis laboratory. At the same time, these methods are expensive and need highly skill expertises in chemical analysis [6]. Due to the cost, the number of samples analyzes per field may be limited and cause the soil nutrient concentrations within the field cannot be characterized effectively [2,8].
Spectroscopy is able to replace the conventional way of measuring concentration of substances in blood, urine and fertilizer using chemical reagents, increasing the efficiency of measurement. Nowadays, many experiments and research has been done to develop spectroscopy based reliable, portable and cost effective device. This is due to the spectroscopy performance that has shown promising results for estimation of soil properties, particularly on macronutrient [9][10][11]. Another advantages of spectroscopy is including rapid, simple, less expensive and non-destructive technique [12]. According to the absorbance and reflectance of materials, spectroscopy technique can distinguish the elements corresponding to its specific wavelength without the addition of chemical reagent in soil [13][14][15][16][17].
In this paper, the development of a low cost experimental assessment of soil macronutrient for soil spectroscopy utilizing RPI module in visible and NIR wavelength is reported. By building a low cost spectrometer using silicon photodiode (SiPD), transimpedance amplifier (TIA), Arduino Uno and RPI, absorbance of soil extract samples is obtained. The characterization of the macronutrients content of various soil samples that have been implemented in visible and near infrared light wavelength range are also been discussed. The finding which is highlighted in this paper would help to develop a simple and low cost spectroscopy using LED in determining the macronutrients content in various types of soil samples.

Optical Spectroscopy
Optical sensing method in soil is based on the interaction between the incident light and soil surface properties, such that the characterizations of the reflected light vary due to the soil physical and chemical properties. Hence that, Beer-Lambert law is utilized in determining the soil macronutrients (NPK). In theory, Beer-Lambert Law stated that there is a relationship between absorbance and concentration of an absorbing species in a solution and path length [18][19][20][21][22]. Hence that, Beer-Lambert law combines Lambert's law and Beer's law and correlates the light absorbance to both concentrations of attenuating species as well as the thickness of the material sample [14,17,23]. The material sample will absorb certain amount of light photons from the light source and the remaining light photons will be transmitted to the photodetectors which is then converted into electrical signal for further investigation. The modern optical absorption techniques for remote sensing are based on selective absorption of light by the molecule which is described by the Beer-Lambert law [4,11,[23][24][25] where is the intensity of transmitted light, 0 is the intensity of incident optical radiation, is the molar extinction coefficient in (mol/L) -1 cm -1 (mol/L) -1 cm -1 (and is dependent on wavelength), is the molar concentration, and is the path length in cm. Then, the measurement can be done using: = log ( 0 / ) (2) where is the absorbance of light. Absorption spectroscopy for measurements can generally be done either in the mid-infrared (MIR) or NIR light spectral region. The Beer-Lambert law is illustrated as partly shown Figure 1. Figure 1 shows the basic structure of a single beam spectrometer. The main components of spectroscopy are photodetector, amplifier and readout circuit. The photodetector captures the transmitted light from the sample and converts the light into electrical signal before the signal is amplified. The amplified signal is sent to the readout circuit to display the output by utilizing the RPI module. Figure 1. The block diagram of a basic single-beam spectrometer

Raspberry Pi based Spectrophotometer
The spectrometer is the back end device of an optical sensing system. The front end of the system is a light source directed onto a sample. The light energy would be absorbed by the samples from the light source and transmit the remaining light photons. A RPI based spectrometer had included the implementation of SiPD as the photodetector, transimpedance amplifier (TIA) as the optical amplifier, Arduino Uno as the analog-to-digital converter (ADC), RPI 3 Model B as the processing unit and a desktop monitor as the display as shown in Figure 2. The Tkinter (TK) graphic user interface (GUI) written in Python (PY) displays the output voltage, power and absorbance of light.
The hardware implementation includes the SiPD, TIA and ADC. The SiPD is used to convert the light (or specifically light photons) into a very small electrical current. The small electrical current is amplified to a larger voltage variation using a TIA. The gain of the TIA can be defined as transimpedance gains, which is given by [26]: where ∂ is the output voltage in voltage (V) and is the input current in Ampere (A). In the hardware setup, the transimpedance gain was designed based on [11,16] and computed as =270 kΩ. The was selected based on the specification sheet of the SiPD. The analog voltage from the TIA output was then converted to digital signal using an ADC. The analog output from the TIA must be converted to digital signal because the general-purpose input output pins (GPIOs) of RPI are only capable to read or write digital signals. The software implementation involved the usage of Raspbian operating system (UNIX-based operating system) which was installed in the RPI and the open-source scripting language (PY). The prototype display is an electronic portable screen monitor to present the photodetector ouput voltage, power dissipation and absorbance level of light to the users.
The experimental setup as shown in Figure 3 has been developed to identify the relationship between the concentration of a sample with output power and absorbance level of light which is detected with various soil concentration. The setup consists of prototype RPI based spectrometer and commercial Thorlabs PM100A spectrometer. Hence that the performance of the prototype RPI based spectrometer has been compared to commercial Thorlabs PM100A spectrometer in order to justify the performance of the proposed low cost spectrometer. The experimental assessment was carried out using red LED with wavelength of 630 nm with the supplied input power of 500 mW. The positions of each component in the experiment set up were fixed because any changes in the positions could cause variations in the readings.
The samples that were used in this experiment is NPK soil kits consisting of phosphorus and potassium soil extracts. The soil extract concentration was altered by varying the ratio of distilled water in the soil extract. A pipet was used to mix the soil extract and distilled water. The percentage of soil extract concentrations was calculated based on:

Results and Analysis
In this section, the overall functional block diagram of this project is explained. The sample preparation, characterization performances and the comparison between the proposed RPI based spectrometer and commercial spectrometer are also been discussed in this section.

Soil Samples preparation
The soil samples used in this study were collected from the geotechnique laboratory (non-agriculture soil) and the farm (agriculture soil). The soil samples have been labeled as the processed soil, the soil from the plant growth area, the cleaned soil in which no cultivation (wthout fertilizer), the soil with fertilizer from a non-plant growth area and non-agricultural soils, which are mud flood and kaolin. The reason non-agricultural soils are chosen is to identify the potential commercial soil for agricultural cultivation. These samples have been oven-dry for 12 hours at temperature of 50°C.

Light Power Measurement
The power of light was measured for 5 different soil extract concentration for phosphorus and potassium soil extracts. The obtained data are shown in Figure 4 and Figure 5 for both phosphorus and potassium soil extracts. The data of power dissipation at the SiPD were collected as the concentrations of soil extract were varied from 20% to 100%. For instance, the soil extract that was not diluted by distilled water was denoted as 100% concentration. The lines in red colour indicates the readings for Thorlabs PM100A spectrometer and in blue colour indicates the readings for RPI based spectrometer. The plotted graphs on both Figures clearly depict that as the concentration of the soil extract increases, the light power decreases. The highest power dissipation was measured at 20% concentration and the lowest at 100% concentration. Similar results were obtained for both phosphorus and potassium samples.

Absorbance Level Measurement
Experiments were conducted to explore the instrumental capabilities while, at the same time, using Python programming to plot data, perform linear least-squares fitting, and calculate errors. The absorbance of light is the ability of the soil extract sample to absorb light. The absorbance levels of the soil extracts versus soil extract concentrations are shown in Figure 6 and Figure 7 for phosphorus and potassium respectively. From the findings, there is an opposite relationship between the absorbance and the concentration of soil extract to the obtained power dissipation. Similar to the light power plots, the lines in red colour indicates the readings for Thorlabs PM100A spectrometer and in blue colour indicates the readings for RPI based spectrometer. The absorbance level was the highest at 100% concentration and the lowest at 20% concentration. Similar trends were found in both of the samples and are reported in this paper.
From the findings, it is shown that as the concentration increases, the power obtained decreases because more light is absorbed by the sample with higher concentrations. On the other hand, the potassium sample shows higher absorbance compared to phosphorus sample because the phosphorus soil extract is partially transparent in blue colour while potassium soil extract is an opaque grey colour solution.
The RPI based spectrometer is a useful low cost device for beginners in optoelectronics to learn the theories of spectroscopy. The comparisons between the two devices are summarised in Table 1. By comparing the Thorlabs PM100A spectrometer and RPI based spectrometer, the cost of a RPI based spectrometer is about 20% cheaper of the Thorlabs instrument. The trade-off for the low cost device is the accuracy of readings. Even though the reading is not accurate, but the trends of the graphs are in the correct way. In addition, another advantage of the RPI based spectrometer is that it can be used to calculate the absorbance of a spectroscopy experiment by just clicking a few buttons, but for the Thorlabs PM100A spectrometer, users have to manually record the values for all data and calculate the absorbance.

Conclusion
The results shown in this paper indicate that the proposed RPI based spectrometer is sensitive to the change of concentrations of soil nutrients in the sample. RPI based spectrometer is convenient because it is portable and users do not have to manually record the power readings for each set of data to calculate the absorbance of the samples. Users can obtain the light absorbance of the sample by clicking a few buttons in the GUI. In addition, the experimental that has been implemented using RPI based spectrometer based on detection soil macronutrients thoroughly demonstrated the instrument is able to measure the light absorbance level in various soil samples on any suitable light spectrum ranges which typically cover around 200 nm to 2500 nm in wavelength.