Evolution of Wireless Sensor Network for Air Quality Measurements

This study addresses the development of a wireless gas sensor network with low cost, small size, and low consumption nodes for environmental applications and air quality detection. Throughout the article, the evolution of the design and development of the system is presented, describing four designed prototypes. The final proposed prototype node has the capacity to connect up to four metal oxide (MOX) gas sensors, and has high autonomy thanks to the use of solar panels, as well as having an indirect sampling system and a small size. ZigBee protocol is used to transmit data wirelessly to a self-developed data cloud. The discrimination capacity of the device was checked with the volatile organic compounds benzene, toluene, ethylbenzene, and xylene (BTEX). An improvement of the system was achieved to obtain optimal success rates in the classification stage with the final prototype. Data processing was carried out using techniques of pattern recognition and artificial intelligence, such as radial basis networks and principal component analysis (PCA).


Introduction
In most cities, air quality improved (significantly) over the past decades. Visible air pollution (smoke, dust, and smog) disappeared from many cities due to local, national, and European initiatives. However, the current air quality still affects the health of the population. According to the World Health Organization (WHO), 1.7 million children die as a result of contaminated environments (indoor and outdoor) [1]. On the other hand, the Health Effect Institute concludes from its studies that long-term exposure to air pollution in 2016 was responsible for the deaths of 6.1 million people due to strokes, heart attacks, lung diseases, and lung cancer [2]. Air quality is, therefore, a problem common to almost all major cities.
Volatile organic compounds (VOCs) are among the main pollutants in the atmosphere. These are organic compounds that evaporate or sublimate at room temperature and pressure, and are derived from products such as fuels and solvents from anthropogenic and natural sources. These compounds are directly associated with chronic effects on health, as well as the formation of ozone and mists. The health effects of VOCs depend on the type of component, although benzene (C 6 H 6 ) is the most relevant compound, since it is considered a potent human carcinogen by the International Agency for Research on Cancer (IARC). Specifically, it causes acute myeloid leukemia, and there is some evidence that it may cause lymphocytic leukemia [3]. In addition, like toluene (C 6 H 5 CH 3 ), it is a precursor pollutant of ozone and secondary organic aerosols.
Because of the great global damage caused by the presence of pollutants in the atmosphere, many organizations and countries around the world established monitoring systems that provide the data needed to improve air quality. While, for the vast majority of these observations, the established analytical reference methods continue to be used, miniaturization led to a growth in

•
Design and development of a wireless gas sensor network for low-cost air quality measurements, with low size and low consumption. • Description of the different prototypes corresponding to the evolution of the designed system across several years and projects: electronics and communication.

•
Use of artificial neural networks for processing the collected data.

•
The discrimination capability of the module was tested with BTEX volatile compounds. These tests also allowed studying the evolution of system operation.

Materials and Methods
This paper describes the development of a wireless sensor network (WSN) for gas sensors to detect air quality. During the evolution of the project, four different prototypes of the device were developed: prototype version 1 (PV1) [31], prototype version 2 (PV2), prototype version 3 (PV3) [32], and prototype version 4 (PV4). In general, the scheme of the different designs is similar (shown in Figure 1). The corresponding energy source in each case powers the entire device through different voltage converters. Firstly, an optional pumping system carries the gas samples to the sensors cell. These sensors change their electrical resistance in the presence of the different gaseous compounds, which is translated into a voltage change. The signal is conditioned and filtered so that it can be received by the chosen radio frequency (RF) module. This module is responsible for wirelessly sending all the information received to a central station, where the data processing can be performed to obtain the final results in terms of concentration prediction or classification of gas. On the other hand, the RF module is also responsible, in some cases, for controlling the pump system and the sensor heaters (necessary for proper operation of gas sensors).
Electronics 2018, 7, x FOR PEER REVIEW 3 of 17 and data transmission. Numerous authors also used devices based on colorimetric methods [28]. However, although they are portable, they do not allow the creation of a spatial matrix of numerous nodes that allows studying the presence of BTEX at different points. Notably, it is usually necessary to apply data processing techniques in the use of devices with MOX gas sensors. The main used pattern recognition techniques in the field of gas detection were summarized in numerous articles in recent years [29,30].
Therefore, in this work a low-cost system was developed for the measurement of air quality. Throughout the article, the architecture and the evolution in the development of the electronic and communication system are described.
In this work, the following contributions are presented: • Design and development of a wireless gas sensor network for low-cost air quality measurements, with low size and low consumption.

