Direct current (DC) is generated by sources that provide a constant flow of electric charge in one direction. There are several methods to generate DC, but I'll describe two common ones:
Batteries: Batteries are a portable and widely used source of DC. They generate electricity through chemical reactions. A battery consists of two electrodes (a positive and a negative terminal) immersed in an electrolyte solution or separated by a separator. Chemical reactions occur at the electrodes, causing a buildup of electric charge. This charge flows from the negative terminal to the positive terminal, creating a direct current.
Rectifiers: AC (alternating current) power, which periodically changes direction, is the standard form of electricity supplied by power plants and the electrical grid. To convert AC to DC, a device called a rectifier is used. A rectifier consists of diodes that allow the flow of electric current in one direction while blocking it in the opposite direction. By connecting a rectifier to an AC power source, the alternating current is converted into pulsating DC. This pulsating DC can be further smoothed using filters or capacitors to obtain a more constant DC voltage.
In addition to batteries and rectifiers, other methods such as dynamo generators, solar cells, and fuel cells can also produce direct current, each with its own principles and mechanisms.