Problem: Arduino UNO with LED strip and Bluetooth Module

Hello, For my school project I am working on an LED strip on music. I am new to this forum so sorry if I forget to mention anything.
Materials
Arduino Uno
WS2812B LED strip 2m, 60 LED / m
HC-05 BT module
Jack chassis (To do jack input to analog port)

I have different modes in my app for different types of music. I also have a separate section for a static color, so not on music.
I want to be able to operate the LED strip using the app.

#include <SoftwareSerial.h>
#include <FastLED.h>
#define NUM_LEDS 120
#define PIN 7
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
SoftwareSerial Bluetooth(3,2);

int k = 2040;
int k2 = 340;
int k3 = 340;
int k4 = 340;
int k5 = 340;
int k6 = 340;
int k7 = 340;
  int kleur =  0;
  int kleur2 = 0;
  int kleur3 = 0;
  int kleur4 =  150;
  int kleur5 = 120;
  int kleur6 = 250;
  int kleur7 = 150;
  int kleur8 = 120;
  int kleur9 = 250;
  int kleur10 = 150;
  int kleur11 = 120;
  int kleur12 = 250;
  int kleur13 = 150;
  int kleur14 = 120;
  int kleur15 = 250;
  int kleur16 = 150;
  int kleur17 = 120;
  int kleur18 = 250;
  int kleur19 = 150;
  int kleur20 = 120;
  int kleur21 = 250;
  int R = 0;
  int G = 0;
  int B = 0;
  int brightness = 50;
  String dataIn ="";
  String mode = "0";

void setup() {
  // put your setup code here, to run once:
FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
Serial.begin(9600);
Bluetooth.begin(9600);
}

