There are a variety of different devices that use sunlight to generate power, but the basic way that a solar cell works is the same. In a photovoltaic (PV) cell, there are two layers of silicon, both of which are doped, or lightly mixed, with a certain element. Typically, one side is doped with boron and the other with arsenic.
Because of the way each element bonds to the silicon, the layer containing boron, called the n-type layer, has a surplus of free electrons. The other side, the p-type layer, has a deficit of electrons, called holes. The p-type layer and n-type layer are pressed closely against each other and linked by a wire connected to an external load. This creates a circuit in the solar cell.
When sunlight of the right energy level hits the n-type layer, which is on top, it excites some of the free electrons, which break loose from their natural state — pairs — and flow across the boundary between the layers to create a current. This only works if the two layers of the cell are pressed directly into each other. This is usually accomplished by fabricating both sides as part of the same process.
The current flows through the p-layer into the wire, which goes to the load, generally used to store electricity. Direct current (DC) is produced. If alternating current (AC) for household appliances is desired, the DC current is put through an alternator.
After flowing through the load, the current continues back into the n-layer, which is lacking in electrons in some areas due to the current. The process continues. A current is generated without any mechanical input. Unfortunately, the materials used to make solar cells can be quite expensive.
For protection, the top layer of the solar cell is covered with a glass plate affixed with transparent resin. The entire setup is called a p-n junction diode. More sophisticated cells use a series of p-n junction diodes.
The first solar cells were only 1% efficient. Today, commercial solar panels are between 5% and 15% efficient. There are currently millions of dollars going into research on improving these percentages.