Here is a simplified and hopefully easy to understand summary of how solar (PV) panels work.
Think of the sun as a giant ball of hot gases that gives off a vast amount of energy through a process called fusion. Fusion is when hydrogen atoms are slammed together to produce helium and when this happens its gives off loads of light and heat.
Photons are little particles inside that light that travel down to us here on earth from the sun. Humans have engineered devices that are able to absorb and use these photons to create electricity. These devices are called solar photovoltaic (PV) cells and the vast majority of solar panels you see on roofs are made up of these PV cells.
Solar PV cells are made from silicon, a very common element, which is a semiconductor material. That just means it is halfway between a conductor (a material that allows electricity to easily flow through it) and an insulator (a material that doesn’t). A silicon solar cell has been designed in a way so that it has two types of silicon- a P type and an N type. The two of them are put together creating a junction and in turn an electric field. That electric field isn’t enough to create a sustainable current. But when photons hit the solar cell they excite and energise electrons in the Solar PV material- this process generates pairs of charges (electron-hole pairs). The electrons start to move and the built-in electric field guides those electrons to the N-type side and the holes go to the P-type side. Now if the cell is connected into a circuit, which is a closed loop pathway where current can flow from a voltage source to a load and back, then you create a usable current that lights up a home!
When these cells create this current it is in the form of DC (direct current- which means flowing in one direction). To be integrated into the grid or used in homes and buildings it needs to be converted to AC (alternating current). To do this we need an inverter which is an electric device that converts it for us. Also, to be safe and secure we put in a couple of isolators so that parts of the system can be cut off in case of an emergency. There are various regulations around this and also around the labelling on all these items that need to be met to pass regulatory standards.
This does not go in depth into the physics and mechanics behind this technology, but hopefully it provides a bit of insight into the magic that is taking place on your roof when you install these panels!