The above coding is the code I want to modify further to control the stepper motor. As it is very heavy and inconvenient to test it by stepper motor. I try to test by using LED first .when I press the button, The LED turn on and vice versa. However when I upload the program. The LED turns off When I press the button and turn it on when I release it. Can someone help me troubleshoot and reverse the LED output to the correct one?
Yes- show how the button is wired... does it go from the pin to ground or from the pin to 5V, and do you have a pullup or pulldown resistor in the circuit? And show how the led is wired: where do the cathode and anode connect to?
Normal practice is to wire the button from the pin to ground, and use:
pinMode(BUTTON_PIN, INPUT_PULLUP);
That will keep the pin HIGH until it's pressed, at which point it will go low.
It looks as if you're expecting a LOW when pressed, but without either an external pullup or the use of INPUT_PULLUP, that won't be.
ps: Your schematic doesn't need to be anything fancy from a cad type system. Photo of pen and paper drawing is fine, or do some blocks and lines in Paint or Powerpoint even.
Sorry for the long waiting for the schematic. I Finally find back my tinkered account and create the schematic picture
For the Pullup point. I have try to do so and the LED does not light up. Might be the Ohm of the resistance is too high or something else. Maybe I try it later on
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project See About the Installation & Troubleshooting category.