Arnov Sharma
Published © MIT

Pico Stepper Motor Driver Board

Raspberry Pi PICO with A4988 Stepper Motor Driver Setup

BeginnerFull instructions provided1 hour475
Pico Stepper Motor Driver Board

Things used in this project

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
403 projects • 446 followers
I'm Arnov. I build, design, and experiment with tech; 3D printing, PCB design, and retro consoles are my jam.

Comments