*2.5. Sensor Test*

Solutions of a certain pH were prepared from 0.1 M citric acid (aq.) and 0.1 M trisodium citrate dihydrate (aq.), 0.05 M NaH2PO4 (aq.), 0.1 M Na2HPO4 (aq.), 0.05 M NaHCO3 (aq.), and 0.1 M NaOH (aq.). The pH of the buffer solution was measured by a pH meter (INESA PHSJ-3F). Each UPPGF sample was dipped into the buffer solution for 2 min and then blown using a N2 flow to eliminate the excess solution on its surface. The reflectance spectra of the UPPGF samples were recorded before and after the dipping process. The samples were recovered by soaking in pH 10 buffer solution for 2 s, washing with deionized water, and then blowing with N2.

#### **3. Results and Discussion**

#### *3.1. Preparation and Characterization of UPPGF*

The synthesis of ultrathin photonic polymer gel films (UPPGF) is shown in Scheme 1. We obtained close-packed (cp) monolayer colloidal crystals (MCCs) by gas–liquid interface self-assembly. As shown in Scheme 1a, the polystyrene (PS) microspheres were stacked in a dense hexagonal manner on the silicon substrate to form cp MCCs. The non-close-packed monolayer colloidal crystals (ncp MCCs-x) (x = etching time in minutes) was obtained by O2 plasma etching of cp MCCs. P2VP swells by protonation in acid solution.; thus, we selected P2VP as the responsive polymer in this study. The P2VP precursor solution (3.25 wt %, in NM) was immersed into the ncp MCCs by spin-coating (Scheme 1b). Finally, the P2VP was completely cross-linked with DIB in the vacuum drying oven at 120 ◦C to obtain UPPGF-x (x = etching time in minutes) (Scheme 1c).

**Scheme 1.** Steps to fabricate UPPGF. (**a**) Monolayer colloidal crystals of PS nanoparticles were etched through oxygen plasma etching for different times. (**b**) The ncp MCCs was infiltrated with a polymer precursor (qP2VP) solution by spin coating. (**c**) P2VP was crosslinked by annealing.

The packing density of the ncp MCCs can be controlled by adjusting the O2 plasma etching time. The cp MCCs were treated at 80 ◦C for 12 h before etching to enhance the contact between PS and the silicon wafer and ensure that the film did not fall off or fold during etching and response detection. O2 plasma etching was then performed on the cp MCCs. Figure 1 reveals that the particle size of the PS microspheres gradually decreased with increasing etching time (from 438 nm for the sample without etching to 430 nm for ncp MCCs-2, 417 nm for ncp MCCs-4, 404 nm for ncp MCCs-6, and 395 nm for ncp MCCs-8). However, due to the good contact between PS and the silicon wafer, the position of the PS microspheres did not change during the etching process, and the gap between the microspheres increased gradually. Thus, ncp MCCs with different packing density were formed. Low-magnification SEM images reveal that the order of the array was not destroyed by plasma etching, and ordering of PS microspheres was maintained even after etching for 8 min. Such a characteristic is an important condition enabling films to display color and achieve a visual response to pH.

**Figure 1.** SEM images of the ncp MCCs after etching: (**<sup>a</sup>**,**f**) top views of ncp MCCs-0; (**b**,**g**) top views of ncp MCCs-2; (**<sup>c</sup>**,**h**) top views of ncp MCCs-4; (**d**,**i**) top views of ncp MCCs-6; and (**<sup>e</sup>**,**j**) top views of ncp MCCs-8.

UPPGF was prepared by spin-coating a polymer precursor solution onto ncp MCCs and thermal crosslinking. The qP2VP was spin-coated onto the surface of ncp MCCs. As shown in Figure 2, the P2VP was coated uniformly on the surface of the PS microspheres but it did not completely fill the voids between spheres. The viscosity of P2VP is such that rapid spin-coating does not allow it to fully infiltrate the substrate structure. The thickness of the films decreased with increasing etching time (478 nm for qP2VP-infiltrated ncp MCCs-0 to 462 nm for qP2VP-infiltrated ncp MCCs-2, 440 nm for qP2VP-infiltrated ncp MCCs-4, 430 nm for qP2VP-infiltrated ncp MCCs-6, and 414 nm for qP2VP-infiltrated ncp MCCs-8) because the thickness of P2VP on the surface of the PS array was determined by the speed of spin-coating and the concentration of the precursor solution. The thickness of the films depended on the particle size of PS after etching when the speed of the spin-coating and concentration of qP2VP were held constant. Figure 2 shows that the array maintained its good order after thermal cross-linking. Although the temperature of thermal cross-linking was higher than the glass transition temperature of PS, the protective effect of P2VP prevented serious deformation of the microspheres. During thermal crosslinking, P2VP gradually infiltrated the gap between PS microspheres, which grew larger with increasing etching time and allowed more P2VP to infiltrate into the pores. Thus, waves were produced on the surface of the films. Compared with that before thermal cross-linking, the thickness of the films decreased (from 478 to 440 nm for UPPGF-0, from 462 to 419 nm for UPPGF-2, from 440 to 397 nm for UPPGF-4, from 430 to 390 nm for UPPGF-6, and from 414 to 387 nm for UPPGF-8). This finding is related to the slight deformation of PS microspheres and the infiltration of P2VP.

