A p-n junction is formed when we bring p-type and n-type material together by diffusion on the surface between them. Electrons start to diffuse from n-type to p-type. Similarly, holes diffuses from p-type region to n-type region. This diffusion creates a electron-hole free region in a very short distance at the interface region. This thin layer is called depletion region.
There is an electric field from the n-side to the p-side of the depletion region. Since the electrons are negative charges this electric field applies a force to an electron entering the depletion region. Any electron generated by sun light in the vicinity of the depletion region may pass to the n-side of the junction very easily. If we connect a wire or any load between the ends of n-type and p-type region with metal contacts, this electron will flow to the p-type through this external load. Something should energize the electrons in the p-type region to enter depletion region. Solar radiation is an excellent energy source to do this job.
It works on the principle of photovoltaic effect.
When sunlight hits the semiconductor, an electron springs up and is attracted toward the n-type semiconductor. This causes more negatives in the n-type semiconductors and more positives in the p-type, thus generating a higher flow of electricity. This is the photovoltaic effect. The electricity produced is called direct current (DC) and can be used immediately or stored in a battery.
Image courtesy – www.cheapsolarpanelssale.com