The electromagnet was invented by Andre Ampere in 1825 after several years of work by many people regarding the magnetic properties of current carrying wires. In 1819 Hans Christian Oersted performed an experiment to show that a wire carrying an electrical current could influence a nearby compass needle. The diagram below shows what was happening.

The wire produces loops of magnetic field lines around it. Their direction can be determined by the right-hand screw rule. Imagine turning a screw so that it moves into a piece of wood. You have to turn it clockwise, and it will move forward. In analogy, the current represents the movement of the screw, and the resulting field line direction is the direction of the turning.
If a wire is wound into a coil, then the field lines add up in such a way as to produce a set of field lines that surround the coil in a similar way to those that surround a permanent bar magnet.
If further, a piece of soft iron is placed inside the coil, then the magnetic domains in the iron align with the field lines and they themselves serve as many little bar magnets in the iron, creating a powerful bar magnet for as long as the current is switched on. This is what we call an electromagnet.
The idea of a switchable magnet has many applications. They are seen in car scrap yards where a large electromagnet is used to pick up cars, carry them to another location, and then drop them there by switching off the current to the electromagnet coil.
We have built a simple electromagnet which contains a 2.5cm thick iron bar 30cm long, and with two layers of 1mm thick insulated copper wire wrapped around. The electromagnet will pick up large bunches of keys, and can be used separate magnetic and non-magnetic coins. It is powered from a 12V DC power supply capable of supplying up to 7A.
Household nails, and hook-up wire bough from hobby stores cab be used to built simple electromagnets. Wind around thirty turns of hook-up wire around a 4" nail, and then connect up to a 1.5V battery. You should be able to pick up small paper clips or pins with this simple home-made electromagnet.