This study developed a sustainable colorimetric pH sensor using chitosan derived from mealworm (Tenebrio molitor) biomass and anthocyanin extracted from red cabbage (Brassica oleracea). Chitosan was used as the substrate material, and anthocyanin served as the pH indicator dye, collectively forming the basis of the pH sensor. The resulting pH-responsive film effectively measures pH levels from 1 to 13, with a distinct color shift from pink to green. The sensor demonstrated remarkable stability, maintaining color fidelity after prolonged exposure to aqueous environments, and its practical functionality was confirmed through an ammonia detection assay, underscoring its utility in monitoring food freshness. Mechanistic investigations using Fourier-transform infrared spectroscopy (FTIR) and molecular modeling identified electrostatic and hydrophobic forces as key factors in anthocyanin binding to the chitosan matrix. Molecular modeling further revealed a minimal binding energy of -3 kcal/mol and an RMSD of 0 & Aring;, indicating a strong interaction stability. The film exhibited high structural integrity, with tensile strength and elongation values of 8.8 MPa and 8.4%, respectively, and its flexibility suggests its suitability for diverse applications, including biomedical devices. The eco-friendly production process and the biocompatibility of this sensor provide a sustainable alternative to conventional pH measurement technologies. This innovation not only addresses ecological challenges but also expands the capabilities of colorimetric sensors for use in scientific research, biomedical applications, and other fields.