•
Description of the different prototypes corresponding to the evolution of the designed system across several years and projects: electronics and communication.

•
Use of artificial neural networks for processing the collected data.

•
The discrimination capability of the module was tested with BTEX volatile compounds. These tests also allowed studying the evolution of system operation.

Materials and Methods
This paper describes the development of a wireless sensor network (WSN) for gas sensors to detect air quality. During the evolution of the project, four different prototypes of the device were developed: prototype version 1 (PV1) [31], prototype version 2 (PV2), prototype version 3 (PV3) [32], and prototype version 4 (PV4). In general, the scheme of the different designs is similar (shown in Figure 1). The corresponding energy source in each case powers the entire device through different voltage converters. Firstly, an optional pumping system carries the gas samples to the sensors cell. These sensors change their electrical resistance in the presence of the different gaseous compounds, which is translated into a voltage change. The signal is conditioned and filtered so that it can be received by the chosen radio frequency (RF) module. This module is responsible for wirelessly sending all the information received to a central station, where the data processing can be performed to obtain the final results in terms of concentration prediction or classification of gas. On the other hand, the RF module is also responsible, in some cases, for controlling the pump system and the sensor heaters (necessary for proper operation of gas sensors). Throughout the evolution of the system, four different prototypes were designed and developed, depending on the context of the application and also improving on the previous ones. The first version was a homemade prototype created to study the operation of ZigBee communication  Throughout the evolution of the system, four different prototypes were designed and developed, depending on the context of the application and also improving on the previous ones. The first version was a homemade prototype created to study the operation of ZigBee communication and gas sensors. The second system incorporated improvements in system autonomy and a greater versatility for using different types of sensors. The third one included changes in communication and data acquisition (incorporating the use of a data cloud), and improved the adaptation of the sensors signals and their stability. Finally, the last system is the most optimized, incorporating solar power and greater autonomy, greater adaptation and control of the sensors, and improvements in the acquisition and processing of data.

Battery Chargers
The first prototype (PV1) was powered by a 9-V nickel metal hydride battery with a capacity of 155 mAh that allowed portability. However, an autonomy of more than 1.5 h was not achieved (3.5 h while maintaining the RF module in low-consumption mode in measurements with low sampling frequency, ≤1 sample per hour). For this reason, in PV2 and PV3, a lithium-ion battery of 3.7 V and 1350 mAh was incorporated. In addition, in PV2, a charger circuit was also included to facilitate charging through an external jack connector. The core of this circuit was the MCP73113/4 chip (Microchip, Chandler, AZ, USA), an integrated lithium-ion battery charge management controller with overvoltage protection. In particular, it provides specific charging algorithms for the batteries and, thus, achieves an optimal and safe capacity in the shortest possible charging time. The load current is programmed from the value of an external resistor connected to a 10-pin chip. In this case, a limiting value of 1000 mA was chosen ( Figure 2). and gas sensors. The second system incorporated improvements in system autonomy and a greater versatility for using different types of sensors. The third one included changes in communication and data acquisition (incorporating the use of a data cloud), and improved the adaptation of the sensors signals and their stability. Finally, the last system is the most optimized, incorporating solar power and greater autonomy, greater adaptation and control of the sensors, and improvements in the acquisition and processing of data.

