The magnetic field produced due to current flowing in a coil or a solenoid can be used to magnetise a material like soft iron temporarily. The insulated copper wire is wrapped on a soft iron piece. When current is passed through the coil using a battery and a key the iron piece behaves like a bar magnet as long as current is being passed. Such a magnet is called an electromagnet.
