pH sensors typically operate based on the electrochemical principle. In a glass electrode, the potential difference between a reference electrode and a measuring electrode varies with the hydrogen ion concentration in the solution. This potential difference is then converted to a pH value using the Nernst equation. Optical sensors, on the other hand, measure changes in light absorption or emission due to pH-sensitive dyes.