wiring limit switches

Hello all! my first post here. i made my own cnc mill based on arduino and some pololu (?) drivers

and i need to install some limit switches on it, but have no clue how to do it.
i've been reading bits and pieces here and there and if i understand things correctly i need to install pull up resistor somewhere and limit switch. i do have limit switches from ebay

http://www.ebay.com/itm/10-pc-TEMCo-Micro-Limit-Switch-Short-Roller-Lever-Arm-SPDT-Snap-Action-home-LOT-/400514508501?pt=LH_DefaultDomain_0&hash=item5d408666d5

and if i understand things correctly pull up resistor is just a regular resistor? i need exact specifications
and where it needs to be connected. i mean detailed explanation of how and where to connect it along with limit switch. i'm completely clueless.when it comes to a radio electronics and will appreciate any help.
here is a picture of how everything is connected on the board.

Thank you!

To detect the change in the switch you need to change the voltage on a digital input pin. Simply switching it to ground does not provide this. You need to connect a standard 10k resistor from 5v to the digital input pin. This way the pin will be high. You then connect the switch from the input pin to ground. When the switch contact closed, the input voltage goes to zero.

To read the switch simply check if it is high or low and proceed accordingly.

Weedpharma

Thank you for helping me with this problem! as i said above-i'm completely clueless about wiring and reading diagrams. i've found this diagram on internet, which looks exactly as you described, except for a different specs resistor(from what ive reading-to reduce the noise and false triggers)
but even when i'm looking at it-im's still confused about one thing(let's take x axis for example)-wire goes from 5v pin thru resistor into pin 9 and from pin 9 to the switch? can you confirm this, so make sure i understand you (and picture) correctly?
i apologize for such lame question.

Thank you!

i also found this one-

which is similar to what you are saying, with exeption that the resistor is between ground and switch and 5v goes straight to the switch. will this make any difference?

Thank you!

The first circuit is preferable.
Read about inputs here:-
Inputs page

Why not use the Arduino's internal pullup resistors - pinmode(swPin, INPUT_PULLUP);

...R

I think in this application the internal pullups are a bit weak. There is likely to be a lot of noise around and for better noise immunity I would use external pull up resistors, maybe down to 1K.

I agree with Mike on that pullup topic. This will get it done, but I myself would give myself separate inputs for each switch. You can use the Analog Inputs as Digital Pins starting with A0=D19, A1=D20 etc. It's also a better idea to use the NC contacts of the switch and look for it to open. That way, if a wire breaks or something smashes your switch, you will stop and not tear up your screw.

Think about what you do when you hit a limit: Just doing a STOP on that axis is crude, whereas if you knew WHICH LIMIT, you can allow a move in the opposite direction. With the switches being "or'ed" like they are, you have to manually crank yourself off the limit.

The other consideration is how you define "home". Usually this is done by slowly going in reverse until you hit the reverse limit, then slowly going forward until you have come off the switch and hit a rotary index switch or encoder mark.

rmetzner49:
I agree with Mike on that pullup topic. This will get it done, but I myself would give myself separate inputs for each switch. You can use the Analog Inputs as Digital Pins starting with A0=D19, A1=D20 etc. It's also a better idea to use the NC contacts of the switch and look for it to open. That way, if a wire breaks or something smashes your switch, you will stop and not tear up your screw.

Think about what you do when you hit a limit: Just doing a STOP on that axis is crude, whereas if you knew WHICH LIMIT, you can allow a move in the opposite direction. With the switches being "or'ed" like they are, you have to manually crank yourself off the limit.

The other consideration is how you define "home". Usually this is done by slowly going in reverse until you hit the reverse limit, then slowly going forward until you have come off the switch and hit a rotary index switch or encoder mark.

first of all-i like to thank you all for your responses.i did wire the switches as in diagram that i've posted above with 10K resistors. didn't work at all. i would assume it was due interference? i've ended up with 330 ohm resistors. this bring me to a next question-everyone is talking about best wiring practices, but i have no idea what exactly do they mean and how to apply it to my particular case. here is a close up on my setup on pic below. obviously a far cry from best wiring practices. i wired the limit switches with some speakers wire. whole thing looks just plain ugly after i done with it. can anyone give me some advise about what should i do to reduce the interference and where can i read about wiring management on such things like home made CNC?

and what is the good place(forum?) to find the answer or address all my CNC related questions.
it is arduino based setup ,running on grbl 0.9,using grbl controller as a front end gui.
another question i have is about homing. i've made a short vid of how things are working after i've added limit switches and press $H command in GRBL(without running $H first-machine would not respond to anything, giving me alert lock)

is this is how it's suppose to be? i did enabled hard and soft limit with soft limits are set to x=300,y=200 and z=100 mm. what happens after i send $H command is that machine would go first into a top of z -smashes into limit switch few times, then stops at very top, maybe 1-2 mm away from top switch on z. then it goes to far corner,does same on y,but hit switch only once on x and stayed there, in the corner,defined in soft limits. which doesn't looks logical at all.

Thank you once again for all your help and one more time- i would appreciate,if someone point me to the right direction or forum,where i can ask all those questions(because they are obviously not really related to arduino forum and this particular section of it)

s.i did wire the switches as in diagram that i've posted above with 10K resistors.

Which one, you posted two?

without running $H first-machine would not respond to anything, giving me alert lock)
......... is this is how it's suppose to be? i

No idea you haven't posted your code. It can be however you want it to be, you just write the code accordingly.

As to wiring, get some cable ties:-
Cable ties

Next get some pin headers and solder the whole row rather than individual pins, it is much more robust.
Pin Headers

You might want to consider some multicore cable
Multicored cable

Thank you for a quick respond! as i search thru the forums i also found this :

All you need to do for 100% perfect limit switch operation with Zero false triggers is:

Install 3 X 0.47 uf electrolytic capacitors.

http://www.shapeoko.com/forum/viewtopic.php?f=4&t=1290&start=20

here is where i stuck(while trying to make an sort of engraving of a logo my son’s favored game- wolfenstein): with homing(and soft and hard limits off) if i position the spindle manually in lower left corner (machine itself positioned as it was on grbl controller application)-ie- if i use grbl’s controllers arrows to move spindle in any direction-left,right back and forth and up or down-it does it in same direction of the arrow buttons on grbl controller. now- once again-if i position the spindle in lower left corner manually, using grbl controller arrow buttons and then load .nc file pictures above with g code and press begin-everything works fine.
but! when i enable homing,hard and soft limits and load same file after i’ve performed homing and press begin-nothing happens(pic 3).

pic 1-machine after start and homing done

in pic 2 i’m trying to explain where position actually is after $H

and pic 3-what happens after i done homing and tried to run the code.


i press begin and that was it. nothing happens. not a single move. not sure why. i also don’t understand how to get the machine in “sync” if you will with grbl controller application, which assumes than when machine is zeroed-it should be in lower left corner of working area, before it’s starts working.

Thank you once again for all your help and sorry for my english(not my native language)

g code that i’m trying to run is attached.

output_12_0002_w.zip (5.21 KB)

With homing enabled on GRBL nothing will happen until you home the machine, then zero your machine and start the file. The newest version of GRBL actually says that on startup. I have a lot of trouble with GrblController, have switched to Universal G-Code Sender, and it seems to handle homing better.

Also try reading this Quick GRBL setup guide for Windows (Arduino G-Code Interpreter) | Protoneer.co.nz
Tells how to modify homing directions ect.