"The perfect machine, which would use the energy generated by its own motion indefinitely, is unattainable."

Second Law of Thermodynamics

All known processes occurring in nature, whether mechanical, electrical, chemical or biological, obey the laws of thermodynamics. It is very important for engineering, for building machines, and to answer question about energy generation and use. In this context the following definitions are important:

Thermodynamic Equilibrium
It is when a system is in thermal, mechanical, radiative and chemical equilibrium. In this case, there is no matter or energy exchange between the system and the surroundings, there are no phase changes and there are no unbalanced electrical potentials within the system.
Reversible Processes
A process will be reversible if a system goes from an initial equilibrium state to a final equilibrium state through a succession of thermodynamic equilibrium states. For a real process, occurs very slowly (quasi-statically), so slowly that each step has only a minuscule (infinitesimal) difference to the previous equilibrium step, the process can be considered reversible. Otherwise, the process is said to be irreversible.
Spontaneous Processes
There are spontaneous and not spontaneous processes. For example, heat flows spontaneously from the hot body to the coldest, two gases in the same vessel mix spontaneously. However, there are non-spontaneous processes, where it is necessary to perform work for them to occur, as in the case of when we want to transfer the heat from a colder body to a warmer one, or to segregate a mixture of gases.
Thermal Machines
Devices that transform thermal energy into other forms of energy. Examples of thermal machines are: Steam engines (old models), alternative steam engines (piston, such as steam locomotive), combustion engines (diesel and Otto), reaction engines (jet turbine and firearms) and etc. Thermal machines make use of a working fluid, which draws heat from a hot source, and part of that amount of heat is effectively used in the work. The remaining energy of the heat is rejected for a cold source (see figure). So, we have: $$ W = Q_h - Q_c$$
Diagram of a heat engine. A substance, usually a gas, is heated by the hot source (red rectangle), then this substance performs an external work \(W_e\) (green ball), and lifts some weight as it expands, for example. Afterwards, the substance is cooled and compressed (blue rectangle). And finally, the substance is heated again and the cycle restars.
Engine efficiency
The efficiency \(\eta\) of a heat engine is the ratio of the work done and the amount of heat removed from the hot source: $$\eta = \frac{W}{Q_h}= \frac{Q_h – Q_c}{Q_h} = 1 - \frac{Q_c}{Q_h}.$$

Second Law and Consequences

We will present the second law in three different ways, because we believe that every statement highlights an important aspect.

Statement of Efficiency (Kelvin)
A process whose completely converts heat into work is impossible.
Statement of irreversibility (Clausius)
A process whose spontaneously transfers heat from a hot body to another one even hotter is impossible.
Statement of the Entropy
All natural processes evolve in the direction that leads to increased entropy. (In a simplified way, entropy can be understood as a measure of disorder of the system particles.)
Maximum Efficiency (Carnot Machine)
The Carnot machine is a theoretical thermal engine of maximum efficiency. That is, no real thermal machine, operating between the same hot and cold reservoirs can be more efficient than the Carnot machine operating between the same two thermal reservoirs. The efficiency of the Carnot cycle is: $$ \eta_c = 1 - \frac{T_c}{T_h},$$ where \(T_c\) and \(T_h\) are the temperatures of the hot and cold sources, respectively, Kenvin.
Carnot cycle. First, a reversible isothermal expansion (upper red line) occurs, where the hot reservoir gives an amount of heat \(Q_{in}\) to the system. Then, there is a reversible adiabatic expansion (right blue line), and the system does not exchange heat with the thermal reservoirs. After that, a reversible isothermal compression (lower red line) occurs, and the system rejects a quantity of heat \(Q_{out}\) for the cold reservoir. Finally, a reversible adiabatic compression occurs (left blue line), where the system does not exchange heat with the thermal reservoirs.
Carnot Refrigerator.
Refrigerators are machines that transfer heat (\(Q_c\)) from a system at a lower temperature (freezer) to the outside environment, which is at a higher temperature \((Q_h)\). Such transfer is not spontaneous, occurring at the expense of a work \(W\) (Compressor work). The performance coefficient \(\kappa\) is defined by: $$\kappa = \frac{∣Q_f∣}{|W∣} = \frac{∣Q_f∣}{∣Q_q∣ - ∣Q_f∣}$$
Entropy and the Second Law
The entropy \(S\), as well as pressure, volume and other quantities, can be used to caracterise a system in equilibrium. The second law of thermodynamics states that: "In any thermodynamic process that evolves from one equilibrium state to another, the entropy of the system \(+\) surroundings remains constant or increases." The entropy change of a real system, that undergoes a irreversible process between two equilibrium states, is, at least, equal to the change of entropy of a reversible process between the same states.
Calculation of the Entropy Change in an Isothermal Process.
$$\Delta S = \frac{\Delta Q}{T}$$ Where \(\Delta Q\) is the amount of heat exchanged by the system with the exterior, \(T\) is the temperature at which this exchange occurs. The entropy change of a system is positive when the amount of heat \(\Delta Q\) is positive, i.e., when the system receives heat. Its negative when the system outputs heat. The unit is \([S]=\frac{J}{K}\), in the \(IS\).
Variation of Entropy in a Reversible Adiabatic Process.
$$\Delta S = 0$$
Entropy and Free Energy.
Macroscopically, entropy is a quantity that is related to the free or usable energy of the system. An increase in entropy leads to a decrease in usable energy. Microscopically, entropy is related to "disorder." In natural processes, systems tend to evolve spontaneously into a state of greater disorder. For example, two gases separated into a container (order), they tend to mix spontaneously (disorder). The restoration of order is only possible by doing some work. The entropy function is associated with the concept of disorder, in such a way that the value of the function increases when the disorder in natural processes increases.

Beyond the Second law

We still have another law of thermodynamics.

Third Law
It is impossible for a system to reach the absolute zero degree, through a finite number of operations. Some consequences of the third law of thermodynamics: in absolute zero, the thermal capacity and coefficient of expansion of the bodies become zero.