// https://wokwi.com/projects/442675760429265921
// Simulate potentiometer positional feedback of a stepper position
// https://wokwi.com/projects/410058296261374977
// Other example simulations https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754
// This simulation uses
// https://github.com/drf5n/Wokwi-Chip-LimitCounter
// https://github.com/Dlloydev/Wokwi-Chip-Scope
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER,4,3);
const int TARGET_POT = A0;
const int FEEDBACK_POT = A1;
void setup()
{
stepper.setMaxSpeed(500);
stepper.setAcceleration(2000);
}
void loop()
{
// Read new target and feedback
int target = analogRead(TARGET_POT);
int pot = analogRead(FEEDBACK_POT);
int error = pot-target;
if(abs(error) <=1){ // deadband
stepper.move(0);
}
else{
stepper.move(-error); // move towards target
}
stepper.run();
}
Wokwi-stepper-motor
AccelStepper.h demo.
Target
1023
CW
CCW
0