Hi All,
I have a problem I can't figure out. I have a stepper motor I would like to move every ~2.5 minutes if a limit switch is pressed. If the limit switch continues to be pressed I would like for it to follow this cycle. If the limit switch is not pressed, the motor would not spin. The problem I have is that the delay is very inconsistent. Sometimes it will spin in under a minute, and others it will take 8+ minutes to have the motor spin (if at all), all while the limit switch remains pressed. Would anyone take a look at my code and let me know where I might be going wrong? I very new to Arduino Programming (~4 Months), so any direction or advice would be greatly appreciated. Thanks!
These are the components I'm using
Arduino Nano Mega328p
Limit switch
5v Stepper
ULN2003 Driver Board
When the limit switch is not pressed it is held at ground. When the limit switch is pressed it will float since there is no pullup or pulldown resistor. The state of a floating switch is indeterminate (random). I would wire the switch to ground and the NO terminal to an input set to INPUT_PULLUP. The switch would then read HIGH when not pressed and LOW when pressed. Also I would put a 0.1uF ceramic cap across the switch to provide some hardware debounce and prevent false readings due to noise on the wire. If the wire is long the internal pullup may not be enough. Then use an external pullup, start with 10K and go down in value.
Thanks @groundFungus! This is some awesome information. I'm going to try this out tonight. I really appreciate you including the schematic for the limit switch!
Thanks @gcjr I have seen some examples where a limit switch was used to determine the rotation of a stepper. I'm also going to look into removeing the delay() function from the code. Millis() seems to be a much better option.