Battery Chargers
The first prototype (PV1) was powered by a 9-V nickel metal hydride battery with a capacity of 155 mAh that allowed portability. However, an autonomy of more than 1.5 h was not achieved (3.5 h while maintaining the RF module in low-consumption mode in measurements with low sampling frequency, ≤1 sample per hour). For this reason, in PV2 and PV3, a lithium-ion battery of 3.7 V and 1350 mAh was incorporated. In addition, in PV2, a charger circuit was also included to facilitate charging through an external jack connector. The core of this circuit was the MCP73113/4 chip (Microchip, Chandler, AZ, USA), an integrated lithium-ion battery charge management controller with overvoltage protection. In particular, it provides specific charging algorithms for the batteries and, thus, achieves an optimal and safe capacity in the shortest possible charging time. The load current is programmed from the value of an external resistor connected to a 10-pin chip. In this case, a limiting value of 1000 mA was chosen ( Figure 2). This circuit was eliminated in the third prototype because the location where it was going to be used had no external source, thus allowing the optimization of the size of the PCB (Printed Circuit Board).
The last and current prototype (PV4) includes a 3.7-V and 2050-mAh battery that, together with a solar panel, greatly improves the autonomy of the system. For this purpose, the LT3652 charger integrated circuit (Linear Technology, Milpitas, CA, USA), optimized for solar panel applications, is used ( Figure 3). This circuit keeps the solar panel at the maximum output power and the charging current is modified according to the battery state at each moment. In addition, it has temperature protection and a timer. This circuit was eliminated in the third prototype because the location where it was going to be used had no external source, thus allowing the optimization of the size of the PCB (Printed Circuit Board).
The last and current prototype (PV4) includes a 3.7-V and 2050-mAh battery that, together with a solar panel, greatly improves the autonomy of the system. For this purpose, the LT3652 charger integrated circuit (Linear Technology, Milpitas, CA, USA), optimized for solar panel applications, is used ( Figure 3). This circuit keeps the solar panel at the maximum output power and the charging current is modified according to the battery state at each moment. In addition, it has temperature protection and a timer.

Voltage Converters
With respect to the voltage transformation, different converters were used in the different versions of the device. In PV1, linear regulators with up to 250 mA of 3.3 V (for the XBee module) and 5 V (for the sensors) were used. PV2 had an adjustable and disconnectable step-up converter for the sensors, since the battery voltage was changed from 9 V to 3.7 V. This was replaced by two direct current (DC)-DC converters with fixed output voltage (5 V) in PV3 and PV4. This change was due to the high instability in the voltage that distorted the functioning of the sensors. Both converters have different functions: one is used to power the pumping system (pump and electrovalve), while the other allows powering the sensor devices (heating resistor and sensor) more accurately and efficiently. Figure 4 shows the electrical scheme in the case of PV4. It shows that the step-up DC-DC converter NCP1402 (ON Semiconductor, Phoenix, AZ, USA), capable of providing 200 mA, was used to power the pumping system (5V_P); the high efficiency step-up DC-DC converter LTC3525-5 (Linear Technology, Milpitas, CA, USA), capable of supplying 400 mA at the output, was used to power the sensors (5V_S); and the step-down DC-DC converter LM3671MF-3.3 (Texas Instruments, Dallas, TX, USA) was used to power the XBee communication module (3.3 V).

Voltage Converters
With respect to the voltage transformation, different converters were used in the different versions of the device. In PV1, linear regulators with up to 250 mA of 3.3 V (for the XBee module) and 5 V (for the sensors) were used. PV2 had an adjustable and disconnectable step-up converter for the sensors, since the battery voltage was changed from 9 V to 3.7 V. This was replaced by two direct current (DC)-DC converters with fixed output voltage (5 V) in PV3 and PV4. This change was due to the high instability in the voltage that distorted the functioning of the sensors. Both converters have different functions: one is used to power the pumping system (pump and electrovalve), while the other allows powering the sensor devices (heating resistor and sensor) more accurately and efficiently. Figure 4 shows the electrical scheme in the case of PV4. It shows that the step-up DC-DC converter NCP1402 (ON Semiconductor, Phoenix, AZ, USA), capable of providing 200 mA, was used to power the pumping system (5V_P); the high efficiency step-up DC-DC converter LTC3525-5 (Linear Technology, Milpitas, CA, USA), capable of supplying 400 mA at the output, was used to power the sensors (5V_S); and the step-down DC-DC converter LM3671MF-3.3 (Texas Instruments, Dallas, TX, USA) was used to power the XBee communication module (3.3 V).

Gas Sensors
All sensors used in this work are commercial resistive gas sensors. Specifically, they are semiconductor metal oxide (MOX) sensors whose electrical conductivities are modulated as a result

