Arnov Sharma
Published © MIT

Pico Stepper Motor Driver Board

Raspberry Pi PICO with A4988 Stepper Motor Driver Setup

BeginnerFull instructions provided1 hour128
Pico Stepper Motor Driver Board

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1
Stepper motor driver board A4988
SparkFun Stepper motor driver board A4988
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Fusion 360 FILE for the Gearbox

Schematics

SCH

Code

code

C/C++
const int dirPin = 16;
const int stepPin = 17;
const int ledPin = 0; // Pin connected to the LED
const int stepsPerRevolution = 200;
const int maxSpeed = 1000; // Maximum speed in microseconds
const int minSpeed = 2000; // Minimum speed in microseconds

void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  // Blinking LED when motor is moving
  digitalWrite(ledPin, HIGH);

  // Set motor direction clockwise
  digitalWrite(dirPin, HIGH);

  // Ramp up speed from low to high over 5 seconds
  for (int speed = minSpeed; speed >= maxSpeed; speed -= 20)
  {
    for (int x = 0; x < stepsPerRevolution; x++)
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(speed);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(speed);
    }
    delay(50); // Small delay to avoid skipping steps
  }

  delay(2000); // Hold at max speed for 2 seconds

  // Set motor direction counterclockwise
  digitalWrite(dirPin, LOW);

  // Ramp up speed from low to high over 5 seconds
  for (int speed = minSpeed; speed >= maxSpeed; speed -= 20)
  {
    for (int x = 0; x < stepsPerRevolution; x++)
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(speed);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(speed);
    }
    delay(50); // Small delay to avoid skipping steps
  }

  delay(2000); // Hold at max speed for 2 seconds

  // Turn off LED when motor stops
  digitalWrite(ledPin, LOW);

  delay(1000); // Optional delay between cycles
}

Credits

Arnov Sharma

Arnov Sharma

310 projects • 307 followers
Just your average MAKER

Comments