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!!