Hans Christian Oersted (August 14, 1777 - March 9, 1851) was a renowned Danish physicist and chemist who discovered that electric currents create magnetic fields, a discovery that had a dramatic impact and influence on scientific and technological development of the 19th century.
In 1820, during one of his lectures, H.C. Oersted noticed a compass needle deflected from magnetic north when an electric current from a battery was switched on and off, showing a relationship between electricity and magnetism.
The H. C. Oersted discovery showed that by connecting a battery to a wire, the wire generates an independent magnetic field.
Now, imagine the same battery connected to the wire, which is placed close to a magnetic material. Considering that the magnet mass is significantly larger than the wire’s, the wire will be attracted or repulsed, depending on the direction of the current.