Patent attributes
A magnetic sensor includes first through fourth GMR elements. The fixed layers of the first through fourth GMR elements have respective magnetization directions toward the X-axis positive, X-axis negative, Y-axis negative, and Y-axis positive directions. When a magnet is located at the initial position, the free layers of the first through fourth GMR elements have respective magnetization directions toward the Y-axis positive, Y-axis negative, X-axis negative, and X-axis positive directions. When the magnet is located at the initial position, the magnetization axis of the magnet passes through the centroid of the first through fourth GMR elements. The magnetic sensor detects, from the resistances of these GMR elements, changes in horizontal magnetic fields of the magnet which pass through the first through fourth GMR elements and which change in accordance with the moved position of the magnet, to thereby determine the position of the magnet.