The device for counting the strokes of a piston sliding within a cylinder comprises a support housing a magnet which generates a magnetic field. The support also houses a sensor arranged to sense the magnetic field, such that the passage of the piston into a position corresponding with the magnet causes a disturbance in the magnetic field, which is sensed by the sensor, to indicate a stroke of the piston.