Just a thought although all of the above is correct are we assuming that the sensor has a resistor built in of say about 10K If not would it be prudent to put a current limiting R in.. My sensors have 10K internal so not neaded.

Also if you home at the middle you have gcode with -ve and +ve code I find it more convenient to have the home switch at one end then all gcode is +ve (for me being a novice it's easier to read) ..Clive