DC and Servo Motors edited

(im editing this post questions since what i have wrote b4 was a completely mess to follow)

ok so yesterday b4 get any replay in here i just came up with what u just said about my servo motors; I was using continuous positional servo motor xd ... (respect with the diagram in thinkercard this circuit i made like 2 weeks ago and didnt know how much needed to power up so i just put that 2 AAA batteries as a reference that have to be powered with external power ik its wrong just changed after that because right now im not using that to power my circuit xd )

right now i cant really test if the new code that i modified yesterday is working or no but it present no error after compiling without saying more just gonna upload it

hopefully someone can tell me if something is wrong or have no sense in the code because in the end i modified by myself base of all the examples that i have seem related to this

what is what i want to do???

i wanna control 2 servo motors and one dc motor by bluetooth through the App Mit Inventor
so in the app ill have 2 slider for each servo and move any degree from 0 to 180
and with the dc motor 3 buttons Forward Backward and Stop
that's all

so this is the code:

#include <Servo.h> 

Servo servo1;  
Servo servo2; 
char a;
String readString; 
int Forwardmotor = 8;     //pins in the arduino UNO
int Backwardmotor = 9;
int speed = 255;   //(motor speed  0-255) 

void setup() {
  servo1.attach(5); 
  servo2.attach(6); 
  servo1.write(0);   //initial servos position
  servo2.write(90);  // initial servos position
  pinMode(Forwardmotor, OUTPUT);
  pinMode(Backwardmotor, OUTPUT);
  
  Serial.begin(9600);
  delay(10);
}

void loop() {
 if (Serial.available()) {  
    a = Serial.read();
    
    if(a=='A'){       
      Servo1();
    }
    
    if(a=='B'){                            
      Servo2();
    }
    
    if(a=='C'){       //motor move forward                        
       analogWrite(Forwardmotor, speed);
       analogWrite(Backwardmotor, 0);
    }
    
    if(a=='D'){      //motor move backward                   
       analogWrite(Forwardmotor, 0);
       analogWrite(Backwardmotor, speed); 
    }

    if(a=='E'){     //motor stop                        
       analogWrite(Forwardmotor, 0);
       analogWrite(Backwardmotor,0);     
    }
  }
}  

  
void Servo1(){ //servo motor 1   //servo motor get slider thumbsposition
        delay(10);   
        while (Serial.available()) { 
                           
          char b = Serial.read();  
          readString += b;        
        }
        if (readString.length() >0) {   
          Serial.println(readString.toInt());  
          servo1.write(readString.toInt());
          readString=""; // Clear string
        }
}

void Servo2(){   //servo motor 2    //servo motor get slider thumbsposition
        delay(10); 
        while (Serial.available()) {                  
          char b = Serial.read();  
          readString += b;         
        }
        if (readString.length() >0) { 
          Serial.println(readString.toInt());  
          servo2.write(readString.toInt());
          readString=""; 
        } 
}

I have been trying to add the URL image to make it appears like the maximun reach 90000 characters
im adjuting the circuits image sy

the image of the circuits i made it in thinkercard so if u dont want to download the file
u can clicked here that is my circuit diagram is in public the code there is different so ignore it

2 x servos and a DC motor powered by 2 x AAA batteries? Really? And why is one pin of the Bluetooth module connected to a resistor that goes nowhere?

If your servo is spinning round and round then it's 360 degree/continuous rotation servo. You can't position this type of servo to specific angles. The mechanism that normally allows this in a standard servo has been removed.

The code is a mess, problems include Servo.h and SoftwareSerial.h not working together. But although you define bluetooth as SoftwareSerial you never use it the rest of the code. What's going on there? All your commands come from the hardware Serial.

And did you really mean "dc motor part" to be part of the motor2() function? And why does it define a local version of readString that it never uses?

Steve

I suggest you better code your text problem description, making for easier reading, by using upper case letters to mark the start of a sentence, and use a period as the end of sentence marker. Also as to posting code:

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select "more" and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.