i used this code in the bed.g
G1 Z-200 S1 F100 ; move Z down until the switch triggers
G30 P0 ; probe
You should probe from a sufficient Z height, say 5mm. You should not have any homing moves (i.e. G1 moves with S parameter) in bed.g. Try this:
M561 ; clear any bed transform, otherwise homing may be at the wrong height
G28 ; home all
G1 Z5 ;
G30 P0 X15 Y15 Z-99999 ; probe
G30 P1 X160 Y15 Z-99999 ;
G30 P2 X160 Y160 Z-99999 ;
G30 P3 X15 Y160 Z-99999 S0 ; probe and calibrate with 4 parameters (as there is 4 points)
G1 Z10 F350 ;
and i used mechanical limit swutch in z axis
the z axis in all points still down (the limit is triggered and do not stop down ) until the z postion bcome 0 and become up again