When there is a current in a wire, a circular magnetic field is produced around the wire. This magnetic field can deflect the needle of a magnetic compass. The strength of the magnetic field is greater:
A solenoid is a long coil of wire. When a direct electric current is passed through it, the shape of the magnetic field is very similar to the field of a bar magnet. The field inside a solenoid is strong and uniform. The small magnetic fields caused by the current in each turn of the coil add together to make a stronger overall magnetic field.
The strength of the magnetic field around a solenoid can be increased by:
The use of an iron core makes the solenoid into an electromagnet which can be switched on and off.