had to change precision in title because of this posting further below
This posting is on how to build a high precision (3µm accuracy) linear actuator, and provides basic needed sketches.
The 28BYJ-48 stepper motor has 4096(!) half steps per revolution.
You can find the math behind the features of using 28BYJ-48 motor shaft itself as high precision linear actuator here:
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=210605&p=1563791#p1563791

Summary for this high precision linear actuator:
Operating range: 0..1mm [0..1038µm measured]
Steps: 604 [600 steps used for measurement]
Linear distance change per step: min=3nm, max=3.062µm, avg=1.655µm
Feedback from 0.001mm electronic micrometer allows for automatic 0° calibration.
This actuator is a cam type linear actuator.
Unlike normal linear actuators, the (linear) step width here is not constant (guaranteed <=3.062µm/step).
This is an advantage for microscpope type of application, since minimal step (just before 0°) is <=2.95nm(!!).
You can use the 2$ stepper motor alone as linear actuator, you need a lever with a spring only in this case.
I did build it onto 46$ 0.001mm resolution electronic micrometer for feedback:
I did wire the 28BYJ-48 stepper motor with an L293D on breadboard according this description with and Arduino Uno (I know that there might be problems with powering stepper motor from the Arduino 5V rail, but it works):
~~https://lastminuteengineers.com/stepper-motor-l293d-arduino-tutorial/~~
I did control the 28BYJ-48 stepper motor with ULN2003 motor driver and Arduino Uno (I know that there might be problems with powering stepper motor from the Arduino 5V rail, but it works).
I used this script for calibration. It uses AccelStepper library mainly because that supports half stepping. It asks for position on serial monitor, and when you input new position followed by return, it will move to that position and print the value you enterd into console output as well. Since with reset of any sketch the stepper motor current position is taken a 0, I did try different positions until motor was in 53.13° position. Then I pressed reset button to make that position the 0-position of stepper motor. The electronic micrometer reading is typically not 0 at 0-position set for stepper motor -- press ZERO button on electronic micrometer to change that:
#include <AccelStepper.h>
// ULN2003
AccelStepper stepper(AccelStepper::HALF4WIRE, 2, 4, 3, 5);
void setup()
{
stepper.setMaxSpeed(500);
stepper.setAcceleration(50);
Serial.begin(9600);
}
void loop()
{
if (stepper.distanceToGo() == 0)
{
Serial.print("pos? ");
while (!Serial.available()) { delay(50); }
int pos = Serial.parseInt();
if (Serial.read() == '\n') {
Serial.println(pos);
stepper.moveTo(pos);
}
}
stepper.run();
}
I used this sketch for the demo video I uploaded to youtube. After the demo completed, sketch goes into endless loop at 0-position. You can upload another sketch, or press reset to start it again. The sketch moves to some positions, and waits for 2 seconds before moving on to next postion. The 2 seconds are needed to make notes of the values displayed by 0.001mm resolution electronic micrometer:
#include <AccelStepper.h>
// ULN2003
AccelStepper stepper(AccelStepper::HALF4WIRE, 2, 4, 3, 5);
int i=0;
int A[]={
-600,0,
-100,-200,-300,-400,-500,-600,0,
-100,-200,-300,-400,-500,-600,0,
};
void setup()
{
stepper.setMaxSpeed(500);
stepper.setAcceleration(50);
Serial.begin(9600);
}
void loop()
{
if (stepper.distanceToGo() == 0)
{
if (i == sizeof(A)/sizeof(A[0])) for(;;){}
Serial.print("moveto(");
Serial.print(A[i]); Serial.println(")");
delay(2000);
stepper.moveTo(A[i++]);
}
stepper.run();
}
Youtube video is here:
Stepper motor starts at 0, then moves to 600, back to 0, and then two times to 100,200,300,400,500,600,0.
The micrometer measurents are repeatable for those positions (0/276/530/736/887/991/1038).
If you want to verify, you will have to look at youtube video, the animated gif shows 0,600,0,600,0,... only:
I never had to connect something to metal before. My favorite method of connecting anything is superglue. But I wanted to be able to remove the stepper motor, so it had to be screwed somehow. I decided to superglue two small Lego pieces onto metal, drill holes into them and screw the motor. There was a 0.2mm higher metal area on the left -- I decided to dremel away a bit from the Lego piece left. On the right the Lego piece did not fit 100%, so I used Dremel again to correct Lego piece:
I used M3x16 screws, and drilled 2mm diameter holes with Dremel:
I had to add two M4 screw nuts with those screws in order to be able to firmly screw stepper motor:
The addition of black cardboard above stepper motor was not needed fuctionally.
It allows to capture video without too much reflection by stepper motor metal surface:
P.S:
Need to figure out which serial cable is needed (for automatic 0° calibration, automatic reliability testing, graphing, ...):
P.P.S:
Seems to be this RJ11 6P4C Male to 4 Pin AV Screw Terminal Connector, will know tomorrow, just ordered it on Amazon Prime:
P.P.S:
RJ11 is too big, does not fit -- so what connector is needed?