**Figure 2.** SEM images of the fabricated structures: (**<sup>a</sup>**–**<sup>e</sup>**) cross-sectional views of the qP2VP-infiltrated ncp MCCs-x (x = (**a**) 0 min; (**b**) 2 min; (**c**) 4 min; (**d**) 6 min; and (**e**) 8 min); and (**f**–**j**) cross-sectional views of UPPGF-x (x = (**f**) 0 min; (**g**) 2 min; (**h**) 4 min; (**i**) 6 min; and (**j**) 8 min) obtained after thermal annealing.

#### *3.2. Optical Properties of UPPGF*

To better understand the effect of O2 plasma etching on the structure of the film, we studied its optical properties. A high-refractive index silicon wafer (*n* ~ 3.5) was chosen as the substrate on which to construct UPPGF. Fabry–Pérot fringes are formed by reflecting the interference between the beams of the thin-film air and thin-film substrate interfaces [37]. Under normal conditions, the position of the interference peak wavelength conforms to Equation (1) [38]:

$$m\lambda = 2nd,\tag{1}$$

where *n* is the refractive index of the film, *m* is an integer, and *d* is the thickness of the film. Calculations indicated that the peak of the cp MCCs was located in the visible region (585 nm; *d* = 438 nm, *m* = 2, and *n* = 1.335) [39]. In the experiments (Figure 3a), the center of the reflection peak was found at 588 nm. The valley observed was the result of multiple scattering from a single sphere, and the characteristic mode of 2D photonic crystals with hexagonal symmetry was found. The position of the valley gradually shifted toward shorter wavelengths with increasing etching time (625 nm for ncp MCCs-2, 617 nm for ncp MCCs-4, 611 nm for ncp MCCs-6, and 596 nm for ncp MCCs-8). This finding could be attributed to the refractive index of the film gradually decreasing with increasing etching time, because the distance between colloidal crystal microspheres did not change with the increase of etching time, but the ratio of air in the array increased, resulting in the decrease of effective refractive index of the film, consistent with the phenomena observed in the SEM images (Figure 1).

**Figure 3.** Optical properties of the fabricated structures:(**a**) reflectance spectra of the ncp MCCs-x obtained at different etching times (x = 0, 2, 4, 6, 8 min); (**b**) reflectance spectra of the qP2VP-infiltrated ncp MCCs-x; and (**c**) reflectance spectra of UPPGF-x obtained after thermal annealing.

We constructed UPPGF by spin-coating and thermal crosslinking. We found only one reflection peak in the visible region after spin-coating of the qP2VP, and no valleys associated with the photonic characteristic mode were observed. This is because of the refractive indices contrast was eliminated when the P2VP was infiltrated into the films. In this case, the position of the reflection peak also moved toward shorter wavelengths with increasing etching time (688 nm for qP2VP-infiltrated ncp MCCs-0, 653 nm for qP2VP-infiltrated ncp MCCs-2, 619 nm for qP2VP-infiltrated ncp MCCs-4, 584 nm for qP2VP-infiltrated ncp MCCs-6, and 549 nm for qP2VP-infiltrated ncp MCCs-8; Figure 3b). Because the thickness of the film decreased gradually, the UPPGF obtained by thermal cross-linking showed the same trend (656 nm for UPPGF-0, 621 nm for UPPGF-2, 589 nm for UPPGF-4, 547 nm for UPPGF-6, and 533 nm for UPPGF-8; Figure 3c). The reflection peaks of all films demonstrated a certain blue-shift after thermal cross-linking, which was due to the decrease in film thickness. The above data are consistent with the change in film thickness observed in the SEM images (Figure 2).

#### *3.3. Responsiveness of the UPPGF to pH and Mechanism Research*