Gas Sensors
All sensors used in this work are commercial resistive gas sensors. Specifically, they are semiconductor metal oxide (MOX) sensors whose electrical conductivities are modulated as a result of a reaction between the semiconductor and the gases in the atmosphere. These types of sensors need to be heated in a localized and uniform way or using a pulsed mode between 200 and 450 • C to keep them at an optimum temperature for gas detection [33,34]. It is necessary to carefully control the temperature because the sensitivity of the sensor is strongly dependent on it. Therefore, such sensors include an integrated heating element. The pulsed-temperature operating mode [35] consists of using short heating or cooling pulses from a reference temperature (ambient, high, or intermediate temperature). This mode of operation promotes transient chemical reactions.
The equivalent circuit for these sensors is composed of heating resistance (R H ) and a sensor resistance (R S ) components. Figure 5 shows the general circuit recommended by the manufacturers, where a heating voltage (V H ) is applied to R H and a supply voltage (V CC ) to R S . In addition, a load resistance (R L ) is used to obtain an output voltage (V S ), which depends on the following equation: (1) Electronics 2018, 7, x FOR PEER REVIEW 7 of 17

Signal Conditioning Circuits
Regarding the conditioning circuit of the sensor signal, PV1 was only composed of the load resistor together with a capacitor to reduce electromagnetic noise and provide low impedance to the analog input of the XBee communication module. In the second and third prototypes, a voltage follower was added to avoid the loading effect. Furthermore, in the second prototype, a variable resistor was used as load resistance (seeking more versatility of the system). However, because it destabilized the system, a fixed resistor was again used in the third version. Finally, the final prototype added the ability to amplify the signal for applications with low-signal sensors.
On the other hand, the power circuits of the heating resistance of the sensors also evolved. In the first device, a voltage of 5 V was directly applied to the heating resistor. Then, a variable resistor was added, since not all the sensors needed the same power for proper operation. In the third version, this variable resistor was replaced by a fixed one (as in the case of the conditioning circuit for the sensor signal), and the heating element activation and deactivation functionality was incorporated using a digital output of the XBee module and a bipolar transistor. Thus, it managed to reduce

Signal Conditioning Circuits
Regarding the conditioning circuit of the sensor signal, PV1 was only composed of the load resistor together with a capacitor to reduce electromagnetic noise and provide low impedance to the analog input of the XBee communication module. In the second and third prototypes, a voltage follower was added to avoid the loading effect. Furthermore, in the second prototype, a variable resistor was used as load resistance (seeking more versatility of the system). However, because it destabilized the system, a fixed resistor was again used in the third version. Finally, the final prototype added the ability to amplify the signal for applications with low-signal sensors.
On the other hand, the power circuits of the heating resistance of the sensors also evolved. In the first device, a voltage of 5 V was directly applied to the heating resistor. Then, a variable resistor was added, since not all the sensors needed the same power for proper operation. In the third version, this variable resistor was replaced by a fixed one (as in the case of the conditioning circuit for the sensor signal), and the heating element activation and deactivation functionality was incorporated using a digital output of the XBee module and a bipolar transistor. Thus, it managed to reduce consumption when sensors were not necessarily working. Finally, PV4 added a heater power control through a PWM (Pulse-Width Modulation) output and a MOSFET transistor, thereby achieving the possibility of modifying the operating temperatures of the gas sensors and of using the pulsed-temperature operating mode. Figure 6 shows the final electrical diagram of the sensor signal conditioning and of the heating power control in PV4. RH corresponds to the heating resistance, R3 is the resistor placed in series to limit the maximum current in RH, Rg is the gate resistor, VS is the output voltage of the gas sensor, R2 and R1 are the resistors corresponding to the amplification circuit of the signal, RS is the resistance of the sensor, RL the load resistor corresponding to the sensor, and VA is the output voltage of the amplifier stage, and the input to the analog/digital converter of the XBee module. According to this, the input voltage in the XBee module is defined by the following equation (corresponding to the non-inverting amplifier):

Sampling System
The sampling system takes a representative sample of the air to be analyzed, which is carried to the sensor cell. From the second prototype onward, the sampling system included a pump and an electrovalve in the sensor nodes in order to be connected to the system and to control the headspace from liquid samples for doing several measurements in the laboratory. In this way, it was possible to switch between a reference gas and a target gas and lead it to the sensor cell. For this purpose, a PWM output was used for adjusting pump speed, and a digital output was used for controlling the electrovalve state. In the first case, a MOSFET transistor and a gate resistor were used, while, in the second case, a bipolar transistor and the corresponding base resistor were used (Figure 7). According to this, the input voltage in the XBee module is defined by the following equation (corresponding to the non-inverting amplifier):

