Can someone please write me a code for my stepper motor with arduino uno ( Big Please )
Nema 23 with Tb 6560 driver
All i need the stepper to do is the following
Push button to start
Stepper motor 1 rotation clockwise
Delay for 2 seconds
Stepper motor 1 rotation Anticlockswise
End of circuit
Then if i want to repeat the process just push the start button again
You need to post this in the programmer for hire section.
I will quote $250USD per hour with a 3 month minimum and 1 month in advance plus all expenses.
I am, why? I last worked for money in 2000 and was paid $125. The rates have easily doubled in the last 25 years. Entry rate at Facebook or Google is $150,000 to $191,000 and a Principal Engineer (which sounds like my Staff level) can earn between $500,000 and $750,000. Now that I looked it up I see I am quoting too low, I need to change it to $400 an hour.
Just for fun, I tried AI (DeepSeek). I copied your whole post and used it as a prompt.
// Stepper Motor Control with NEMA 23 and TB6560
// Button press triggers 1 clockwise rotation, 2s delay, then 1 counter-clockwise rotation
// Define pins
const int dirPin = 5; // Direction pin
const int stepPin = 2; // Step pin
const int enablePin = 8; // Enable pin (optional)
const int buttonPin = A2; // Push button pin
// Stepper motor settings
const int stepsPerRevolution = 200; // Change this if your motor has different steps/rev
const int pulseWidthMicros = 20; // Pulse width in microseconds
const int rpm = 60; // Speed in RPM
// Calculate delay between steps in microseconds
const int stepDelay = 60000000 / (stepsPerRevolution * rpm);
// Variables
bool motorRunning = false;
bool lastButtonState = HIGH; // Assuming pull-up resistor is used
void setup()
{
// Set pin modes
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor
// Disable motor initially (if enable pin is used)
digitalWrite(enablePin, HIGH); // HIGH typically disables the driver
}
void loop()
{
// Read button state
bool currentButtonState = digitalRead(buttonPin);
// Check for button press (LOW because of pull-up)
if (currentButtonState == LOW && lastButtonState == HIGH && !motorRunning)
{
// Start the motor sequence
motorRunning = true;
// Enable motor (if enable pin is used)
digitalWrite(enablePin, LOW);
// Rotate clockwise
digitalWrite(dirPin, HIGH); // Set direction (may need to reverse depending on your setup)
rotateMotor(stepsPerRevolution);
// Delay for 2 seconds
delay(2000);
// Rotate counter-clockwise
digitalWrite(dirPin, LOW); // Reverse direction
rotateMotor(stepsPerRevolution);
// Disable motor (if enable pin is used)
digitalWrite(enablePin, HIGH);
motorRunning = false;
}
// Update last button state
lastButtonState = currentButtonState;
}
// Function to rotate the motor a specific number of steps
void rotateMotor(int steps)
{
for (int i = 0; i < steps; i++)
{
// Generate pulse
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay - pulseWidthMicros);
}
}
I altered the pin numbers and tested with a CNC shield and button. It appeared to work.
I think the code has a few errors, but perhaps can be used a basis.