Robotic arm not working

This code allows me to check for serial monitor and movement of servo,the problem is when it is setting up it moves but when I use the app via Bluetooth to move the robot it doesn't move at all pls help

#include <SoftwareSerial.h>
#include <Servo.h>

Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
Servo Servo5;
Servo Servo6;

SoftwareSerial bluetooth(1, 0); // Arduino(RX, TX) - HC-05 Bluetooth (TX, RX)

int currentAngle1 = 0;
int currentAngle2 = 0;
int currentAngle3 = 90;
int currentAngle4 = 0;
int currentAngle5 = 0;
int currentAngle6 = 0;

void setup() {
bluetooth.begin(9600);
Servo1.attach(13);
Servo2.attach(12);
Servo3.attach(11);
Servo4.attach(7);
Servo5.attach(6);
Servo6.attach(5);
Servo1.write(currentAngle1);
Servo2.write(currentAngle2);
Servo3.write(currentAngle3);
Servo4.write(currentAngle4);
Servo5.write(currentAngle5);
Servo6.write(currentAngle6);
}

void loop() {
//Read from bluetooth and write to usb serial
if (bluetooth.available() >= 2) {
String mode = bluetooth.readString();
String type = bluetooth.readString();

if (mode == 'm') {
  if(bluetooth.available()>=1){
  int servopos = bluetooth.read();
  if (type == 'a') {
    Serial.println(servopos);
    Servo1.write(servopos);
    delay(10);  // Recommended delay after each Servo.write()

  } else if (type == 'b') {
    Serial.println(servopos);
    Servo2.write(servopos);
  } else if (type == 'c') {
    Serial.println(servopos);
    Servo3.write(servopos);
  } else if (type == 'd') {
    Serial.println(servopos);
    Servo4.write(servopos);
  } else if (type == 'e') {
    Serial.println(servopos);
    Servo5.write(servopos);
  } else if (type == 'f') {
    Serial.println(servopos);
    Servo6.write(servopos);
  }
  } else if (mode == 'a') {
    int action[6];  // Declare the array with a size
    String command = bluetooth.readString();
    int actionIndex = 0;  // Index for storing tokens

    if (command.length() > 0) {
      int index = 0;
      String token;

      while ((index = command.indexOf('/')) != -1) {
        token = command.substring(0, index);
        if (actionIndex < 6) {  // Check array bounds
          action[actionIndex++] = token.toInt();
        }

        command.remove(0, index + 1);
      }

      // Handle the last token if any
      if (command.length() > 0 && actionIndex < 6) {
        action[actionIndex++] = command.toInt();  // Store the last token
      }

      for (int i = 0; i < actionIndex; i++) {
      if (i < 6) {
        bluetooth.println(action[i]);  
        switch (i) {
          case 0: Servo1.write(action[i]); break;
          case 1: Servo2.write(action[i]); break;
          case 2: Servo3.write(action[i]); break;
          case 3: Servo4.write(action[i]); break;
          case 4: Servo5.write(action[i]); break;
          case 5: Servo6.write(action[i]); break;
        }
        delay(1000);
      }

      }
    }
    command = "";
  }
}

}
}

Welcome to the forum

Why did you post in the Emergency Response category of the forum ? Your topic has been moved to the Programming Questions category

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

SoftwareSerial bluetooth(1, 0);

Don't use pins 0 and 1for SoftwareSerial. They are used by the hardware Serial interface of most common Arduino boards although you have not told us which Arduino you are using

I'm using Arduino Uno ,the thing is I can see the info on serial monitor while using port 0,1 ,if I use other pwm the serial monitor won't show anything,the only problem right now is that I'm receiving inputs from my app but it's not running.it does move during the setup position

My advice still stands. Do not use pins 0 and 1 for SoftwareSerial, or anything else for that matter

I don't understand what you mean by this

Please post your sketch using code tags to make it easier to copy for examination

Hi @kirazen123,

welcome to the arduino-forum.

The reason why you should not use IO-pins 0,1 is:

IO-pins 0,1 are used for the hardware-serial.
If you write code that makes software-serial use the same IO-pins 0,1 as hardware-serial this is basically the same as if you call two people on two different phones and then you want to talk to both persons at the same time: doesn't work. The words will interfere and you will understand nothing.

You will have to add code to your program that realises the "transportation" of the received data from software-serial to hardware-serial to still make the data send from bluetooth visible on the serial monitor.

example:

bluetooth-receiver is connected to IO-pin 8 and 9
your code receives the data with software-serial
as pseudo-code

myBluetoothData = receiveFrom-IO-Pin 9

take data that is stored into variable myBluetoothData and send it to the serial monitor
Serial.println(myBluetoothData);

You will have to learn quite some things to understand how it really works.
You can ask as many questions as you like even hundreds of questions.
If you are willing to take advice for serious and follow the advice of experienced users your flow of questions will always be answered.

If you insist on not learning by argueing against the advice your potential helpers will turn away and answer other threads.

Thanks I'll give it try

As a general advice you should post a lot of more details of your project.
This means posting the exact type of bluetooth-module

Robotic arm sounds like a ready to build kit.
Does your robotic-arm have a separate power-supply?

Here is a link to a tutorial for HC-05 bluetooth-modules.

have you verified that your bluetooth connection works?

and oh!, your using software serial

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.