Sampling System
The sampling system takes a representative sample of the air to be analyzed, which is carried to the sensor cell. From the second prototype onward, the sampling system included a pump and an electrovalve in the sensor nodes in order to be connected to the system and to control the headspace from liquid samples for doing several measurements in the laboratory. In this way, it was possible to switch between a reference gas and a target gas and lead it to the sensor cell. For this purpose, a PWM output was used for adjusting pump speed, and a digital output was used for controlling the electrovalve state. In the first case, a MOSFET transistor and a gate resistor were used, while, in the second case, a bipolar transistor and the corresponding base resistor were used (Figure 7). from liquid samples for doing several measurements in the laboratory. In this way, it was possible to switch between a reference gas and a target gas and lead it to the sensor cell. For this purpose, a PWM output was used for adjusting pump speed, and a digital output was used for controlling the electrovalve state. In the first case, a MOSFET transistor and a gate resistor were used, while, in the second case, a bipolar transistor and the corresponding base resistor were used (Figure 7).

RF Module (XBee) and Evolution of Wireless Communication
The wireless communication devices used were the XBee radio frequency modules [36], which work in the 2.4-GHz band and with the IEEE 802.15.4 communication protocol. These are developed by Digi International (Minnetonka, MN, USA), and allow the creation of ZigBee networks (oriented to systems of low data transfer and consumption). They also incorporate a microcontroller (M9S08GT60, Freescale, Austin, TX, USA) to control all other peripherals. The module has seven ports configurable as digital inputs/outputs or analog inputs, along with two more digital inputs and outputs, and two PWM outputs.
In the first and second prototypes developed in this work (PV1 and PV2), the communication network was formed by the sensor nodes and a coordinator node responsible for receiving information from all others. To implement this coordinator node, a commercial interface card was used to communicate the XBee module with a computer via universal serial bus (USB). For receiving data and for configuration and monitoring of the entire network, an application was developed in LabVIEW. Then, data were stored on the computer for further processing.
In PV3, as before, the network consisted of some sensor nodes responsible for receiving the information and sending it, following the ZigBee protocol. However, in this case, the network coordinator node was the gateway "ConnectPort X4" (Digi, Minnetonka, MN, USA). It was connected to the internet via ethernet, and was responsible for submitting the information collected by the sensor nodes to the commercial cloud "Device Cloud" from Digi, where it is stored in XML format.
For programming, the "ConnectPort X" gateways offer a built-in Python ® engine, providing a powerful open-source software tool to develop custom applications that run on the gateway. In this study, several Python ® applications were developed for controlling the network. Among them, two stand out, which allow the information received by the nodes to be separated and pre-processed and then sent and stored in the data cloud. The difference between these two applications is that one was designed for laboratory measurements and, therefore, controls the pump and the electrovalve for switching between a reference gas and the target gas. The other application was designed for field applications, with an uncontrolled gas inlet to the sensor cell.
Finally, in the latest version, a self-developed data cloud was created in order to receive data from the sensor network and to provide storage services, classification, and requests. Table 1 shows the different main characteristics of each of the developed versions of the wireless sensor network for air quality measurements. It specifies the different sizes, the maximum and minimum consumption, and the autonomy, whether the gas sensors were integrated within the node or were connectable from an external PCB, as well as the tools used to receive, store, and process the collected data by the sensor nodes, whether they included a connection and control capacity for the pumping system, and the main features of improvement with respect to the previous version. The evolution was geared toward greater autonomy, smaller size, and greater flexibility and versatility. Pictures of the evolution of the wireless gas sensor nodes described in this paper are presented in Figure 8.  Pictures of the evolution of the wireless gas sensor nodes described in this paper are presented in Figure 8.

Data Processing
For proper device operation, it is necessary to use data processing techniques and artificial intelligence algorithms. In this process, four stages are typically performed (Figure 9): preprocessing, reduction of the number of variables, prediction, and decision-making.

