In a single atom, electrons can only have discrete ranges of energy values. These ranges are called "atomic orbitals". When we say things like $1s^1$, $1s^22s^22p^2$, we are referring to atomic orbitals, which we learned about in chemistry class.
When atoms come together, they affect each other and change how the electrons are distributed. For example, if two identical hydrogen atoms are brought together, the wave functions of the electrons overlap and, due to the exclusion principle, can no longer be in the same quantum state. This splits the original equivalent energy levels into two different energy levels.
In a solid crystal, the energy levels of the electrons of all the atoms form several energy bands.
One of them is the valence band, which is the highest energy band that contains electrons at 0K.
The other one is the conduction band, which is the lowest energy band that is empty at 0K. Electrons in this band can move freely in the crystal, and they are responsible for the electric current in the crystal.
The energy gap between these two bands is called the band gap.
For metals, the valence band and conduction band have some overlap, allowing some electrons to move freely between them, which is why metals are good conductors. In contrast, insulators have a large band gap, making it extremely hard for electrons to move between them, which makes them poor conductors. Semiconductors are something in between; they have a small band gap. If some energy is given to the electrons, they may move between the two bands and conduct electricity.
When given some energy, electrons can move from the valence band to the conduction band, leaving a hole in the valence band. The hole can be treated as a positive charge, and it can move freely through the crystal.
After being given some energy, the electrons can move from the valence band to the conduction band, leaving a hole in the valence band. The hole can be treated as a positive charge, and it can move freely in the crystal.
The movement of electrons and holes forms a current in semiconductors. Both of them are called charge carriers.
In a pure semiconductor crystal, although some electrons may move to the conduction band, it is still too difficult to form a large enough current.
By adding a small number of atoms with more or fewer electrons than the host atoms, we can add more charge carriers into the crystal, making it easier for the crystal to conduct current. This process is called doping.
When we add atoms with more electrons than the host atoms, it is called n-type doping.
When we add atoms with fewer electrons than the host atoms, it is called p-type doping.
The added atom will form a new energy band in the band gap, and electrons can move from or to the new band.
When we press a p-type semiconductor and an n-type semiconductor close together, the electrons in the n-type semiconductor will move to the p-type semiconductor and fill the holes there.
- There are few charge carriers in this area, making it difficult for current to pass through. This area is called the depletion region.
- A potential difference will be formed in the junction. This potential difference is called the built-in potential.
When connecting the p-type semiconductor with the positive terminal of a battery and the n-type semiconductor with the negative terminal of the battery, electrons in the n-type semiconductor and holes in the p-type semiconductor will be pushed towards the depletion region, and the width of the depletion region will be reduced. Thus, the current is easier to pass through this area.
If we connect the battery oppositely, due to similar reasons, the depletion region will be wider, and current is harder to pass through this area.