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.