Hello guy's,i am new to arduino and microcontrollers and i have a school project.
I need to use a stteper motor , them motor needs to stop on a specific value(angle) and to turn on a led ,and the motor needs to go both ways 180 degrees total of 360 degrees full circle.I bought a A4988 driver for my motor and got it to work.
int stp = 8;
int dir = 9;
int led1=5;
int i = 0;
void setup()
{
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
}
void loop()
{
//--------------------------------orar---------------------
digitalWrite(dir,HIGH);
for(i=0;i<=200;i++){
digitalWrite(stp,HIGH);
delay(8);
digitalWrite(stp,LOW);
delay(8);
}
//----------------------------------trigonometric--------------------------
delay(100);
digitalWrite(dir,LOW);
for(i=201;i<=400;i++){
digitalWrite(stp,HIGH);
delay(10);
digitalWrite(stp,LOW);
delay(10);
}
delay(100);
}
here is my code so far, on the things i don't know to do is:
1.To stop the motor on a specific angle
2.read a specific value from my keyboard
Thank you PS:sorry for my bad english ,it's not my first language
You need to find the degrees per step from the stepper motor's data sheet, then you want to work out how many steps to achieve your desired angle by dividing the desired angle by the degrees per step and stepping that amount of times. For example, your stepper could be 8 degrees per step and you want to move 45 degrees, you move 45/8= 5.625 steps. You would then decide how you wanted to round that off to an integer.
i know those things my motor does 1.8 degree so 360/1.8 is 200 what i don't know is the command or the way to stop the motor on a speccific angle(value) and how to read a value from keybord in c++ is cin>>x; how to do that cin on arduino and how to stop the motor on a value
If it needs 200 steps for one circle then just tell it to move 100 steps for 180 degrees.
Do you mean that you want to send instructions from a program on a PC?
OR do you mean that you want to read a keypad using your Arduino?
You need a variable that is incremented (or decremented) for every step. That way you will always know where the motor is and you can stop it when the count matches the desired value.
Have a look at
Planning and Implementing a Program
Stepper Motor Basics
Simple Stepper Code
...R