void loop() {
    if ((Bluetooth.available() > 0) && (mode == "0")){
    dataIn = Bluetooth.readString();
    Serial.println(dataIn);
    delay(20);
    if (dataIn.startsWith("M")){
    mode = dataIn.substring(dataIn.indexOf("M") + 1);
        Serial.println(mode);
      } else if (dataIn.startsWith("2")) {
    delay(10);
    String stringR = dataIn.substring(dataIn.indexOf("R") + 1, dataIn.indexOf("G"));
      R = stringR.toInt();
      String stringG = dataIn.substring(dataIn.indexOf("G") + 1, dataIn.indexOf("B"));
      G = stringG.toInt();
      String stringB = dataIn.substring(dataIn.indexOf("B") + 1, dataIn.indexOf("E"));
      B = stringB.toInt();
      mode = "4";
    }
   else if (dataIn.startsWith("3")){
    String stringBrightness = dataIn.substring(dataIn.indexOf("3") + 1, dataIn.length());
    brightness = stringBrightness.toInt();
    FastLED.setBrightness(brightness);
   } 
   }
   
if (mode == "1"){
        int audioInput = analogRead(A0);
        int ledSterkte0 = map(audioInput, 0, 60, 0, 120);
        FastLED.clear();
        Serial.println(audioInput);
        for (int i = 0; i < ledSterkte0; i++) {
            leds[i].setRGB (R, G, B);
            k++;
            if(k > 2040){
              R = random(0, 150);
              G = random(0, 240);
              B = random(0, 170);
              k = 0;
}}
        FastLED.show();
        if (Bluetooth.available() > 0){
            mode = "0";
}}
      
else if (mode == "2"){
           int audioInput = analogRead(A0);
           int ledSterkte0 = map(audioInput, 0, 60, 0, 59);
           int ledSterkte1 = map(audioInput, 0, 60, 120, 60);
           FastLED.clear();
           Serial.println(audioInput);
           for (int i = 0; i < ledSterkte0; i++) {
              leds[i].setRGB (kleur, kleur2, kleur3);
              k++;
              if(k > 2040){
                  kleur = random(10, 255);
                  kleur2 = random(10, 255);
                  kleur3 = random(10, 255);
                  k = 0;
}}
          for (int i2 = 120; i2 > ledSterkte1; i2--) {
              leds[i2].setRGB (kleur, kleur2, kleur3);
              k++;
              if(k > 2040){
                kleur = random(10, 255);
                kleur2 = random(10, 255);
                kleur3 = random(10, 255);
                k = 0;
}}  
    FastLED.show();
    if (Bluetooth.available() > 0){
    mode = "0";
      }  
      }
else if (mode == "3"){
     int audioInput = analogRead(A0);
  int ledSterkte0 = map(audioInput, 0, 60, 0, 19);
  int ledSterkte1 = map(audioInput, 0, 60, 20, 39);
  int ledSterkte2 = map(audioInput, 0, 60, 40, 59);
  int ledSterkte3 = map(audioInput, 0, 60, 60, 79);
  int ledSterkte4 = map(audioInput, 0, 60, 80, 99);
  int ledSterkte5 = map(audioInput, 0, 60, 100, 120);
  
  FastLED.clear();
          Serial.println(audioInput);

  for (int i = 0; i < ledSterkte0; i++) {
    leds[i].setRGB (kleur4, kleur5, kleur6);
  k2++;
  if(k2 > 340){
  kleur4 = random(10, 255);
  kleur5 = random(10, 255);
  kleur6 = random(10, 255);
  k2 = 0;
  }
}
  for (int i2 = 20; i2 < ledSterkte1; i2++) {
    leds[i2].setRGB (kleur7, kleur8, kleur9);
  k3++;
  if(k3 > 340){
  kleur7 = random(10, 255);
  kleur8 = random(10, 255);
  kleur9 = random(10, 255);
  k3 = 0;
  }
}
  for (int i3 = 40; i3 < ledSterkte2; i3++) {
    leds[i3].setRGB (kleur10, kleur11, kleur12);
  k4++;
  if(k4 > 340){
  kleur10 = random(10, 255);
  kleur11 = random(10, 255);
  kleur12 = random(10, 255);
  k4 = 0;
  }
}
  for (int i4 = 60; i4 < ledSterkte3; i4++) {
    leds[i4].setRGB (kleur13, kleur14, kleur15);
  k5++;
  if(k5 > 340){
  kleur13 = random(10, 255);
  kleur14 = random(10, 255);
  kleur15 = random(10, 255);
  k5 = 0;
  }
}
  for (int i5 = 80; i5 < ledSterkte4; i5++) {
    leds[i5].setRGB (kleur16, kleur17, kleur18);
  k6++;
  if(k6 > 340){
  kleur16 = random(10, 255);
  kleur17 = random(10, 255);
  kleur18 = random(10, 255);
  k6 = 0;
  }
}
  for (int i6 = 100; i6 < ledSterkte5; i6++) {
    leds[i6].setRGB (kleur19, kleur10, kleur11);
  k7++;
  if(k7 > 340){
  kleur19 = random(10, 255);
  kleur20 = random(10, 255);
  kleur21 = random(10, 255);
  k7 = 0;
  }
}
  

FastLED.show();
if (Bluetooth.available() > 0){
    mode = "0";
      }  
      }
else if (mode == "4"){
        for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].setRGB (R, G, B);
    if (Bluetooth.available() > 0){
  mode = "0";
      }
    }
    FastLED.show();
    delay(20);  
        }
    if (dataIn.startsWith("3")){
      delay(10);
      String stringBr = dataIn.substring(dataIn.indexOf("I") + 1, dataIn.indexOf("J"));
      brightness = stringBr.toInt();
      FastLED.setBrightness(brightness);
              Serial.println(brightness);
              
          }
          FastLED.show();
    }

This has already worked out quite well. I manage to get colors and to choose modes, only I put it all together and now it doesn't work anymore. In the code I retrieve the incoming data from the bluetooth, so that a mode is selected. Only when I choose a mode in the app do I get an inverted question mark in the output of the Arduino. In another code I tested the bluetooth module and got good values out.
I send information to the bluetooth module using the app. I have 4 buttons, mode 1, mode 2, mode 3 and colors.
Photos of the app + code: Arduino Uno Hulp - Album on Imgur
Code 1, code of mode button
Code 2, code of color button
The above code ensures that I get a code with the help of a colorpicker, consisting of 2R ... G ... B ... E
The RGB values of that color are then placed on the dots.
When you click on a mode button it sends the value M1, M2, or M3. When you click the color button, it will send the value M4.

At the beginning of the code I make sure that the variable becomes mode 1, 2, 3 or 4. Only I have the problem that these codes are not retrieved properly, in the output I sometimes get an inverted question mark and sometimes it works, but then I cannot change the mode. How can I fix that? The app works the way I want, I tested this with a different code.

Thanks in advance!
PS you can download the app via these links
.apk: File on MEGA
.aia; MEGA
You can upload the aia file in MIT App Inventor so that you can access the complete code.

This thread was also posted in Joris' first language, in the Dutch section: [Opgelost] Problemen met Arduino uno met WS2812B Led strip, HC-05 en BT app - Nederlands - Arduino Forum

I'm not going to download anything, or visit some photo site to read code, but this
may be of use to you. It could be the same problem.

It is, and i already told him that in our own language.

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