When a conducting coil moves in the vicinity of a magnet, an electric current is generated in the coil. The same thing happens when the magnet moves, instead of the coil. The following visual simulates an experiment which is the basis of a generator. This is Faraday's famous experiment.