Hans Christian Orsted discovered the initial ideas where electrical currents create magnetic fields.

During a lecture, on 21 April 1820, Oersted noticed that the needle of his compass, that was pointing toward magnetic north, was pulled toward an electrical current when the battery was switched on and then returned to magnetic north the the current was switched off. Confirming the relationship between electricity and magnetism.