In this work, nanoclusters (NCs) of Cu and Ag capped with hyperbranched polyethyleneimine (PEI) were prepared using chemical reduction by a one-step hydrothermal method. The PEI coated-NCs were characterized by high-resolution transmission electron microscopy, ζ potential, thermogravimetric analysis, dynamic light scattering, Fourier-transform infrared, UV-visible, and fluorescence spectroscopy. The PEI-NCs exhibited strong absorption and fluorescence, high stability, and excellent water dispersibility. The resulting PEI-NCs showed a reversible and linear response of fluorescence intensity with pH over a wide range (3-11); however, PEI-AgNCs showed a better reversibility and sensitivity than PEI-CuNCs. Unlike several types of pH sensors based on modified NCs, which are based on a nanoparticle aggregation/disaggregation mechanism, the response of our sensor is based on a photoinduced electron transfer process, which gives it a high reversibility. This method was successfully applied in pH measurements in tap water and green tea samples, with excellent results, indicating its practical utility for these applications. A visual device was obtained by immobilizing PEI-AgNCs into agarose hydrogels at different pH values. The results show that the proposed sensor can be used as a pH visual detector. Besides, the light emission of the nanosensor was corroborated by fluorescence microscopy, confirming that the nanosensor based on PEI-AgNCs has great potential to be used in cellular imaging.