We tested the responsiveness of the UPPGF sensors to pH by immersing them in buffers of different pH. P2VP swells in acidic solution, and its degree of swelling is related to its degree of protonation. Figure 4 illustrates that the reflection peaks of the films did not change significantly when the films were immersed in alkaline solution (pH ≥ 7). In acidic solution (pH < 7), however, the reflection peaks of all films gradually shifted toward longer wavelengths with decreasing pH. Even under strongly acidic (pH = 2.57) conditions, this response was maintained because the PS array prevented the collapse of the film structure caused by the high degree of swelling. This phenomenon is shown more intuitively in Figure S5. As shown in Figure 4f and Figure S5, in comparison with that of UPPGF-0, the pH responsiveness of the UPPGF templated by non-close-packed monolayer colloidal crystals was improved, and UPPGF-4 and UPPGF-6 showed the best responsiveness to pH. The displacement of reflection peak of UPPGF-4 was 80 nm, about 30 nm longer than the wavelength shift of UPPGF-0. However, compared with that of UPPGF-6, the responsiveness of UPPGF-8 was reduced to a certain extent. It is well known that the sensing ability of polymer gel sensor is closely related to the volume of polymer gel. Thus, we think that the responsiveness of the UPPGF was determined by the volume of P2VP, and the volume change of P2VP in the UPPGF may be influenced by etching.

**Figure 4.** (**<sup>a</sup>**–**<sup>e</sup>**) pH dependence of the reflectance spectra of the UPPGF-x (x = (**a**) 0 min; (**b**) 2 min; (**c**) 4 min; (**d**) 6 min; (**e**) 8 min) sensors after equilibration in pH buffer solution; and (**f**) the corresponding shifts of the reflectance peak of UPPGF-x.

We further explained the variation of the pH responsiveness of the UPPGF with increasing etching time through simple calculation based on geometric model. In Scheme 2, we set the diameter of the PS microspheres as *D* and the total thickness of the film as *H*. The *D* of the PS microspheres decreased to *d* after etching, assuming that the thickness of P2VP on the PS microspheres *h* is unchanged. We then calculated the volume (*VP2VP*) of P2VP with decreasing *d*:

$$V\_{P2VP} = V\_{total} - V\_{PS} = \frac{3\sqrt{3}D^2H - \pi d^3}{12} = \frac{3\sqrt{3}D^2(h+d) - \pi d^3}{12} \tag{2}$$

$$V\_{P2VP}' = \frac{\sqrt{3}D^2 - \pi d^2}{4} \tag{3}$$

$$
\Delta\lambda = \frac{2n \cdot \Delta H}{m} = \frac{2n \cdot V\_{\text{P2VP}} \cdot f\_{\text{P2VP}}}{m} \tag{4}
$$

**Scheme 2.** (**<sup>a</sup>**–**<sup>e</sup>**) Side views of UPPGF-0, UPPGF-4, and UPPGF-8; and (**d**–**f**) top views of UPPGF-0, UPPGF-4, and UPPGF-8.

We found that the *VP2VP* did not always increase with decreasing *d*. Using Equations (2) and (3), we calculated that *VP2VP* increased gradually as *D* decreased from *D* to 0.74*D* but decreased gradually with further decreases in particle size beyond 0.74*D*, i.e., *VP2VP* reached its maximum value at 0.74*D*. According to Equation (4) (where Δ*λ* is the displacement of the reflection peak, Δ*H* is the change in thickness of the film, *n* is the refractive index of the film, *m* is an integer, and *fP2VP* is the swelling rate of P2VP), the displacement of the reflection peak is proportional to the variation in *VP2VP*. Therefore, the law of responsiveness of UPPGF to pH is well explained. In the actual tests, however, maximum volume was achieved even if the particle size was not reduced to 0.74*D*, likely because P2VP did not completely cover the film, as assumed, to form a smooth surface (Figure 2). Thus, *VP2VP* in the actual experiments decreased at a faster rate than predicted by the calculations.

We monitored the change in film thickness with decreasing pH through SEM to confirm our hypothesis. In Figure 5, the thickness of UPPGF-4 increased from 397 to 408, 419, 440, and 449 nm in response to immersion in pH 5.08, 4.20, 3.39, and 2.57 buffer solutions, respectively; the thickness of the UPPGF would still increase when pH is 2.57 with no structural collapse. Other films showed the same trend with decreasing pH (Figures S1–S4). UPPGF-4 also showed the maximum thickness variation, which explains why UPPGF-4 had the best pH responsiveness.

**Figure 5.** SEM images of UPPGF-4 after equilibration in buffer solution at: pH 5.08 (**a**); pH 4.20 (**b**); pH 3.39 (**c**); and pH 2.57 (**d**).

