L293D Bluetooth weird interaction

Hello guys,

I went into weird problem and I need help, maybe you will see the problem here. I am making robot, made my PCB with L293D and went into problem with control. My first motor wont start running (E1, I1, I2) after it gets char 'Q' and second starts turning (code 1). Weird thing is, that everything is good when running second program, both motors run smooth. (code 2). I checked with multi-meter enable pin1 and it gets 0V. Any ideas why?

Code1:

//Motor set
#define E1 11   // Enable Pin for motor 1
#define E2 6    // Enable Pin for motor 2

#define I1 10   // Control pin 1 for motor 1
#define I2 9    // Control pin 2 for motor 1
#define I3 7    // Control pin 1 for motor 2
#define I4 8    // Control pin 2 for motor 2
const int motorNeutral = 120;
const int turnspeed = 150;
const int speedmax = 255;

void drive()
{
  switch (c)
  {
    case 'C': case 'Q':
      {
        if (Front > 200 && Front != 0) //160mm
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
          Lmotor =  motorNeutral - Output;
          Rmotor =  motorNeutral + Output;
        }
        if (Front < 200 && Front > 10 )
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
          Lmotor = turnspeed;
          Rmotor = turnspeed;
        }

        // limit rightMotorSpeed
        if (Rmotor > 160)
          Rmotor = 160;
        else if (Rmotor < 0)
          Rmotor = 0;

        // limit rightMotorSpeed
        if (Lmotor > 160)
          Lmotor = 160;
        else if (Lmotor < 0)
          Lmotor = 0;

        analogWrite(E1, Lmotor);
        analogWrite(E2, Rmotor);
      }
      break;

code2:

