Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Nano-Controlled Nema 17 Stepper Motor with TMC2226 Driver and LiPo Battery Power

Image of Arduino Nano-Controlled Nema 17 Stepper Motor with TMC2226 Driver and LiPo Battery Power

Circuit Documentation

Summary

This circuit is designed to control a Nema 17 stepper motor using an Arduino Nano and a TMC2226 stepper driver. The motor is powered by a LiPo battery. The Arduino Nano sends step and direction signals to the TMC2226 driver to control the motor's movement.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. TMC2226 Stepper Driver

    • Description: A stepper motor driver that provides high precision and smooth motion control.
    • Pins: VMOT, 2B, GND, 2A, 1A, 1B, VDD, STEP, DIR, NC, MS2, MS1, EN, TX, RX, DIAG, VREF, INDEX
  3. Nema 17 42-STH48

    • Description: A high-torque stepper motor commonly used in 3D printers and CNC machines.
    • Pins: A2 (black), A1 Green, B2 Red, B1 Blue
  4. LiPo Battery 2200mAH 30c

    • Description: A rechargeable lithium polymer battery providing power to the circuit.
    • Pins: VCC, GND

Wiring Details

Arduino Nano

  • D3 connected to STEP on TMC2226 Stepper Driver
  • D4 connected to DIR on TMC2226 Stepper Driver
  • D5 connected to EN on TMC2226 Stepper Driver
  • VIN connected to VCC on LiPo Battery and VMOT on TMC2226 Stepper Driver
  • GND connected to GND on LiPo Battery and GND on TMC2226 Stepper Driver

TMC2226 Stepper Driver

  • STEP connected to D3 on Arduino Nano
  • DIR connected to D4 on Arduino Nano
  • EN connected to D5 on Arduino Nano
  • VMOT connected to VIN on Arduino Nano and VCC on LiPo Battery
  • GND connected to GND on Arduino Nano and GND on LiPo Battery
  • 2B connected to B1 Blue on Nema 17 42-STH48
  • 2A connected to B2 Red on Nema 17 42-STH48
  • 1A connected to A1 Green on Nema 17 42-STH48
  • 1B connected to A2 (black) on Nema 17 42-STH48

Nema 17 42-STH48

  • B1 Blue connected to 2B on TMC2226 Stepper Driver
  • B2 Red connected to 2A on TMC2226 Stepper Driver
  • A1 Green connected to 1A on TMC2226 Stepper Driver
  • A2 (black) connected to 1B on TMC2226 Stepper Driver

LiPo Battery 2200mAH 30c

  • VCC connected to VIN on Arduino Nano and VMOT on TMC2226 Stepper Driver
  • GND connected to GND on Arduino Nano and GND on TMC2226 Stepper Driver

Code Documentation

/*
 * Arduino Nano-Controlled Nema 17 Stepper Motor with TMC2226 Driver
 * and LiPo Battery Power
 *
 * This code controls a Nema 17 stepper motor using a TMC2226 driver.
 * The Arduino Nano sends step and direction signals to the driver.
 * The motor is powered by a LiPo battery.
 */

// Pin definitions
const int stepPin = 3; // STEP pin connected to D3
const int dirPin = 4;  // DIR pin connected to D4
const int enPin = 5;   // EN pin connected to D5

void setup() {
  // Initialize the pins as outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(enPin, OUTPUT);

  // Enable the stepper driver
  digitalWrite(enPin, LOW); // LOW to enable
}

void loop() {
  // Set the direction of the motor
  digitalWrite(dirPin, HIGH); // HIGH for one direction

  // Generate steps to move the motor
  for (int i = 0; i < 200; i++) { // 200 steps for one revolution
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000); // Adjust delay for speed control
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }

  delay(1000); // Wait for a second

  // Change direction
  digitalWrite(dirPin, LOW); // LOW for the opposite direction

  // Generate steps to move the motor
  for (int i = 0; i < 200; i++) { // 200 steps for one revolution
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000); // Adjust delay for speed control
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }

  delay(1000); // Wait for a second
}

This code initializes the necessary pins on the Arduino Nano and controls the stepper motor by sending step and direction signals to the TMC2226 stepper driver. The motor alternates its direction after completing one revolution, with a one-second delay between direction changes.