Pins 12 and 13 connected to limit switches 1 and 2


#1

As far as I can tell Pins 12 and 13 are supposed to be connected to limit switches 1 and 2. It’s a big of reverse engineering, but is the attached image correct?

So as a test I thought I’d see if I could read these two pins from the Orion. Which basically means:

pinMode (12,INPUT); // orion port 3
pinMode (13,INPUT); // orion port 3

…and, in a loop…

int iNewX1 = digitalRead (12) ;
int iNewX2 = digitalRead (13) ;

I get some info back on the serial, but it seems more noise than anything else. Is what I’ve written here correct?


#2

Aha! I needed to make the input reading using INPUT_PULLUP…

pinMode (12,INPUT_PULLUP);
pinMode (13,INPUT_PULLUP);

…which reduces the noise of an open circuit connection. Now my sketch only reacts when I click the microswitches…


#3

Yes, you should use INPUT_PULLUP (or INPUT_PULLDOWN) when the input isn’t always connected to a 5V or 0V.

If your input switch connects the input to 0, then it will hang in the air when the switch isn’t pressed. Then it will work more or less as an antenna, and receive random noise in the input. It will be free floating.

That is fixed with the internal pull up resistor to +5V (or internal pull down resistor to 0V), so instead it will be logical 1 (5V) when not connected, and 0 (0V) when the switch pulls it down to 0v.


#4

i would suggest just use the lib :

For Example:
MeLimitSwitch x_limitSwitch1(PORT_3,SLOT1);
MeLimitSwitch x_limitSwitch2(PORT_3,SLOT2);

MeLimitSwitch y_limitSwitch1(PORT_6,SLOT1);
MeLimitSwitch y_limitSwitch2(PORT_6,SLOT2);

if(x_limitSwitch1.touched()) //If the limit switch is touched, the return value is true.
{

No need to think about pins.


#5

But will that fix the electrical floating of the input is not electrical connected to 0 or 5V (through a resistor)?


#6