Having 3 dc motors runing at low speed controled by bluetooth

Hey guys, I want to run 3 dc motors connected to 2 l298n drivers at a slow speed and control it via an app. Everything is functioning just fine besides the speed of the motors, which is always at maximum speed. I can't figure out how to set the speed I want. The code I have is the following:

int motor1Pin1 = 8; 
int motor1Pin2 = 9; 
int enable1Pin = 10; 
int motor2Pin1 = 12; 
int motor2Pin2 = 13; 
int enable2Pin = 11; 
int motor3Pin1 = 2;
int motor3Pin2 = 3;
int enable3Pin = 4;
int state;
int flag=0;       
int stateStop=0;
float delay_time;

void setup() 
  
{    // sets the pins as outputs:
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(enable1Pin, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    pinMode(enable2Pin, OUTPUT);
    pinMode(motor3Pin1, OUTPUT);
    pinMode(motor3Pin2, OUTPUT);
    pinMode(enable3Pin, OUTPUT);

    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

void loop() {

 //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state = Serial.read();   
      flag=0;
      delay_time = 15;  
    }
    else
    {
      delay_time=0;
      }
       
    // if the state is 'F' the DC motor will go Forward
    if (state == 'F') {
        analogWrite(enable1Pin, 30);
        digitalWrite(motor1Pin1, HIGH);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, LOW);
        if(flag == 0){
          Serial.println("Go Forward!");
          flag=1;
        }
    }
    
    // if the state is 'L' the motor will turn Left
    else if (state == 'L') {
        analogWrite(enable2Pin, 30);
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, LOW);
        if(flag == 0){
          Serial.println("Turn LEFT");
          flag=1;
        }
    }
    // if the state is 'S' the motor will Stop
    else if (state == 'S' || stateStop == 1) {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, LOW);
        if(flag == 0){
          Serial.println("STOP!");
          flag=1;
        }
        stateStop=0;
    }
    // if the state is 'R' the motor will turn Right
    else if (state == 'R') {
        analogWrite(enable2Pin, 30);
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, LOW);
        if(flag == 0){
          Serial.println("Turn RIGHT");
          flag=1;
        }
    }
    // if the state is 'B' the motor will Reverse
    else if (state == 'B') {
        analogWrite(enable1Pin, 30);
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, HIGH); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, LOW);
        if(flag == 0){
          Serial.println("Reverse!");
          flag=1;
        }
    }

    // if the state is 'U' the motor will go Up
    else if (state == 'U') {
        analogWrite(enable3Pin, 30);
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, HIGH);
        digitalWrite(motor3Pin2, LOW);
      if(flag == 0){
        Serial.println("Go UP");
        flag=1;
        }
}
    // if the state is 'D' the motor will go Down
     else if (state == 'D') {
        analogWrite(enable3Pin, 30);
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, HIGH);
        if(flag == 0){
          Serial.println("Go Down");
          flag=1;
        }


}

}

Please make a simple pencil drawing showing clearly how you have everything connected and post a photo of the drawing.

Please DO NOT post a Fritzing diagram.

...R
Simple Image Posting Guide

If the motors are running at full speed with only 30 written to enable then you probably have something connected up wrong.

My guess is that your L298N board has a link connecting the enable pin to 5V and you haven't removed it so it's ignoring your analogWrite(). But with no details of the hardware, power or connections it is just a guess.

Steve

Thanks for the replies. I tried to be the most explicit possible in the drawing. Regarding the enable pins, perhaps my mistake is there. I took off the black thing that was connecting the 2 pins and so i am connecting both pins to the same point on the breadboard, i don't know if that's what's causing the problem.



manbap:
Thanks for the replies. I tried to be the most explicit possible in the drawing.

It would have been better if I did not have to turn my laptop on its side to read it. It would also be much easier to follow the diagram if you had drawn all the connections to the Arduino.

My suggestion is to disconnect everything except a single motor and get that working with the simplest possible program.

...R