The detector uses a magnetic field sensor (10) positioned in front of a ferromagnetic wall (1) relative to which the magnet (3) is displaced for providing a magnetic field (6). The useful magnetic flux provides a magnetic remanence (7) aligned with the magnet displacement axis which is retained after the magnet has passed by. The resulting fringing flux on the front side of the wall is detected via the magnetic field sensor. The latter registers a change in direction of the magnetic field for providing a switching signal.