Place the wire over the compass so that it is parallel to the needle. Turn on the current. The needle rotates to where it is perpendicular to the wire, and it remains so no matter how you rotate the wire over the compass. In addition, you can show that in whichever direction the current flows, the north end of the compass needle always points 90° counterclockwise to it.
In 1820, Hans Christian Oersted – while performing a classroom demonstration! – discovered that a current in a wire produces a magnetic field around the wire. The relationship between this magnetic field and the current that produces it is given by Ampère’s law, which states ∮B · dl = μ0i, where dl is an element of a circular path around the wire, μ0 is the permeability constant, which equals 4π × 10-7 tesla·meter/ampere, and i is the current in the wire. By convention, current refers to the flow of positive charge, which is in the opposite direction to the flow of electrons. Evaluating the integral gives the magnitude of the magnetic field. ∮B · dl = (B)(2πr) = μ0i, or B = (μ0i/2πr). The right-hand rule (see demonstration 68.13 – Right-hand rule model) gives its direction. Place your right hand near the current-carrying wire, with the thumb pointing in the direction of the current. Now curl the fingers around the wire. Your fingertips point in the direction of the magnetic field (north).
When you place a current-carrying wire near a compass, perpendicular to the pivot axis of the needle as in this demonstration, the compass needle rotates so that it points tangent to the magnetic field (i.e., parallel to the field lines), in the direction of the field. This brings the needle perpendicular to the wire, with the north end pointing 90° counterclockwise to the current flowing in the wire.
Demonstration 68.18 – Compasses and current-carrying wire, shows four compasses placed around a current-carrying wire, which is parallel to the pivot axes of their needles.
References:
1) Halliday, David and Resnick, Robert. Physics, Part Two, Third Edition (New York: John Wiley and Sons, 1977), pp. 746-749.