What I learned:
1. Too much current through the stepper motor driver heats it up... causing it to shut down frequently... causing it to jitter the motor.
2. Running the motor with external 6V instead of the rated 12V, allows to not draw as much power, removing the stutter/jitter.
3. Turning off the motor when it's not in use allows for more cooldown time.
I wrote some code to allow for controlling the motor with a hall sensor. The motor is supposed to be at a "home" position, except when a magnet is near the hall sensor. As soon as a magnet triggers the hall sensor, the motor moves clockwise until the magnet is removed, which is when the motor returns to home position.
#include <Stepper.h>
int sensor = 0;
int distance = 0;
int execsteps = 20;
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying the number of steps of the
// motor and the pins it's attached to
Stepper stepper(STEPS, 4, 5, 6, 7);
void setup() {
// put your setup code here, to run once:
stepper.setSpeed(50); // set the speed of the motor to 30 RPMs
motorOff();
}
void loop() {
// put your main code here, to run repeatedly:
sensor = analogRead(0) - analogRead(1); // Read differential output voltage from hall sensor
sensor = map(sensor, 335, 370, 0, 100);
while (sensor>50) {
stepper.step(execsteps);
motorOff();
distance = distance + execsteps;
sensor = analogRead(0) - analogRead(1); // Read differential output voltage from hall sensor
sensor = map(sensor, 335, 370, 0, 100);
}
while (distance !=0) {
stepper.step(-execsteps);
motorOff();
distance = distance - execsteps;
}
}
void motorOff() {
digitalWrite (4, LOW);
digitalWrite (5, LOW);
digitalWrite (6, LOW);
digitalWrite (7, LOW);
}
Here's a video of it functioning:
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.