Go Down

Topic: Motors and Line Follower Sensors (Read 561 times) previous topic - next topic


I am trying to make a robot follower of line with 3 sensors, But I am having difficulty in programming, Hereunder the programming

//Standard PWM DC control
int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 4;    //M1 Direction Control
int M2 = 7;    //M1 Direction Control

int sensorCantoDir = A1;
int sensorMeio = A3;
int sensorCantoEsq = A4;

int ValorCorte = 75;

int ValorLinhaM,ValorLinhaD,ValorLinhaE = 0;

void setup(void){
 int i;
   pinMode(i, OUTPUT);

void loop(){

 valorLinhaM = analogRead(sensorMeio);    
 valorCantoD = analogRead(sensorCantoDir);
 valorCantoE = analogRead(sensorCantoEsq);

 if(valorSensorM > ValorCorte){
   digitalWrite(M1, LOW); //rotacao no sentido horario do canal 1
 digitalWrite(M2, LOW); //rotacao no sentido horario do canal 2
 analogWrite(E1, 100); //informa a velocidade do canal 1 - 0 É A VELOCIDADE MINIMA
 analogWrite(E2, 100); //informa a velocidade do canal 2 - 255 É A VELOCIDADE MÁXIMA

 delay(1000); //espera 1 segundo
 analogWrite(E1, 0);
 analogWrite(E2, 0);

 if(valorSensorD > ValorCorte){
 digitalWrite(M1, LOW); //rotacao no sentido horario do canal 1
 digitalWrite(M2, HIGH); //rotacao no sentido horario do canal 2
 analogWrite(E1, 255);
 analogWrite(E2, 255);
 delay(500); //espera 0.5 segundo
 analogWrite(E1, 0);
 analogWrite(E2, 0);

 if(valorSensorE > ValorCorte){
 digitalWrite(M1, HIGH); //rotacao no sentido horario do canal 1
 digitalWrite(M2, LOW); //rotacao no sentido horario do canal 2
 analogWrite(E1, 255);
 analogWrite(E2, 255);
 delay(500); //espera 1 segundo
 analogWrite(E1, 0);
 analogWrite(E2, 0);


Aug 11, 2017, 11:39 am Last Edit: Aug 11, 2017, 11:41 am by UKHeliBob
What does the program do ?
What should it do ?

I note that valorSensorE (and other variables) are not declared in the code you posted, but the program as posted is not complete.

Please read this before posting a programming question and follow the advice regarding posting code.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


The program is clearly incomplete.

Please remember to use code tags when posting code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


Your working program to follow a line will have NO delay() statements.

You do NOT drive both wheels at the same speed to follow a line. The difference between the left wheel speed and the right wheel speed will depend on how far the line is from the center sensor.
The art of getting good answers lies in asking good questions.

Go Up