CNC-Shield Limit Switch confusion

Hello,

I am using a CNC shield to control stepper motors using the Arudino IDE. The part I am stuck on is using the limit switch pins to get input from a button. (Essentially I want to run the Ardunio button example, but with a CNC shield on the Arduino)

From the attached image I see that the X limit switch input goes to pin 9.

So, I have been testing whether input works using this code

const int inpin9 = 9;
int state9 = 0;

void setup() {
 Serial.begin(9600);

}

void loop() {
  state9 = digitalRead(inpin9);
  Serial.print(state9);
  delay(500);   

}

It works as expected when I have the push button set up per the button example. But when I add the CNC shield it does not work as expected.

If- on the CNC shield- I connect the postive side of X+ to the ground side of X+ as labeled by the green line in my image this does not return high.

I tried to measure the voltage and it does not seem like the V+ pin gives off any of its own. So, I tried to directly connect the 5V from the ardunio (blue arrow in my image) to the X+ ground. This may have had too much draw as my Arduino stopped returning serial monitor information when I did this and its LEDs turned off.

I have spent a few hours trying to figure this out, and I am very new to all of this- so dumbed down explanations would be much appreciated!

In summary: how do I get button input from a CNC shield using the limit switch pins?

Thank you for your time!

On the CNC shield the limit switches are expected to be normally open and are wired to ground with the internal pullup enabled. The switch will read high when not actuated (open) and low when actuated (closed).

Try this example code:

const byte xLimitPin = 9;
const byte yLimitPin = 10;
const byte zLimitPin = 11;


void setup()
{
   Serial.begin(115200);
   pinMode(xLimitPin, INPUT_PULLUP);
   pinMode(yLimitPin, INPUT_PULLUP);
   pinMode(zLimitPin, INPUT_PULLUP);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 200;
   if (millis() - timer >= interval)
   {
      timer = millis();
      Serial.print("x limit = ");
      Serial.print(digitalRead(xLimitPin));
      Serial.print("   y limit = ");
      Serial.print(digitalRead(yLimitPin));
      Serial.print("   z limit = ");
      Serial.println(digitalRead(zLimitPin));
   }
}

Both switches for each axis go to one pin. X+ and X- go to pin 9, Y+ and Y- to 10, Z+ and Z- to 11.

1 Like

Thank you so much! That absolutely clears up my confusion! I spent hours trying to figure this out and now my project works as intended!

Thank you again for putting in the time to help!