Data Processing
For proper device operation, it is necessary to use data processing techniques and artificial intelligence algorithms. In this process, four stages are typically performed (Figure 9): preprocessing, reduction of the number of variables, prediction, and decision-making. Firstly, pre-processing techniques are applied to the collected data. In this case, this stage is performed in real time on the gateway. One of the existing feature extraction algorithms in the literature according to Gutierrez-Osuna [30] was used, namely the relative resistance algorithm (RR). Following this algorithm, the characteristic value of each measurement is defined by the following equation: where RV is the resistance value in exposure to the reference compound (air) and RN is the resistance value in exposure to the target compound, both in steady-state situations.
To reduce the size of the extracted data, the principal component analysis (PCA) [37] technique was used. This technique reduces the dataset, losing the least amount of information possible. It employs linear combinations of the original variables resulting in linearly independent variables. This phase and the following phase are performed in the cloud system.
Next, the prediction phase is carried out. At this stage, regression techniques can be applied to quantify concentrations, while classification techniques can be applied to discriminate contaminating compounds, or clustering techniques can be applied to group similar responses. In the results shown in this article, classification tasks were applied. To this end, probabilistic neural networks (PNN) were used, also called radial basis networks due to the use of a neuron activation radial basis function (RBF) [38]. These networks are made up of four layers. The input layer corresponds to the PCA components used. The next one is the pattern layer, with a number of neurons equal to the training vectors, grouped by classes, where the distance between the input layer vector and each element of the training set was evaluated. The third layer, i.e., the summation layer, contains a neuron for each class and adds the outputs of the pattern neurons belonging to the same class. Lastly, the output layer is a "limiter" that seeks the maximum value of the sum layer. Then, the highest value is selected and set to 1 as a result, while the other outputs are set to 0.
Finally, to determine the validity of the system, predictions of known values were made to compare the estimate values with the real results. Leave-one-out cross-validation (LOOCV) was used to determine the performance of the trained model in this case. This validation technique proposes to perform as many iterations as samples present in the dataset.

Measurement Set-Up
The same measurements were made for each of the versions of the designed wireless networks, except in the case of the PV1, which was developed in order to make first contact with the technology used, and only had one gas sensor (TGS2600, Figaro, Japan).
The array of sensors used in each prototype for the following measurements are as follows:  Firstly, pre-processing techniques are applied to the collected data. In this case, this stage is performed in real time on the gateway. One of the existing feature extraction algorithms in the literature according to Gutierrez-Osuna [30] was used, namely the relative resistance algorithm (RR). Following this algorithm, the characteristic value of each measurement is defined by the following equation: where R V is the resistance value in exposure to the reference compound (air) and R N is the resistance value in exposure to the target compound, both in steady-state situations.
To reduce the size of the extracted data, the principal component analysis (PCA) [37] technique was used. This technique reduces the dataset, losing the least amount of information possible. It employs linear combinations of the original variables resulting in linearly independent variables. This phase and the following phase are performed in the cloud system.
Next, the prediction phase is carried out. At this stage, regression techniques can be applied to quantify concentrations, while classification techniques can be applied to discriminate contaminating compounds, or clustering techniques can be applied to group similar responses. In the results shown in this article, classification tasks were applied. To this end, probabilistic neural networks (PNN) were used, also called radial basis networks due to the use of a neuron activation radial basis function (RBF) [38]. These networks are made up of four layers. The input layer corresponds to the PCA components used. The next one is the pattern layer, with a number of neurons equal to the training vectors, grouped by classes, where the distance between the input layer vector and each element of the training set was evaluated. The third layer, i.e., the summation layer, contains a neuron for each class and adds the outputs of the pattern neurons belonging to the same class. Lastly, the output layer is a "limiter" that seeks the maximum value of the sum layer. Then, the highest value is selected and set to 1 as a result, while the other outputs are set to 0.
Finally, to determine the validity of the system, predictions of known values were made to compare the estimate values with the real results. Leave-one-out cross-validation (LOOCV) was used to determine the performance of the trained model in this case. This validation technique proposes to perform as many iterations as samples present in the dataset.

