As electrons are moving through the ETC, how is ATP produced for the active transport to even happen?
ATP formation is done using the Complex V called as ATPsynthase (also called as F0/F1 particle) and the theory explaining this process is called as the Chemiosmotic Theory2. 

During cellular respirationKreb’s cycle (in the mitochondria) and Light dependent Photophosphorylation photosynthesis (in the chloroplast thylakoids) a set of reactions establish a proton gradient across the inter-membrane space ( hereby referred to as IMS) of the mitochondria/chloroplast( if you remember mitochondria/chloroplast are double membrane bound organelles). 

Just as in a battery/cell we have EMF(electron motive force) we have, in the IMS of the mitochondrion/chloroplasts, a proton motive force. 

Since substances always flow from higher potential to lower potential, the IMS of mitochondrion/chloroplast having a high amount of protons is a region of high potential and lumen of mitochondrion/chloroplast is a region of low potential since there are less number of protons. 

The only way protons can move from the IMS  of the mitochondrion/chloroplast to the lumen of the mitochondrion/chloroplast is via the complex V (also known as ATPsynthase). 

The ATPsynthase is a lollipop shaped protein structure that is freely rotatable and it brings ADP &amp; phosphate molecules close together so that a covalent bond can be formed in between them. 

How does it exactly do this you ask?
So let’s summarise what all we have here:


ATPsynthase that can rotate about its rotor. 
Proton gradient across the IMS ( high potential) and the lumen ( low potential). 
The only way out for the protons is via the ATPsynthase. 


Now we can see a link here. 

So what happens is, there’s the F0 subunit of the ATPsynthase through which the protons are able to move across the membrane and during that movement the rotate the F1 subunit. 
During this rotation shown in animation here  the ADP &amp; the phosphate group which are present in the active site of the F1 subunit are brought near each other and due to atomic interactions a bond is formed. 
The mechanical energy ( movement of protons across the membrane) is converted into chemical energy ( covalent bond) between the two molecules. 
This is the process via which the currency of the cell, ATP, is produced. 
Hope that answers the question.