Using a 5 wire NO/NC LED button with Arduino correctly

I am trying to build a simple motor test sketch, currently, to test a NEMA 23 stepper motor and the DM542T stepper driver.

Here is the code, and I am having trouble figuring out how to properly wire the 5-lead button (+, -, Common, NO, NC)

Here is the code

// Pin numbers
   const int buttonPin = 2;
   const int directionPin = 8;
   const int stepPin = 9;

   // Other constants
   const int NumSteps = 5000; // steps
   const int Speed = 500; 

   void setup() {
     pinMode(buttonPin, INPUT_PULLUP);
     pinMode(directionPin, OUTPUT);
     pinMode(stepPin, OUTPUT);
     digitalWrite(directionPin, LOW);
     digitalWrite(stepPin, LOW);
   }

   void loop() {
     if (digitalRead(buttonPin)) {
       // Move in one direction
       for (int distance = 0; distance < NumSteps; distance++) {
         digitalWrite(stepPin, HIGH);
         delayMicroseconds(Speed);
         digitalWrite(stepPin, LOW);
         delayMicroseconds(Speed);
       }
      // Reverse direction
      digitalWrite(directionPin, !digitalRead(directionPin));
    }
     delay(5);
   }

The button is a momentary button, so I am holding it in to simulate a latching button.

I have the buttons Common and Neg leads wired together, and connected to the Gnd pin on the Arduino (mega rev3)
I have the buttons Positive and the NC wired together and connected to pin 2.

Wiring that button in that manner, works fine in the button-controlled blink sketch, but is not working here (LED on the button doesn't light up and the motor test doesn't run).

Note:
I am using a 5 lead momentary button as that what the project these motors will be for will be using.

The DM542T Dir - and Pul - are wired to Gnd on the mega and the Dir + is pin 8 and Pul + is pin 9

Further Notes:
When I separate the common and neg and send the common to Gnd and the Negative to Pin 2, the LED is off on the Arduino and the button turns it on, but it doesn't turn on the LED on the button. If I switch those two, so common goes to Pin 2 and Negative goes to Gnd, the LED on the Arduino AND the LED on the button stay lit but the button does nothing.

Objective:
Find the proper wiring for the 5 leads so that when the button is pressed it turns on the light on the button because if it does that means it's signaled the pin and the motor functionality should work.

Any help appreciated.

Hello dinotom
Post a picture and the datasheet of the button used.
Have a nice day and enjoy coding in C++.
Дайте миру шанс!

There is no data sheet, it is a standard 5 wire LED button, +,-,common,NC,NO. Here is a link to the button. 5 wire LED button

“connected to the Gnd pin on the Arduino (mega rev3)“

Maybe try:

if (digitalRead(buttonPin) == LOW)

I made that change, but the button does not light up nor do the motors turn when the button is pressed.

Run a simple sketch that prints out the state of your button switch state to prove you have things wired correctly.

Start with a simple wire as a switch.


Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

No disrespect, but the reason I posted is I'm certain it isn't wired correctly. The led on the button would be lighting up if it was. The button is printing 1 on the serial monitor at all times whether pressed or not.

If you have a DMM, measure between terminals to see if you get continuity when the switch operates.

By your link to the switch, you need 12 volts to light the led: " * LED Voltage- 12VDC

  • LED Nominal Current- 15 mA". Please show a block diagram of how you have all this stuff connected and powered!

With the NC and + connected together to 5V and common and - connected together to Gnd, you can turn on/off the board led with the button and the led on the button lights up just fine.

As noted in the post, on the DM542T Dir+ is going to pin 8, Pul+ going to pin 9, Dir- and Pul- are going to Gnd. On the 5 wire button, NO is unused, NC and + are on the 5V pin and common and - are going to pin 2.

The driver is powered from a 24V power supply and the Arduino is usb powered to my pc, for now

With wiring as mentioned, its 0V static and 0V pressed, as expected since it's not working. Sorry, you asked for continuity, its .3ohms static and 38 ohms when pressed.

Thanks for the data sheet, couldn't find it 4 different vendor sites

google turned it up by using the PN

These are essentially the same, try other terminals.

If it is a LED, it will light up perfectly well on 5 V and given the specifications, draw 3 mA. Not as bright as 15 mA, but perfectly visible.

In the "olden days", an incandescent 12 V bulb would be barely visible on 5 V.

Unless you wore IR imaging goggles! LOL

I can see the dim red glow of "IR" LED's used in night vision cams, so can most folx.

Here's a datasheet from superbrightleds.com that shows the various way a lighted LED with uncommitted SPDT switch can be wired.

Found this on the web (might not be the exact same product):

OP: As you can see it can be wired several ways depending on how you want it to operate. Don't think of it as a lighted switch, think of it as a SPDT switch with an uncommitted LED. The LED can be wired to a DO and PWM modulated if you want. It doesn't have to tie back to the switch side of things at all. You could wire JUST the LED or JUST the switch. The software relation of the switch and the LED is up to you. I kinda like LEDs that brighten and dim slowly instead of just blinking. Seems more sinister that way especially with a RED button. LOL


Open the pod bay doors, HAL.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.