One of the important discoveries of 19th-century physics was that a changing electric field produces a magnetic field, and vice versa. This phenomenon, known as "electromagnetic induction," makes it possible to construct an electromagnet using a piece of metal, a length of conducting wire and a source of electricity. In principle, the procedure is to coil the wire around a metal core and connect the wire to a power source, such as a battery. The magnetic field inside the coil, produced when current is flowing, magnetizes the bar. You can increase the strength of the magnet in several ways.
Increase the number of coils to increase the strength of the magnet. According to Ampere's Law, the strength of the magnetic field is directly proportional to the number of coils; doubling the number of coils doubles the field strength.
Pass more current through the wire. Ampere's Law also tells us that the strength of the magnetic field is proportional to the current, and you can increase the current by increasing the voltage of the power source. If you're using batteries, connect more by wiring them in series with the originals. To wire batteries in series, connect the negative terminal of one to the positive terminal of the other and put the load across the other set of terminals. The electrical resistance of the wire limits this method of increasing magnetic field strength; the wire will overheat if you increase the voltage too much.
Make the core out of soft iron. Iron is a magnetic material, and it amplifies the field produced by the electromagnet. If you have to use a steel item, such as a nail or bolt, avoid hardened or stainless steel. Neither of these materials are magnetic.
Bend the core into a C-shape. Reducing the distance between the poles of the electromagnet reduces the distance that the magnetic lines of force have to travel through air to complete the magnetic circuit. Air has a high reluctance to the flow of magnetic energy -- reluctance is analogous to electrical resistance -- while metal has low reluctance. The closer together you bring the poles of the magnet, the stronger the field will be.
Increasing the cross-sectional area of the wire reduces resistance and allows you to increase the voltage to strengthen the magnetic field, but you can't wind as many coils around the core if you use thicker wire.
The conductance of the wire matters. If you make the coil from steel wire, the magnetic field won't be as strong as it will be if you use copper wire.
The spacing between individual turns in the coil has no effect on the strength of the magnetic field.
When the coil becomes electrically charged, you can get a shock if you touch it. If you want to pick the magnet up, be sure to wear gloves made from an electrical insulator, such as rubber.