I am new to the field of Arduino. I have to run a stepper motor in clockwise for some degrees (say 180°) and anticlockwise for some degrees (say 180°).
I have followed the tutorial How to Control Stepper motor with Arduino - YouTube and built exactly the same set up using 12V 4-wire stepper motor, a stepper motor driver and Arduino controller. The wiring diagram is attached with this question.
The Arduino code to run in clockwise direction is like this:
void setup() {
// put your setup code here, to run once:
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//digitalWrite(8,HIGH); //for reverse direction
digitalWrite(9,LOW);
delay(2);
digitalWrite(9,HIGH);
delay(2);
}
This code works perfectly fine. There is also provision of reverse the direction and run the motor in anticlockwise by un-commenting the said line.
I have learnt how to run a motor in bi-directions by changing the codes, but now, I have to run the motor in clockwise for some degrees (lets say half turn) and anticlockwise for some degrees (lets say half turn) continuously in a loop.
What changes can I make in the code. I am really poor in coding, It would be great if someone can help me here.
@lirilsilvi, your topic has been moved to a more suitable location on the forum. At the moment that you can upload code, Installation and Troubleshooting is the wrong section.
When posting code, please use code tags. Edit your post, select all code and click </>; next save your post. It makes is easier to read, the forum software will not mangle it and it's easier to copy.