Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Micro-Controlled Stepper Motor Pump System with TB6600 Driver

View and Edit Project In Cirkit DesignerImage of Arduino Micro-Controlled Stepper Motor Pump System with TB6600 Driver

Circuit Documentation

Summary

This circuit is designed to control a stepper motor using an Arduino Micro (Rev3) and a TB6600 stepper motor driver. The circuit is powered by a 12V power supply, which is stepped down using an LM2596 Step Down Module to provide the necessary voltage to the Arduino. The Arduino is programmed to control the stepper motor's speed and direction based on user-defined parameters.

Component List

LM2596 Step Down Module

Stepper Motor (Bipolar)

12V Power Supply

TB6600

Arduino Micro (Rev3)

Wiring Details

LM2596 Step Down Module

Stepper Motor (Bipolar)

12V Power Supply

TB6600

Arduino Micro (Rev3)

Code Documentation

Arduino Code

// ============================ USER INPUT SECTION ============================
// Users can adjust these values to control the pump behavior.

#define TARGET_RPM 60           // Target RPM for the pump motor (Revolutions per Minute)
#define MOTOR_RUN_DURATION 5    // Duration the pump runs (in minutes)
#define MOTOR_RUN_INTERVAL 10   // Interval between pump runs (in minutes)

// ============================ END OF USER INPUT SECTION =====================

// ============================= SYSTEM CONSTANTS =============================
#define MICROSTEP 16            // Microstep setting on the TB6600 driver
#define STEPS_PER_REV 200       // Full steps per revolution for the stepper motor
#define STEP_PIN 12             // Step pin
#define DIR_PIN 11              // Direction pin
#define ENABLE_PIN 10           // Enable pin
// ============================================================================

// Globals
unsigned long previousRunTime = 0;  // Keeps track of the last pump cycle start time
unsigned long delayPerStep;         // Time delay per step in microseconds

void setup() {
  // Initialize pins
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  pinMode(ENABLE_PIN, OUTPUT);

  // Set the motor direction (forward)
  digitalWrite(DIR_PIN, HIGH); // Forward direction
  
  // Enable the motor driver
  digitalWrite(ENABLE_PIN, LOW); // Active LOW to enable motor
  
  // Calculate delay per step in microseconds
  delayPerStep = calculateDelay();
}

void loop() {
  unsigned long currentTime = millis(); // Current time in milliseconds

  // Check if it's time to run the motor
  if (currentTime - previousRunTime >= MOTOR_RUN_INTERVAL * 60000UL) {
    previousRunTime = currentTime; // Update the last run time

    // Run the motor for the specified duration
    unsigned long runEndTime = currentTime + (MOTOR_RUN_DURATION * 60000UL);
    while (millis() < runEndTime) {
      stepMotor(1); // Step one step
    }

    // Optionally disable the motor after running
    digitalWrite(ENABLE_PIN, HIGH); // Disable motor
  }
}

// Function to calculate the delay per step based on RPM and motor characteristics
unsigned long calculateDelay() {
  return 60000000L / (TARGET_RPM * STEPS_PER_REV * MICROSTEP); // Delay in microseconds
}

// Function to step the motor by one step
void stepMotor(int steps) {
  for (int i = 0; i < steps; i++) {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(delayPerStep / 2); // Half delay for HIGH pulse
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(delayPerStep / 2); // Half delay for LOW pulse
  }
}

This code is designed to control the stepper motor's speed and direction based on user-defined parameters. The motor runs at a target RPM for a specified duration and interval. The TB6600 driver is used to interface between the Arduino and the stepper motor, providing the necessary current and voltage to drive the motor.