about limit switches connected to Arduino

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
I found the wiring drawing like below, question is if hooked 6 switches, can I use just one 10 KΩ ? Thanks.
limit.jpg
 

djsfantasi

Joined Apr 11, 2010
9,163
I’d recommend using 10kΩ resistors.

Did you know that if you code properly, no resistor is needed? In the setup() routine, initialize the pin with the INPUT_PULLUP option. Then connect the pin through the switch to ground.

This way, if the switch is open, the pin will return HIGH and if it’s closed, it’s value will be LOW. If you desire the opposite values, it’s easy to invert the value/logic in your program/sketch.
 

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
I’d recommend using 10kΩ resistors.

Did you know that if you code properly, no resistor is needed? In the setup() routine, initialize the pin with the INPUT_PULLUP option. Then connect the pin through the switch to ground.

This way, if the switch is open, the pin will return HIGH and if it’s closed, it’s value will be LOW. If you desire the opposite values, it’s easy to invert the value/logic in your program/sketch.
Thanks.
I'll try not use resistor.
As a knowledge question, can six switches share just one 10kΩ resistors? will it generate any unfavorable factors?
Best
 

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
Are all the limit switches going to just one input?
If so, only one resistor is needed. But if just one input, then you will not know the switch that caused the limit signal.

As @djsfantasi says, you can use no resistor if the internal pullups are on. Then, connect the switched from the input to GND, not +5V.

pinMode(limit_Switch, INPUT_PULLUP);

see....
https://www.arduino.cc/en/Tutorial/DigitalPins
Thanks.
I'll use the pinMode(limit_Switch, INPUT_PULLUP) to get rid of the resistor. I still wonder if it's OK to use just one resistor and wiring all switches to one GND? each switch go one input.
 

upand_at_them

Joined May 15, 2010
940
You should use the resistor as a pullup, not a pulldown. The way you have it connected the Arduino pin will not see any current limiting. The resistor is for the Arduino input, to prevent it from floating. And, yes, only one resistor is needed, because it's for the Arduino pin.
 

djsfantasi

Joined Apr 11, 2010
9,163
You should use the resistor as a pullup, not a pulldown. The way you have it connected the Arduino pin will not see any current limiting. The resistor is for the Arduino input, to prevent it from floating. And, yes, only one resistor is needed, because it's for the Arduino pin.
You don’t use PULLUP resistors on an Arduino. They are built in.

Each pin/switch combo needs its own resistor. So you need one resistor for each Arduino pin.
 

Reloadron

Joined Jan 15, 2015
7,517
It looks like this, sorry I didn't have a lever micro-switch to illustrate so pretend. :)
PULLUP EXAMPLE.png

When the switch is closed a logic low (0) is applied, when the switch is open a logic high (1) is applied. The choice of using an internal or external pullup resistor rest with the user. On most boards the value of the internal pullup resistor well exceeds the typical external 10K pullup value. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board. Even then the values you see are approximate.

For what you are doing it really matters not so coding for an internal pullup will do just fine as you likely are well aware by now. In your example drawing in post #1 the resistor is acting as a pulldown and the logic would be reversed from what I have posted here. Just a matter of the logic level based on switch open or closed.

That's my story and I am sticking to it.

Ron
 

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
You should use the resistor as a pullup, not a pulldown. The way you have it connected the Arduino pin will not see any current limiting. The resistor is for the Arduino input, to prevent it from floating. And, yes, only one resistor is needed, because it's for the Arduino pin.
Thanks.
What I mean is just use one resistor for all 6 switches, not one resistor for 1 switch, if it's OK? that means hook up 6 switches in parallel to one resistor to GND.
best
 

Deleted member 115935

Joined Dec 31, 1969
0
If you try drawing up the 6 switches, and try one resistor
then see what happens if you press one or two switches.

You need 6 resistors.
 

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
It looks like this, sorry I didn't have a lever micro-switch to illustrate so pretend. :)
View attachment 209404

When the switch is closed a logic low (0) is applied, when the switch is open a logic high (1) is applied. The choice of using an internal or external pullup resistor rest with the user. On most boards the value of the internal pullup resistor well exceeds the typical external 10K pullup value. On most AVR-based boards, the value is guaranteed to be between 20kΩ and 50kΩ. On the Arduino Due, it is between 50kΩ and 150kΩ. For the exact value, consult the datasheet of the microcontroller on your board. Even then the values you see are approximate.

For what you are doing it really matters not so coding for an internal pullup will do just fine as you likely are well aware by now. In your example drawing in post #1 the resistor is acting as a pulldown and the logic would be reversed from what I have posted here. Just a matter of the logic level based on switch open or closed.

That's my story and I am sticking to it.

Ron
Thanks.
I'd use internal pull-up resistor in fact.
Best.
 

KeithWalker

Joined Jul 10, 2017
3,091
Thanks.
What I mean is just use one resistor for all 6 switches, not one resistor for 1 switch, if it's OK? that means hook up 6 switches in parallel to one resistor to GND.
best
You can connect all the switches in parallel if you only need to know when one of the switches closes. If you need to know which one, you will need to connect each switch to a separate pin.
You can use a pull-up resistor or a pull down resistor. Either way, the input will not be floating when the switch is open.
Regards,
Keith
 
Last edited:

upand_at_them

Joined May 15, 2010
940
Right. And the connections should be as drawn in post #10. What is shown in post #1 is wrong.

Would be helpful if LAOADAM described his situation more. You can certainly have 6 switches in parallel, if that's what you want. Just seems odd to everyone trying to help.
 

Thread Starter

LAOADAM

Joined Nov 21, 2018
879
You can connect all the switches in parallel if you only need to know when one of the switches closes. If you need to know which one, you will need to connect each switch to a separate pin.
You can use a pull-up resistor or a pull down resistor. Either way, the input will not be floating when the switch is open.
Regards,
Keith
Thanks.
I mean each switch wire to one Arduino pin, but the other end together with a resistor like this:

6 switches.JPG6 switches.JPG
 

dendad

Joined Feb 20, 2016
4,476
Your drawing looks like you a r trying to use 6 inputs with one resistor. that will not work.

Only if it uses one input!
6 switches.JPG
You need one resistor per input. Either the internal or an external one.
 

crutschow

Joined Mar 14, 2008
34,420
If you are concerned about reliability it's better to use a normally-closed contact for the limit switch, which then opens when the switch is actuated.
That way an open-circuit anywhere (including a failed-open switch) will be recorded as a limit condition.
Open-circuit failures are generally more common than short-circuit failures.
 
Top