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

Arduino-Controlled Stepper Motor with A4988 Driver and Speed Control

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Stepper Motor with A4988 Driver and Speed Control

Circuit Documentation

Summary

This circuit is designed to control a Nema 17 stepper motor using an A4988 stepper motor driver. The motor's speed and direction are adjustable via a potentiometer and a toggle switch, respectively. The circuit is powered by a 12V 5A power supply, which is switched on and off using a round rocker switch. The Arduino UNO microcontroller is used to generate the control signals for the A4988 driver based on the inputs from the potentiometer and toggle switch.

Component List

Arduino UNO

POWER SUPPLY 12V 5AMP

Round Rocker Switch

A4988 Stepper Motor Driver (Red)

Electrolytic Capacitor

IEC320 In

2Pin Push Switch (x2)

Toggle Switch

Potentiometer

Nema 17 42-STH48

Wiring Details

Arduino UNO

POWER SUPPLY 12V 5AMP

Round Rocker Switch

A4988 Stepper Motor Driver (Red)

Electrolytic Capacitor

IEC320 In

2Pin Push Switch

Toggle Switch

Potentiometer

Nema 17 42-STH48

Documented Code

/*
 * Arduino Sketch for Stepper Motor Control
 * This code controls a stepper motor using an A4988 driver.
 * The motor's speed and direction can be controlled via a potentiometer and toggle switch.
 * The rocker switch is used to power the circuit.
 */

// Pin definitions
const int stepPin = 3;
const int dirPin = 4;
const int ms1Pin = 5;
const int ms2Pin = 6;
const int ms3Pin = 7;
const int enablePin = 8;
const int toggleSwitchL1 = 9;
const int rockerSwitchInput = 10;
const int potPin = A0;

void setup() {
  // Set pin modes
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(ms1Pin, OUTPUT);
  pinMode(ms2Pin, OUTPUT);
  pinMode(ms3Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(toggleSwitchL1, INPUT);
  pinMode(rockerSwitchInput, INPUT);
  pinMode(potPin, INPUT);

  // Initialize pins
  digitalWrite(enablePin, LOW); // Enable the driver
  digitalWrite(ms1Pin, LOW); // Full step mode
  digitalWrite(ms2Pin, LOW); // Full step mode
  digitalWrite(ms3Pin, LOW); // Full step mode
}

void loop() {
  // Read the potentiometer value
  int potValue = analogRead(potPin);
  // Map the potentiometer value to a delay time
  int delayTime = map(potValue, 0, 1023, 1000, 200);

  // Read the toggle switch state
  int toggleState = digitalRead(toggleSwitchL1);
  // Set the direction based on the toggle switch state
  digitalWrite(dirPin, toggleState);

  // Step the motor
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(delayTime);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(delayTime);
}

This code is designed to run on an Arduino UNO and controls the A4988 stepper motor driver to operate the stepper motor. The speed of the motor is determined by the value read from the potentiometer, and the direction is controlled by the state of the toggle switch. The code sets up the necessary pins as inputs or outputs and initializes the driver in full step mode. The main loop reads the potentiometer value, maps it to a delay time, reads the toggle switch state to set the direction, and then steps the motor accordingly.