Measuring pH is crucial across various domains, including environmental science, healthcare, and food packaging. While conventional pH sensors are highly sensitive, they are often limited by challenges such as limited battery life and slower response rates. An innovative solution lies in triboelectric nanogenerator (TENG) technology, which offers a sustainable, battery-free approach to pH detection. By harnessing mechanical energy and converting it into electrical energy, TENGs enable the development of self-powered sensors suitable for environmental applications. In this context, A nitrogen-rich polymer organic framework (POF) was synthesized based on porphine using pyrrole and tested its effectiveness in a TENG. The POF particles are used as the positive triboelectric layer and FEP as the negative triboelectric layer in the TENG fabrication process. The resulting POF-based TENG could generate 70 V voltage, 1.2 µA of current, and 5 µW of power. We also demonstrated that the TENG could charge capacitors and power LEDs. The study explored the operational mechanism of the TENG in harsh environmental conditions and how the POF material detects pH changes, confirming its efficiency in pH sensing. The research highlights the synthesis of the POF material, its use as a triboelectric layer, the fabrication process of the TENG, and its performance in energy harvesting and self-powered applications.