/* TB6600 Stepper Motor Test Code -------------------------------- This example controls a stepper motor driver (TB6600) using Arduino UNO/Nano. Controls via Serial Monitor: '+' : Increase motor speed '-' : Decrease motor speed 'F' : Set direction Forward 'B' : Set direction Backward 'S' : Stop motor Wiring: STEP pin -> Arduino pin 3 DIR pin -> Arduino pin 5 ENA pin -> Arduino pin 7 (optional) Notes: - Use Serial Monitor at 115200 baud */ #define STEP_PIN 3 #define DIR_PIN 5 #define ENA_PIN 7 int stepDelay = 800; // microseconds (lower = faster) int minDelay = 200; // max speed limit int maxDelay = 2000; // min speed limit bool isRunning = false; bool direction = true; // true = forward void setup() { pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); pinMode(ENA_PIN, OUTPUT); digitalWrite(ENA_PIN, LOW); // enable driver digitalWrite(DIR_PIN, direction); Serial.begin(115200); } void loop() { if (Serial.available()) { char cmd = Serial.read(); if (cmd == '+') { stepDelay -= 50; if (stepDelay < minDelay) stepDelay = minDelay; } if (cmd == '-') { stepDelay += 50; if (stepDelay > maxDelay) stepDelay = maxDelay; } if (cmd == 'F' || cmd == 'f') { direction = true; digitalWrite(DIR_PIN, direction); isRunning = true; } if (cmd == 'B' || cmd == 'b') { direction = false; digitalWrite(DIR_PIN, direction); isRunning = true; } if (cmd == 'S' || cmd == 's') { isRunning = false; } } if (isRunning) { digitalWrite(STEP_PIN, HIGH); delayMicroseconds(stepDelay); digitalWrite(STEP_PIN, LOW); delayMicroseconds(stepDelay); } }