Line follower most faster

Hi!!

First, sorry for my very bad english. I'm creating line follower robot for my school, but i need it go too faster. I used Arduino Elegoo Uno with 4 CNHY70 sensor (for this, i used 4 resistor 180 ohms for catode, and 10k for colector), 2 motors, driver L298N, 1 battery 7,4V.

For the proyect, I have also used a button in pull-up with a resistor 5k6. This button is used to start up the robot. My best time is 10,9 seconds, but i need reduced this time.

My code is:

//Declaramos las constantes a usar

#define SENSOR1 A5 //Sensor exterior izquierdo
#define SENSOR2 A4 //Sensor interior izquierdo
#define SENSOR3 A3 //Sensor interior derecho
#define SENSOR4 A2 //Sensor exterior derecho
#define ADELANTE_MOTOR1 10 //1N1
#define ATRAS_MOTOR1 9 //1N2
#define ADELANTE_MOTOR2 6 //1N1
#define ATRAS_MOTOR2 2 //1N2
#define VELOCIDAD_M1 11 //ENA
#define VELOCIDAD_M2 3 //ENB
#define PULSADOR 8 //Pulsador de inicio

//Declaramos las variables
int suma = 0;


void setup() {

  //Los pinMOde
  pinMode(SENSOR1, INPUT);
  pinMode(SENSOR2, INPUT);
  pinMode(SENSOR3, INPUT);
  pinMode(SENSOR4, INPUT);
  pinMode(PULSADOR, INPUT);
  pinMode(ADELANTE_MOTOR1, OUTPUT);
  pinMode(ATRAS_MOTOR1, OUTPUT);
  pinMode(ADELANTE_MOTOR2, OUTPUT);
  pinMode(ATRAS_MOTOR2, OUTPUT);
  pinMode(VELOCIDAD_M1, OUTPUT);
  pinMode(VELOCIDAD_M2, OUTPUT);

  //Damos asignamos el sentido de giro de los motores
  digitalWrite(ADELANTE_MOTOR1, 0);
  digitalWrite(ATRAS_MOTOR1, 1);
  digitalWrite(ADELANTE_MOTOR2, 0);
  digitalWrite(ATRAS_MOTOR2, 1);

  while (digitalRead(PULSADOR))
  {
  }
  while (!digitalRead(PULSADOR))
  {
    delay(50);
    if (digitalRead(PULSADOR))
    {
      delay(3000);
    }

  }
}

void loop() {

  suma = (1 * digitalRead (SENSOR1)) + (2 * digitalRead (SENSOR2)) + (4 * digitalRead (SENSOR3)) + (8 * digitalRead (SENSOR4));


  switch(suma)
  {
    case 1:
      analogWrite (VELOCIDAD_M1, 255);
      analogWrite (VELOCIDAD_M2, 115);
      break;
    case 3:
      analogWrite(VELOCIDAD_M1, 255);
      analogWrite(VELOCIDAD_M2, 100);
      break;
    case 7:
      analogWrite (VELOCIDAD_M1, 255);
      analogWrite (VELOCIDAD_M2, 40);
      break;
    case 8:
      analogWrite (VELOCIDAD_M1, 115);
      analogWrite (VELOCIDAD_M2, 255);
      break;
    case 9:
      analogWrite (VELOCIDAD_M1, 252);
      analogWrite (VELOCIDAD_M2, 255);
      break;
    case 11:
      analogWrite (VELOCIDAD_M1, 255);
      analogWrite (VELOCIDAD_M2, 180);
      break;
    case 12:
      analogWrite (VELOCIDAD_M1, 100);
      analogWrite (VELOCIDAD_M2, 255);
      break;
    case 13:
      analogWrite (VELOCIDAD_M1, 180);
      analogWrite (VELOCIDAD_M2, 255);
      break;
    case 14:
      analogWrite (VELOCIDAD_M1, 40);
      analogWrite (VELOCIDAD_M2, 255);
      break;
    default:  
      break;
  }

}

How can I do to speed it up?

Thanks!!

I don't think your code is limiting the speed!

Bad component choice. There is a large voltage drop across that driver chip, so you need to change that for a better one or increase the voltage you supply to it.

1 Like

How about this?

TB6612FNG H-Bridge with Arduino - Better Than L298N?.

You can try changing the driver as some have suggested.

Thanks for the quick reply!!

Unfortunately, I can't change the component, the teacher gave them to me and I have to adjust to them. I attached photos of my car. I don't know if there is any way to improve the speed or optimize the program. Any help is appreciated. :blush:

Thanks very much!!

Other photo

Other photo!!

Then you can't go any faster than you are going.

Have you actually asked the teacher if you can change them? If you point out why you want to change them then maybe he / she will let you.

Oh I see. Each motor gets maximum speed when you write analogvalue 255 to them. In some of your defined cases, I can see that you've decreased the value to 100, 40 etc. What are those for?

Unfortunately it is not possible. I have to stick to the given components and I can't do much. Attached is a video of the tour of the circuit. :blush:

In those cases it is the curves that are found, it is the PWM value so that one of the motors reduces its speed and the car turns in that direction.

Fine, so you can't go any faster. No point in continuing with this thread then.

Hi!

Today I was able to reduce the circuit time. Not by speeding up, but by moving the sensors away from the motors with an extension cord. That way it doesn't come off as much in the corners and the movement is more fluid.
Thank you very much for the help!

A thing you never mentioned or defined before. Rabbit out of hat. Thanks a bunch.

Glad to know that.

Hi Grumpy_Mike!

I mentioned the time issue in the first post, which I needed to reduce. I thought the only way was to make the car go faster, but luckily I found another way to do it :blush:

Really, thank you very much for your help!! :hugs: :hugs:

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