Hello all I need code to run a stepper motor nema23 to run one full circle once when i press and release a push button.I have nema23 arduino uno and tb6600
its very hard to find someone nearby who does this job in Noth wales
thank you.
Hello,
show your sketch, formated inside the IDE using CTRL+T and download here in code tags </>, to see how we can help you.
What does being in wales have to do with anything? I'm in east central Scotland, and have clients in England, Scotland, New Zealand, Poland, the USA & others.
Can you tell us if you have already wired the switch up, and what you have set the stepping mode to on your driver. I assume the Stepper motor has 1.8 Degree steps (200 steps per rev.).
I think this is close to what you want:
const int StepsPerRevolution = 200;
const byte DirectionPin = 2;
const byte StepPin = 3;
const byte ButtonPin = 4;
const unsigned long DebounceTime = 10;
boolean ButtonWasPressed = false;
unsigned long ButtonStateChangeTime = 0; // Debounce timer
const unsigned RPM = 60;
const unsigned long MillisecondsPerStep = (60000UL / RPM) / StepsPerRevolution;
void setup()
{
pinMode(DirectionPin, OUTPUT);
pinMode(StepPin, OUTPUT);
pinMode (ButtonPin, INPUT_PULLUP); // Button between Pin and Ground
digitalWrite(DirectionPin, HIGH); // Change to LOW if you want the other direction
}
void DoOneRevolution()
{
for (int i = 0; i < StepsPerRevolution; i++)
{
digitalWrite(StepPin, HIGH);
delay(MillisecondsPerStep / 2);
digitalWrite(StepPin, LOW);
delay(MillisecondsPerStep / 2);
}
}
void loop()
{
unsigned long currentTime = millis();
boolean buttonIsPressed = digitalRead(ButtonPin) == LOW; // Active LOW
// Check for button state change and do debounce
if (buttonIsPressed != ButtonWasPressed &&
currentTime - ButtonStateChangeTime > DebounceTime)
{
// Button state has changed
ButtonWasPressed = buttonIsPressed;
ButtonStateChangeTime = currentTime;
if (ButtonWasPressed)
{
// Button was just pressed
DoOneRevolution();
}
}
}
Thank you very very much John it is perfect
i meant its hard to find anyone doing this job locally
i rang few numbers i found online but they all said they are dealing with big businesses .
thank you it is sorted now
hi john do you still work on arduino coding?
Hi missdrew how can i get in touch with you for arduino coding?
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.