Measurement Set-Up
The same measurements were made for each of the versions of the designed wireless networks, except in the case of the PV1, which was developed in order to make first contact with the technology used, and only had one gas sensor (TGS2600, Figaro, Japan).
These tests attempted to analyze the ability of devices to discriminate the BTEX (benzene, toluene, ethylbenzene, and xylene) volatile organic compounds dissolved in water. For this purpose, the static head space technique was used in 22-mL vials. Samples of 10 mL were prepared at a 5% concentration of each compound. Then, the headspace was drawn into the sensor cell using a pump. The vials were kept at 20 • C. Each measurement cycle lasted 10 min: 140 s for the passage of the target compound to the sensor cell, and 460 s for the flow of the reference gas (in this case, clean air). In the measurements made with the final prototype, these times were updated to 60 s (target) and 540 s (reference) to ensure the signal stabilization in the reference gas phase. Figure 10 shows a diagram of the measurement process. These tests attempted to analyze the ability of devices to discriminate the BTEX (benzene, toluene, ethylbenzene, and xylene) volatile organic compounds dissolved in water. For this purpose, the static head space technique was used in 22-mL vials. Samples of 10 mL were prepared at a 5% concentration of each compound. Then, the headspace was drawn into the sensor cell using a pump. The vials were kept at 20 °C. Each measurement cycle lasted 10 min: 140 s for the passage of the target compound to the sensor cell, and 460 s for the flow of the reference gas (in this case, clean air). In the measurements made with the final prototype, these times were updated to 60 s (target) and 540 s (reference) to ensure the signal stabilization in the reference gas phase. Figure 10 shows a diagram of the measurement process. More than 15 measurements were taken for each one of the BTEX compounds and distilled water (in order to have a reference of absence of simulated contaminants in the environment).

Results
The signals obtained from one of the sensors of each of the four sets of measurements are shown in Figure 11. The selected signals correspond to eight measurement cycles of xylene in each case. One of the sensors (model TGS2600) was selected for PV2 and PV3. Because PV4 did not use this sensor model, the signal of sensor model TGS8100, from the same manufacturer, was selected. The evolution shows the improvement achieved in each version due to changes in the power and conditioning circuits, pump power, and timing optimization. Thus, between the first two sets of measurements, noise reduction was achieved thanks to the changes introduced in the conditioning and power circuits of the sensors, and changes in the heater temperature. Then, between the second and third More than 15 measurements were taken for each one of the BTEX compounds and distilled water (in order to have a reference of absence of simulated contaminants in the environment).

