This process occurs in mitochnodria and chloroplasts along the electron transport chains. Electrons passing down the chain to more electronegative particles allow hydrogen ions to be pumped from lower concentrations to higher concentrations of ions. This decreases the pH in the higher concentration region and increases the stored potential energy. The flow of hydrogen ions is reversed in mitochondria versus chloroplasts so see some diagrams on that. What happens next is the high concentration of hydrogen ions flows through a marvelously designed ATP Synthase portal protein structure that then spins and exposes active sites to ADP plus inorganic phosphate. This makes ATP in large numbers. This ATP helps to drive the dark reactions of photosynthesis and is the main source of ATP production in cellular respiration.