#### *3.4. Linearity of the UPPGF to pH and Mechanism Research*

Sensors with good linearity can detect analytes more accurately in the whole range of measurement. As shown in Figure 6a, we found that the linearity towards pH was gradually enhanced with increasing etching time. The coefficient of determination (R2) of the sensor gradually increased from 0.95684 (UPPGF-0) to 0.9816 (UPPGF-8). This phenomenon can also be explained by Scheme 2. The relationship between the filling fraction of P2VP (*NP2VP*) and PS particle size (*d*) is in accordance with Equation (5):

$$N\_{P2VP} = 1 - \frac{\pi d^3}{3\sqrt{3}D^2(h+d)}\tag{5}$$

**Figure 6.** (**a**) Linear relation between UPPGF-x (x = 0, 2, 4, 6, 8 min) and pH; (**b**) response kinetics of UPPGF-x to a pH 3.39 buffer solution; (**c**) reversibility of UPPGF-x over 10 cycles of exposure to pH 9.17–3.39; and (**d**) hysteresis loops of the UPPGF-x sensors between pH 9.17 and 2.57.

Equation (5) reveals that *NP2VP* always increase with decreasing *d*. We thus considered that *NP2VP* is an important factor affecting the linearity of response. Although the PS array provided the necessary optical signals for the film, it could restrain the regular swelling of the polymer gel. Therefore, the linearity of UPPGF increased with increasing etching time. Considering response degrees and linearity of response, UPPGF-6 exhibited the best properties among the synthesized films.

#### *3.5. Response Speed of the UPPGF to pH*

Fast response speeds are widely favored in practical applications. We measured the response speed of the UPPGF by immersing them in buffer solution of pH = 3.39 and recording the change in reflection peak over time. Approximately 90% of the total response could be achieved within 10 s by the films, and stable responses could be achieved within 2 min (Figure 6b). The response speed of UPPGF was faster than that of the inverse opal hydrogel pH sensor (20 min) reported by Braun et al. [23] and the 2D-PCCA pH sensor (30 min) reported by Asher et al. [15], and comparable with our previously reported inverse opal monolayers of P2VP gels [31] and ultrathin P2VP gel-infiltrated MCCs films [32]. This fast response speed was due to the structural characteristics of the UPPGF, which included submicron thickness. The response speeds of UPPGF did not decrease with increasing volume of P2VP. Although the volume of P2VP increased after etching, the thickness of the whole film decreased.

#### *3.6. Stability of the UPPGF to pH*

We tested the stability of the UPPGF samples. Folding or shedding was not found in the SEM images when the UPPGF responds to the pH buffer solution (Figure 5 and Figures S1–S4). Then, the films were immersed in buffer solution of pH = 3.39 and then recovered in a solution of pH = 9.17. Figure 6c reveals that the position of the reflection peak remains basically unchanged after 10 cycles, thereby indicating good cyclic stability. Although more P2VP was in contact with the substrate with increasing etching time, the contact force between PS and the silicon substrate was

improved through heat treatment of the cp MCCs at 80 ◦C prior to etching. Thus, the UPPGF sensors showed good stability.

#### *3.7. Hysteresis Loops of the UPPGF to pH*

Sensors with low hysteresis loops can accurately detect the environment regardless of their input history. The peak shifts of the UPPGF samples observed under two approaches of pH input, i.e., from pH 9 to 2 and from pH 2 to 9, were recorded, and film recovery was found to be unnecessary for detecting different pH solution. As shown in Figure 6d, all UPPGF exhibited small hysteresis loops with short test times (2 min), likely because of the submicron thickness of the film. Ions could diffuse rapidly through the film, and the polymer gel could swell and shrink quickly. Thus, UPPGF can be used to test the environment continuously.

#### *3.8. Visual Response of the UPPGF to pH*

Importantly, the UPPGF achieved visual response to pH. In Figure 7, we can see that the color of the film changed with the change of pH. Compared with UPPGF-0, the color change of the UPPGF templated by ncp MCCs was more obvious. This phenomenon is consistent with the change of the redshift of the reflection peak with the etching time (Figure 4). Moreover, other responsive materials (for example, other responsive polymer gels, MOF, etc.) can be combined with ncp MCCs to improve their sensing capabilities. A sensor array could be obtained by the combination of the films etched at different times to achieve more accurate analysis.

**Figure 7.** Optical micrographs showing the pH dependence of the different response colors of UPPGF-x (x = 0, 2, 4, 6, 8 min) (the size of each optical micrograph: 1.2 mm × 0.9 mm).
