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

Arduino Nano Controlled Bipolar Stepper Motor with LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Bipolar Stepper Motor with LED Indicators

Circuit Documentation

Summary

This circuit is designed to control a bipolar stepper motor using an Arduino Nano and an A4988 stepper motor driver. The circuit also includes two LEDs (red and green) to indicate the direction of the motor's rotation. The Arduino Nano is programmed to rotate the motor clockwise and counterclockwise with pauses in between.

Component List

  1. Stepper Motor (Bipolar)

    • Pins: D, B, C, A
    • Description: A bipolar stepper motor used for precise control of rotational position.
  2. Battery Case

    • Pins: +, -
    • Description: Provides power to the circuit.
  3. Arduino Nano

    • 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
    • Description: A microcontroller used to control the stepper motor and LEDs.
  4. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: A red LED used to indicate the motor's counterclockwise rotation.
  5. LED: Two Pin (green)

    • Pins: cathode, anode
    • Description: A green LED used to indicate the motor's clockwise rotation.
  6. Resistor (200 Ohms)

    • Pins: pin1, pin2
    • Description: Used to limit the current through the LEDs.
  7. A4988 Stepper Motor Driver Carrier

    • Pins: ENABLE, MS1, MS2, MS3, RESET, SLEEP, STEP, DIR, GND, VCC, 1B, 1A, 2A, 2B, VMOT
    • Description: A driver module used to control the stepper motor.

Wiring Details

Stepper Motor (Bipolar)

Battery Case

Arduino Nano

LED: Two Pin (red)

LED: Two Pin (green)

Resistor (200 Ohms)

Resistor (200 Ohms)

A4988 Stepper Motor Driver Carrier

Code Documentation

// Pin definitions
#define STEP_PIN 8      // STEP pin connected to A4988
#define DIR_PIN 9       // DIR pin connected to A4988
#define GREEN_LED 6     // Green LED pin (Clockwise Indicator)
#define YELLOW_LED 7    // Yellow LED pin (Counterclockwise Indicator)

// Function prototypes
void rotateMotor(int duration, int stepDelay);

void setup() {
  // Configure motor pins
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);

  // Configure LED pins
  pinMode(GREEN_LED, OUTPUT);
  pinMode(YELLOW_LED, OUTPUT);

  // Start with LEDs off
  digitalWrite(GREEN_LED, LOW);
  digitalWrite(YELLOW_LED, LOW);
}

void loop() {
  // Step 1: Rotate clockwise for 3 seconds
  digitalWrite(DIR_PIN, HIGH);      // Set motor direction to clockwise
  digitalWrite(GREEN_LED, HIGH);    // Turn on green LED
  rotateMotor(3000, 1000);          // Rotate for 3 seconds (step delay 1000µs)
  digitalWrite(GREEN_LED, LOW);     // Turn off green LED

  // Step 2: Stop for 5 seconds
  delay(5000);

  // Step 3: Rotate counterclockwise for 3 seconds
  digitalWrite(DIR_PIN, LOW);       // Set motor direction to counterclockwise
  digitalWrite(YELLOW_LED, HIGH);   // Turn on yellow LED
  rotateMotor(3000, 1000);          // Rotate for 3 seconds (step delay 1000µs)
  digitalWrite(YELLOW_LED, LOW);    // Turn off yellow LED

  // Step 4: Stop for 5 seconds
  delay(5000);
}

// Function to rotate the motor for a specified duration
void rotateMotor(int duration, int stepDelay) {
  unsigned long startTime = millis();
  while (millis() - startTime < duration) {
    digitalWrite(STEP_PIN, HIGH);    // Generate HIGH pulse
    delayMicroseconds(stepDelay);    // Wait for step delay
    digitalWrite(STEP_PIN, LOW);     // Generate LOW pulse
    delayMicroseconds(stepDelay);    // Wait for step delay
  }
}

This code is designed to control the stepper motor and LEDs. The motor rotates clockwise for 3 seconds, stops for 5 seconds, rotates counterclockwise for 3 seconds, and then stops for another 5 seconds. The green LED indicates clockwise rotation, and the red LED indicates counterclockwise rotation.