Bluetooth stepper motor rotation

Hello im pretty new in arduino and need some help making my school project. Im using arduino with bluetooth to rotate the stepper motor by 90, 180, 270 and 360 degrees. I made that. I got stuck making the motor turn left constantly or right and i don’t know how to stop it. I make a loop function wich rotates the motor as long as my input is one HIGH and because its on high it ignores the entire code.i started to test some stuff at the end there. Any ideas?

Thanks to anyone.

HERE IS THE CODE:

#include<SoftwareSerial.h>
SoftwareSerial bt(2,3); /* (Rx,Tx) /
char stanje;
byte delayTime;
bool VHOD = 6;
byte L;
int x = 0;
void setup() {
bt.begin(9600); /
Define baud rate for software serial communication /
Serial.begin(9600); /
Define baud rate for serial communication */
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(6, INPUT);
pinMode(7, OUTPUT);

}

void loop() {
int x = 0;
delayTime = 15;
if (bt.available()) /* If data is available on serial port /
{
Serial.write(bt.read()); /
Print character received on to the serial monitor */

}
stanje = bt.read();
switch(stanje){
case ‘a’: do{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(delayTime);
Serial.println (x);
x++; }
while(x <12 );;;break;

default : break;
}
switch(stanje){
case ‘b’: do{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(delayTime);
Serial.println (x);
x++; }
while(x <26 );

;break;
int x = 0;

default : break;}

switch(stanje){

case ‘c’: do{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(delayTime);
Serial.println (x);
x++; }
while(x <37 );
;break;

default : break;
}
switch(stanje){
case ‘d’: do{
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(delayTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(delayTime);
Serial.println (x);
x++; }
while(x <50 );;break;

default : break;}
switch(stanje){

case ‘e’:
digitalWrite(7, HIGH);

do {
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(100);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(100);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(100);
if ( VHOD == HIGH);
goto del;

default : break;}
while (VHOD == HIGH);
del :
switch(stanje){
case ‘s’: digitalWrite(7, LOW);

default : break;
}

}

}

CODE.txt (4.04 KB)

FIRST ... To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Also please use the AutoFormat tool to indent your code consistently for easier reading.

Your code is too long for me to study quickly without copying to my text editor.

Your program seem to use a lot of delay()s. The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

Also look at the second non-blocking example in this Simple Stepper Code

And at the the AccelStepper library

Separately you will make life a lot easier for yourself if you create a variable with a meaningful name for any I/O pins that you use. For example (using leds for illustration)

byte redLedPin = 8;
byte greenLedPin = 9;

then

digitalWrite(redLedPin, HIGH);
// etc

Now if you need to change the pin numbers you just need to make a change on one line of the program and also you can easily see whether a line of code is working with the correct led.

...R

the most important idea about programming is
write one function at a time. Test this function and if it works add the next single function.

So my recommendation is to go back to a code that does nothing more than
receive a byte through the serial interface and just print “received a byte” character is:" value of received byte.

If this is working as second step add your switch-code and the switch-code does nothing more than print messages

stanje = bt.read();
switch(stanje){
case ‘a’: do{

stanje = bt.read();
     switch(stanje){
      case 'a':  do{
       Serial.println("case 'a':  do");
      }

      case 'b':  do{
       Serial.println("case 'a':  do");
      }

etc.

If this is working as thrird stepp add
your upcounting while loop to one case-statement and test if it works like expected

Serial.println (x);
    x++; }
      while(x <37 ); 
  ;break;

Make a completely new code that does just create steps for some rotation

void setup() {
  bt.begin(9600); /* Define baud rate for software serial communication */
  Serial.begin(9600); /* Define baud rate for serial communication */
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(6, INPUT);
  pinMode(7, OUTPUT);
 
}

void loop() {
  int x = 0;
  delayTime = 15;
      digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  delay(delayTime);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  delay(delayTime);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  delay(delayTime);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  delay(delayTime);

delay(1000);
}

put that part of the code that does switch the coils of the steppermotor in its own function.

if this part is working put it inside the code that does the serial receiving and switch-cases the received byte

If you prefer waiting for a reply that does all this work for you. You might consider how long this will take and how much tests described like above you can do in the meantime

best regards Stefan

Please, give a link to your Stepper Motor. I would like to know how you are driving your Motor and how it is connected with Arduino.