## 3 Results
### Firmware Development and Experimental Tests on Realized Smart Garment
SpO\({}_{2}\) can be expressed by the following polynomial relationship:  
\[\text{SpO}_{2}=\text{aR}^{2}+\text{bR}+\text{c with }\text{ R }=\frac{\text{AC}_{\text{red}}\ /\text{DC}_{\text{red}}}{\text{AC}_{\text{ired}}\ /\text{DC}_{\text{ired}}} \tag{7}\]  
where a, b, and c are calibration coefficients; AC\({}_{\text{red}}\) and AC\({}_{\text{ired}}\) are the amplitude of the AC components of the output signals from the red and IR photodiodes, respectively; DC\({}_{\text{red}}\) and DC\({}_{\text{ired}}\) are the amplitude of the DC components of the output signals from the RED and IR photodiodes. In the literature, the SpO\({}_{2}\) percentage is often calculated for medical devices as [53]:  
\[\%\text{SpO}_{2}=110\ -\ 25\ \times\ \text{R} \tag{8}\]  
The implemented firmware for the SpO\({}_{2}\) calculation does not use the previous formula but rather the function \(\%\text{SpO}_{2}=-45\ \times\ \text{R}^{2}+30.54\ \times\ \text{R}+94.845\), implemented by the approximation array shown in Figure 15, which numerically approximates the function. Afterwards, the correctness of the HR and SpO\({}_{2}\) measurements is checked through two flags called HR_valid and SpO2_valid; if two flags are true, the other parameters are acquired, namely, gas concentrations from the electrochemical gas sensor modules, body temperature from MAX30102, and the environmental temperature from LM75A. Relatively to the developed electrochemical gas sensor modules, presented in Section 3.1, the analog signals are acquired by the 12-bit ADC of the SAMD21G18 MCU and converted into gas concentrations through transfer functions of the different stages:  
\[\text{CO concentration}= \frac{\text{V}-0.3\ \text{Volt}}{0.03\ \text{V}/\text{ppm}} \tag{9}\] \[\text{CH}_{2}\text{O concentration}= \frac{\text{V}-0.3\ \text{Volt}}{7.2\ \text{V}/\text{ppm}}\] (10) \[\text{O}_{2}\ \text{concentration}= \frac{\text{V}}{0.141\frac{\text{mV}}{\text{\%Vol}}}\] (11) \[\text{H}_{2}\text{S concentration}= \frac{\text{V}}{0.32\ \text{V}/\text{ppm}} \tag{12}\]  
where V is the acquired voltage in volts, whereas the CO, CH\({}_{2}\)O, and H\({}_{2}\)S concentrations are expressed in ppm, and the O\({}_{2}\) concentration is in \(\%\)Vol. Figure 14.0 Array used for the SpO\({}_{2}\) calculation. These data, suitably formatted, are transmitted to the gateway through the integrated BLE module. The measurement_OK flag is then set to 1 to signal that the measurement and data packet transfer occurred correctly. The flag controls the operation mode of the wearable device, which takes measurements every 15 min (Figure 14a). If the flag is set to 1, the sensor, BLE module, and microcontroller are put into a 15 min sleep mode to save energy and extend the device's autonomy. After resetting the measurement_OK flag, the entire system is restarted, and a new measurement cycle begins. However, if the measurement cycle fails, the flag is not set, and the garment begins a new measurement cycle right away. Finally, fall detection is deployed using the embedded freefall detection mechanism of the MMA8452Q accelerometer (Figure 14b). The algorithm relies on analyzing the three-axis acceleration values, detecting when they are below a set threshold for longer than a given time duration, called debounce time; from experimental tests, the optimal values for the two parameters are 0.063 g and 100 ms, respectively [23]. The fall event is connected to an interrupt source of the MMA8452 accelerometer, which wakes up the microcontroller, recalling an interrupt service routine (ISR). This last event awakens the BLE module for transmitting a warning signal to the cloud platform, which triggers the transmission of an alert message to the company's security manager. Later, the microcontroller brings the BLE module into low-power mode again, and the microcontroller goes into sleep mode for the time remaining before the next awakening.