Hi . I am working on a simple project for my son. I am using one of this motor and the code below. I want to achivie some effect very simple and move the motor between two point back and forward (need for moving one simple wooden bird ) . I think should be enough to oscillate between 90 degree and 0 then from 0 to 90. The problem is that it does not completely go back to the initial point hence the motor keep slightly moving forward. Any help? The motor is broken ? Thanks.
#include <Stepper.h>
const int stepsPerRevolution = 1048;
int revolutionVal = 200;
//Use pin 8-11 to IN1-IN4
Stepper stepperName = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
//Set the RPM of the stepper motor
stepperName.setSpeed(20);
}
void loop() {
//This should make the stepper do a full 360 degrees
stepperName.step(revolutionVal * 1);
delay(2000);
stepperName.step(revolutionVal * -1);
delay(2000);
}
Two possible explanations: you are either commanding the stepper to step too quickly, so it is skipping steps, or not waiting until the move is complete before commanding another move.
Keep in mind that the gearbox has backlash, so forward and backward movements will not end up in the same places.
What is "this" motor? Is it a 28BYJ-48 stepper motor as suggested by @Wawa?
Maybe it's your mechanics and the motor is losing steps due to mechanical resistance. And maybe you need acceleration/deceleration to reach the set speed without loosing steps ( or you have to lower the speed )
What are you using as a power supply for the stepper?
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Can you please post some pictures of your project?
So we can see you component layout.
Hi
I posted above the connection from the arduino mega. Then 2 cable from the driver to the GND and 5V. I am using the driver ULN2003. Holding the stepper motor in my hand. 28byj48-stepper-motor-arduino-tutorial
#include <Stepper.h>
const int stepsPerRevolution = 512 ;
int revolutionVal = 512;
//Use pin 8-11 to IN1-IN4
Stepper stepperName = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
//Set the RPM of the stepper motor
stepperName.setSpeed(20);
}
void loop() {
//This should make the stepper do a full 360 degrees
stepperName.step(revolutionVal * 1);
delay(2000);
stepperName.step(revolutionVal * -1);
delay(2000);
}
it does 90 degree I assume one side but then it should come back it only vibrates.
Bad connection due to arduino board, solved. Is it possible to set the motor in a specific initial position before starting the actual loop ? Thank you.