A solar cell generates electricity from sunlight using the photovoltaic effect. It consists of a thin layer of p-type semiconductor on a thicker n-type semiconductor, forming a p-n junction. When light photons enter the junction, they create electron-hole pairs, separating the charges across the junction and generating a photovoltage. Connecting an external load allows a current to flow, converting sunlight into electricity. Solar cells find applications in powering devices, heating water, providing lighting, and more, harnessing the sun's energy.