case 'N':
      {
        digitalWrite(E1, LOW);
        digitalWrite(E2, LOW);
      }
      break;

    case 'G' :
      {
        digitalWrite(E1, LOW);
        digitalWrite(E2, LOW);

      case 'S':
        {
          digitalWrite(E1, LOW);
          digitalWrite(E2, LOW);
          c = '*';
        }
        break;

      case 'F':
        // turn it on going forward
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'B':
        // turn it on going backward
        {
          digitalWrite(I1, LOW);
          digitalWrite(I2, HIGH);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'L':
        // turn left
        {
          digitalWrite(I1, LOW);
          digitalWrite(I2, HIGH);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'R':
        // turn right
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;
      }
      break;
  }

Post complete code, not snippets.

Your second code does not seem to have a case for 'Q' so how can that possibly be working?

Your second code also seems to have cases inside case 'G'; no idea of the effect.

Full code is hard to understand around 1000 lines. I just tested few things and noticed. As I give to enable 1 high (255) it starts working. Why is that? Something different with digital pin11 ?

analogWrite(E1, Lmotor);
        analogWrite(E2, Rmotor);
 analogWrite(E1, 255);
        analogWrite(E2, Rmotor);

Tried to rotate L293D, to change places E1 and E2, same problem. Result : everything is fine with microchip.
Checked if the connections are fine with multi-meter, everything fine.
And I checked adafruit motor shield schematic. Same arduino 11 pin is used for enable1 pin. So what is wrong?
Why enable pin1 (arduino pin11) gets only high voltage, non medium (1-3V), which disables motor speed control.

Anyone?

Ok Its getting really weird. I wrote different program with same principle of controlling motors and motors only, it works fine. Why this is happening? weak supply or pin is used for something else thats why it lost its PWM to control speed? Both codes added

Working test program:

#define E1 11  // Enable Pin for motor 1
#define E2 6  // Enable Pin for motor 2
 
#define I1 10  // Control pin 1 for motor 1
#define I2 9  // Control pin 2 for motor 1
#define I3 7  // Control pin 1 for motor 2
#define I4 8  // Control pin 2 for motor 2
 
void setup() {
 
    pinMode(E1, OUTPUT);
    pinMode(E2, OUTPUT);
 
    pinMode(I1, OUTPUT);
    pinMode(I2, OUTPUT);
    pinMode(I3, OUTPUT);
    pinMode(I4, OUTPUT);
}
 
void loop() {
 
    analogWrite(E1, 120); // Run in half speed
    analogWrite(E2, 120); // Run in full speed
 
    digitalWrite(I1, HIGH);
    digitalWrite(I2, LOW);
    digitalWrite(I3, HIGH);
    digitalWrite(I4, LOW);
 
    delay(3000);
 
    // change direction
 
    analogWrite(E1, 120);  // Run in full speed
    analogWrite(E2, 120);  // Run in half speed
 
    digitalWrite(I1, LOW);
    digitalWrite(I2, HIGH);
    digitalWrite(I3, LOW);
    digitalWrite(I4, HIGH);
 
    delay(3000);
}

Non-working main program

//Motor set
#define E1 11  // Enable Pin for motor 1
#define E2 6  // Enable Pin for motor 2
 
#define I1 10  // Control pin 1 for motor 1
#define I2 9  // Control pin 2 for motor 1
#define I3 7  // Control pin 1 for motor 2
#define I4 8  // Control pin 2 for motor 2
 
const int motorNeutral = 120;
const int turnspeed = 150;
const int speedmax = 255;
unsigned int Leftmotor;
unsigned int Rightmotor;
void drive()
{
  switch (c)
  {
    case 'C': 
      {
        if (Front > 200 && Front != 0 && Input < 200) //160mm
        {
          Leftmotor =  motorNeutral - Output;
          Rightmotor =  motorNeutral + Output;
          
          analogWrite(E1, Leftmotor);
          analogWrite(E2, Rightmotor);
          
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
        }

        if (Front > 200 && Front != 0 && Input > 200) //160mm)     //suka i kaire
        {
          Leftmotor =  motorNeutral - Output;
          Rightmotor =  motorNeutral + Output;
          
          analogWrite(E1, Leftmotor);
          analogWrite(E2, Rightmotor);
          
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
        }

        if (Front < 200 && Front > 10 )                              //suka i desine
        {
          Leftmotor =  turnspeed;
          Rightmotor =  turnspeed;
          
          analogWrite(E1, Leftmotor);
          analogWrite(E2, Rightmotor);
          
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
        }
      }
      break;


    case 'N':
      {
        digitalWrite(E1, LOW);
        digitalWrite(E2, LOW);
      }
      break;

    case 'G' :
      {
        digitalWrite(E1, LOW);
        digitalWrite(E2, LOW);

      case 'S':
        {
          digitalWrite(E1, LOW);
          digitalWrite(E2, LOW);
          c = '*';
        }
        break;

      case 'F':
        // turn it on going forward
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'B':
        // turn it on going backward
        {
          digitalWrite(I1, LOW);
          digitalWrite(I2, HIGH);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'L':
        // turn left
        {
          digitalWrite(I1, LOW);
          digitalWrite(I2, HIGH);
          digitalWrite(I3, HIGH);
          digitalWrite(I4, LOW);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;

      case 'R':
        // turn right
        {
          digitalWrite(I1, HIGH);
          digitalWrite(I2, LOW);
          digitalWrite(I3, LOW);
          digitalWrite(I4, HIGH);
          analogWrite(E1, 255); // Run in full speed
          analogWrite(E2, 255); // Run in full speed
          c = '*';
        }
        break;
      }
      break;
  }
}
   case 'G' :
      {
        digitalWrite(E1, LOW);
        digitalWrite(E2, LOW);

      case 'S':

That means all those cases below are inside the block for G, since you didn't put a close brace there.

I'm frankly amazed that compiles...

This case is for RC car type control. R case activates control and it starts being controlled with arrow keys on phone, nothing special there. My problem is first part, when robot has to drive automatically.

Also, on the second program, RC car, 1 motor doesn't work as well on low speeds, only speed max (255)

As has been pointed out, how will cases S, F, B, L and R ever be executed as they are all inside the G case ?