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.
Arduino Nano
TMC2226 Stepper Driver
Nema 17 42-STH48
LiPo Battery 2200mAH 30c
/*
* 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.