Controlling Stepper Motor from a Switch using Arduino Uno and CNC Shield


I am trying to control a standard stepper motor using a CNC Shield connected to an Arduino Uno. I have the driver and stepper motor plugged in to use them in the X-position. I am unsure where to plug in the switch on the CNC shield to be able to control the motor. There are ports labeled “X.STEP/DIR” , and two under END STOPS labeled “-X” and “+X”. The code I have is designed to move the motor when the switch is pressed, but when pressing it down the motor will not move. I am also not sure which pin number to assign the switch because all of the diagrams online for the CNC shield do not contain numbers.

For the testing purposes I plugged the switch into “-X” and used “Pin 5” in the code.

End goal of this is to control a motorized filament spool for a 3D Printer

Below is pictures of all the materials used and uploads of my attempted code.

Any help is appreciated!

Devices Used:

  • Arduino Uno
  • CNC Shield (V3)
  • Driver
  • Nema 17 (42mm) motor (1.8 degree)
  • X-Stop switch (Normally used in 3D printers)
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
int motorSpeed = 100; // for your motor
int endStop = 0;
int endStop_pin=5;
int stepCount = 0;

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {

void loop() {
Serial.print("End Stop =        " );


      if(endStop==1) //Low means pressed down 
         //myStepper.step(100); //Amount of steps


X+ and X- limit switches connects to pin 9.

uno cns shield pinout.jpg

Pictures of code are virtually worthless. I can't put the code into an editor to examine. Read the how to use the forum-please read sticky to see how to properly post code and some advice on how to get the most from the forum.

uno cns shield pinout.jpg

The Stepper library is for 4 pin stepper drivers, not the 2 pin step/dir drivers. The AccelStepper library is for the step/dir drivers. Your code is completely wrong for the drivers that you have.

The simple stepper code tutorial is a good start for testing the stepper and the stepper basics tutorial for information on the step/dir type drivers.