Arduino Bluetooth and Outputs

Hi Everyone,

I've been stuck with an issue for a few days and cannot figure out what's wrong...I have a bluetooth module (Hm-10) connected to my Uno, and the bluetooth works.

I've ran code to output to the pins 9-12 and have verified the outputing also works for turning on 4 auxilery LEDs.

The problem is now when I try to use bluetooth AND turn on the auxiliary LEDs. The bluetooth is receiving information, and the IF statements are also triggering (I can see in console), BUT the problem is that the Auxiliery LEDs are not turning on.

see code snippet below.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7,8);
int ledpin=13;
void setup()
{
  
      pinMode(12, OUTPUT);
         pinMode(11, OUTPUT);
            pinMode(10, OUTPUT);
             pinMode(9, OUTPUT);

             
mySerial.begin(9600);
Serial.begin(9600);
pinMode(ledpin,OUTPUT);


}
void loop()
{
int i;

if (mySerial.available())
{
i=mySerial.read();
Serial.println("DATA RECEIVED:");
if(i=='0')
{
//This is the problem because LED won't turn on
Serial.println("Running Aux 9");
digitalWrite(9, HIGH);
 delay(100);                       // wait for a second
digitalWrite(9, LOW);
 delay(100); 
}
if(i=='1')
{
Serial.println("Running Aux 10");
//This is the problem because LED won't turn on
digitalWrite(10, HIGH);
 delay(100);                       // wait for a second
digitalWrite(10, LOW);
 delay(100); 
}

if(i=='2')
{
 Serial.println("Running Aux 11");
//This is the problem because LED won't turn on
digitalWrite(11, HIGH);
 delay(100);                       // wait for a second
digitalWrite(11, LOW);
 delay(100); 
}



if(i=='3')
{
 Serial.println("Running Aux 12");

//This is the problem because LED won't turn on
digitalWrite(12, HIGH);
 delay(100);                       // wait for a second
digitalWrite(12, LOW);
 delay(100); 
}



}
}

The above is the set-up that is not working...Initially I thought maybe bluetooth and LEDs won't work together because bluetooth sucks too much energy, so I provided an external power source for the bluetooth module and even then the LEDs won't turn on.

I ran the below code and the LEDs turn on, so I don't know why I can't turn them on using the Bluetooth code above:

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize digital pin LED_BUILTIN as an output.

   pinMode(13, OUTPUT);
      pinMode(12, OUTPUT);
         pinMode(11, OUTPUT);
            pinMode(10, OUTPUT);
             pinMode(9, OUTPUT);

}

// the loop function runs over and over again forever
void loop() {

digitalWrite(9, HIGH);
 delay(100);                       // wait for a second
digitalWrite(9, LOW);
 delay(100);                        // wait for a second

digitalWrite(12, HIGH);
 delay(100);                        // wait for a second
digitalWrite(12, LOW);
 delay(100);                         // wait for a second

digitalWrite(11, HIGH);
 delay(100);                       // wait for a second
digitalWrite(11, LOW);
 delay(100);                        // wait for a second


digitalWrite(10, HIGH);
 delay(100);                       // wait for a second
digitalWrite(10, LOW);
 delay(100);                      // wait for a second

}

Im out of ideas on what could be wrong...thoughts?

see code snippet below.

Please see Read this before posting a programming question then follow the advice given about posting code to make it easier for all of us to provide help

Thank you for the help. I have now made my code easier to read.

Your code is still very difficult to read because of the awful formatting.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Do you see the matching serial output in serial monitor?

PS
You are aware that your new code switches the leds on an off; after that they will stay off till new data is received.