Here's the limit switch circuit I'm using. One end of the limit switches goes to 12V (24V is also ok). The other ends go through current limiting resistors (a 1.0 kOhm resistor might work a little better) to the anodes. The cathodes are connected to ground. grbl already initializes the D9, D10 and D11 pins as inputs and enables the built-in pullup resistors, so just connect the collectors directly to the pins and the emitters to ground.
When the limit switch is tripped, current flows through the LED, lighting it up and pulling the transistor collector down to ground. Using the higher voltage helps drown out interference and the optical isolation adds another layer of protection against electrical noise.
The LTV-847 is a quad optocoupler so you can handle all of your limit switches using one chip, but really any decent optocoupler will do.