Results
The signals obtained from one of the sensors of each of the four sets of measurements are shown in Figure 11. The selected signals correspond to eight measurement cycles of xylene in each case. One of the sensors (model TGS2600) was selected for PV2 and PV3. Because PV4 did not use this sensor model, the signal of sensor model TGS8100, from the same manufacturer, was selected. The evolution shows the improvement achieved in each version due to changes in the power and conditioning circuits, pump power, and timing optimization. Thus, between the first two sets of measurements, noise reduction was achieved thanks to the changes introduced in the conditioning and power circuits of the sensors, and changes in the heater temperature. Then, between the second and third package (made with the same version of the device, PV3), further noise reduction and a greater stabilization of the signal were achieved by decreasing the flow rate of the sample (by controlling the power of the pump). Finally, between the last two sets of measurements, in addition to the changes introduced in the adaptation and control circuitry, a faster response was achieved due to the use of a sensor of smaller size and consumption.  Once all the data from the measurements were collected, data processing was performed. In the case of PV2, the preprocessing phase was done manually through the Matlab software. However, in the third and fourth versions, this process was performed automatically (while measurements were made) by the program developed in Python that ran on the gateway. As explained above, this preprocessing phase used the relative resistance algorithm. It extracted the value of the ratio between the resistance value of the baseline and the resistance value during exposure to the target compound. In this way, it was possible to extract the main information, while considerably reducing the size of the data.
In all cases, the first two measures were discarded, since the systems were not yet stabilized and the conditions were not the same. Therefore, 13 measurements of each compound were used for data processing.
Then, an analysis of the main component (PCA) was carried out for a graphical representation of the measurements. Figure 12A shows the first two principal components of the measurements made with PV2. A high overlap can be observed between some compounds such as toluene, benzene, Once all the data from the measurements were collected, data processing was performed. In the case of PV2, the preprocessing phase was done manually through the Matlab software. However, in the third and fourth versions, this process was performed automatically (while measurements were made) by the program developed in Python that ran on the gateway. As explained above, this preprocessing phase used the relative resistance algorithm. It extracted the value of the ratio between the resistance value of the baseline and the resistance value during exposure to the target compound. In this way, it was possible to extract the main information, while considerably reducing the size of the data.
In all cases, the first two measures were discarded, since the systems were not yet stabilized and the conditions were not the same. Therefore, 13 measurements of each compound were used for data processing.
Then, an analysis of the main component (PCA) was carried out for a graphical representation of the measurements. Figure 12A shows the first two principal components of the measurements made with PV2. A high overlap can be observed between some compounds such as toluene, benzene, and xylene. In addition, short-term drift and dispersion effects appear, resulting from high noise in the measurements and non-stable temperature of the gas sensor heaters. The PCA of the same measurements made with PV3 is presented in Figure 12B. It shows that the clusters are further apart than in the previous case, although there is still overlap between those of toluene and xylene. Furthermore, a high drift effect is still present, possibly due to depletion of the sample. A similar test was repeated using lower pump power in the extraction phase of the sample (test 2). Moreover, the preprocessing program was improved, achieving greater accuracy of obtaining the characteristic value of each measurement. In Figure 12C, it can be observed that the PCA plot improved significantly, managing to reduce the drift effect and the overlaps between zones (only a small overlap between the areas of benzene and toluene, although they are generally very close to each other). Finally, Figure 12D shows the first two principal components of the values of the measurements made with the latest version of the device (PV4), where it can be observed that different areas concerning each compound are clearly separated and non-dispersed. Furthermore, a high drift effect is still present, possibly due to depletion of the sample. A similar test was repeated using lower pump power in the extraction phase of the sample (test 2). Moreover, the preprocessing program was improved, achieving greater accuracy of obtaining the characteristic value of each measurement. In Figure 12C, it can be observed that the PCA plot improved significantly, managing to reduce the drift effect and the overlaps between zones (only a small overlap between the areas of benzene and toluene, although they are generally very close to each other). Finally, Figure 12D shows the first two principal components of the values of the measurements made with the latest version of the device (PV4), where it can be observed that different areas concerning each compound are clearly separated and non-dispersed. Next, PNN was used in order to discriminate the compounds. Then, the LOOCV validation technique was used to study the classification capacity in each case. The results of each of the four studied cases are presented in Table 2, which contains the confusion matrix obtained, allowing us to observe the system performance. The matrix columns represent the predicted class, and the rows represent the real class. As a result, the main diagonal contains correct predictions, while values Next, PNN was used in order to discriminate the compounds. Then, the LOOCV validation technique was used to study the classification capacity in each case. The results of each of the four studied cases are presented in Table 2, which contains the confusion matrix obtained, allowing us to observe the system performance. The matrix columns represent the predicted class, and the rows represent the real class. As a result, the main diagonal contains correct predictions, while values outside it correspond to erroneous ones. Red data represent the matrix corresponding to the results of PV2. Blue data correspond to the first test performed with PV3 (without preprocessing and pump power correction), while green data correspond to the second test (with correction) of PV3. Finally, the black columns refer to the data resulting from PV4. The resulting success rates were 80%, 93.84%, 96.82%, and 100% for the four datasets, respectively.

Conclusions
In this paper, a wireless gas sensor network focusing on the study of air quality was presented. For this purpose, the electronic evolution of the designed sensor nodes was described, until a node of low cost, low consumption, and small size was obtained. Up to four gas microsensors can be connected to the nodes. In addition, they incorporate a control and RF module with ZigBee protocol that allows communication with a central node. This, in turn, is responsible for collecting and storing the data, controlling some aspects of the sensor nodes, and, in the most advanced prototype, preprocessing the data and uploading it to a data cloud.
The system was designed to be used in pollutant detection applications and air quality control in large areas. In order to verify the proper operation and discrimination capacity of the system, discrimination tests of BTEX volatile organic compounds were carried out. These tests also allowed studying the evolution of system operation. As a result, the signals were observed to improve significantly, and the discrimination success rates increased from 80% (PV1) to 100% (PV4).
Author Contributions: P.A. designed the hardware and performed the measurements; J.I.S. and J.L. designed the control architecture and the experiments. All authors wrote the article.

Funding:
The authors want to thank the Spanish Ministry of Economy and Competitiveness and Junta de Extremadura for supporting the TEC2013-48147-C6-5-R and IB16048 projects.