According to Livescience, a solar panel generates electricity when light strikes the silicon at its surface, and the energy forces electrons to flow through the material. This movement of electrons creates an electric current, and if enough silicon cells are connected together, it creates enough current to run lights and appliances or charge batteries.
When the sun's rays strike an object, the atoms at its surface absorb the energy. In most cases, this simply causes those molecules to vibrate, producing heat. In the case of silicon, however, the sun's rays actually knock electrons off of the atoms. Solar panels take advantage of this property to create an electrical current from sunlight.
In a solar panel, the topmost layer of silicon contains phosphorus, creating an electrically negative surface. The bottom layer contains boron, making it electrically positive. This ensures that when sunlight strikes the silicon, any freed electrons flow in one direction instead of simply causing a random discharge. As the electrons flow from one side of the panel to the other, they create an electric current, and metal charge plates transfer that current to connected wires to create usable electric power. The more cells that are connected together, the stronger the created electric current is once sunlight strikes the panel.