The sun had been shining for nearly four billion years before one human genius by the name Alexander Becquerel discovered what is now, the photovoltaic effect. The discovery opened ways on how to create an electric current from a conductor that’s hit by sun rays.
In a more technical way; the photovoltaic effect can be explained as a reaction between photons of light and hydrogen on an atomic scale. During this reaction, the electrons are catapulted and become free molecules; they are then captured and channeled into usable energy/electricity. Scientists have also developed a theory that when hydrogen gets used up, the photons will start reacting with helium.