How does a thermocouple work?please give as much detail as possible, including how exactly the two different junctions work to produce electricity and how it measures temperature.
See the figure below. For better understanding we will describe the Peltier effect, which is the reverse of the Seebeck effect (thermocouple effect).
Suppose you have two metals in close contact. As it is known the conduction in metals is due to last energy bands being incomplete occupied with electrons. The energy bands for each metal are represented in the figure. Since the metals are different, their work function (energy necessary for an electron to be extracted into vacuum) is different. The difference in these work functions is the contact potential of the metals (much like the contact potential in a pn junction).
`phi_1 - phi_2 =e*U`
When a voltage is applied to the junction of the two metals, electrons from metal 2 that have a higher energy (due to higher band energy) as they travel to metal 1, fall to a smaller energy (lower band energy for metal 1). Thus they loose a part of their initial electric energy which is transferred to the crystal lattice (to the atoms in the metals) as kinetic energy of vibration. Therefore the temperature of the junction of the two metals increases.
The reverse of this effect is also valid, when a voltage difference appears as a result of heating the junction of the two metals is called thermoelectric effect (or Seebeck effect). The voltage difference is proportional to the temperature of the junction, on small intervals.