ultrasonic sensor and line follower robot

hello everyone :smiley:

i have a problem with my ultrasonic sensor , i don't know why it doesn't work but for me it sems that a code problem

my project is to creat a line follower robot: for that i use 2 motors and 4 infrared sensor ..

my robot suppose to stop when the 4 sensors in black OR the ultrsonic sensor detects an obstacle in 10 cm

when i put the code for just following line it works perfectliy but when i add the ultrasonic never work and

he don't follows the line anymore

can you please help me

#include <NewPing.h>

// ****************************************
// Déclaration des constantes et variables
// ****************************************

// capteur de distance

#define trigPin   12  //  Pin Trigger branchée sur la broche 12 de l'arduino
#define echoPin   11  //  Pin Echo branchée sur la broche 11 de l'arduino



NewPing sonar(trigPin, echoPin);

int maximumDistance = 50;  // distance Maximale acceptée (de 0-450 cm)
int minimumDistance = 0;   // distance Minimale acceptée (en cm)
int cm = 0;


boolean PasObstacle = true;   // valeur à O ou true si pas d'obstacle détecté  sinon la valeur prend 1

const int distanceObstacle = 10; //  Distance de détection d'un obstable : ici 15 cm
int distance = 0;
int attenteCateur = 200;

//définition des bouttons
int button1=1;  //vert 
int button=2;   //rouge
int z;
int w; 

int cap1=3;  
int cap2=4;  
int cap3=5;  
int cap4=6;  

int varmot2=9;
int av2=7;       //avant 
int ar2=8;       //arrière

int varmot1=14;
int av1=15;       //avant 
int ar1=16;

boolean a;
boolean b;  //les deux capteurs au milieu 
boolean c; //les deux capteurs au milieu 
boolean d; 

boolean stope;
boolean left;
boolean right;
boolean forward;
boolean backward;


void setup() {
  // dir.attach(13);
   //dir.write(90);
  pinMode(varmot1,OUTPUT);
  pinMode(av1,OUTPUT);
  pinMode(ar1,OUTPUT);

  pinMode(varmot2,OUTPUT);
  pinMode(av2,OUTPUT);
  pinMode(ar2,OUTPUT);
  
  Serial.begin(9600);

pinMode(button,INPUT);
  pinMode(button1,INPUT);

}

void loop() {
  int val1,val2,val3,val4 ;
  val1 = digitalRead(cap1) ;
    a = val1 ;                  //< 500;
  val2 = digitalRead(cap2) ;
    b = val2 ;                   //< 500;
  val3 = digitalRead(cap3) ;
    c = val3 ;                  //< 500;
  val4 = digitalRead(cap4) ;
    d = val4 ;                   //< 500;


 right=           (((!a)&&(d))&&(c||(!b)));   //(((!b)&&(!a))&& d);

 left=            ((a&&(!d))&&(b||(!c)));   //(((!d)&& a) &&(!c)); 

 backward=   (((!a)&&(!c))&&((!b)&&(!d)));      //||(b&&d)))||((!b)&&(!d)&&a&&c);

 forward=   ((!a)&&(b)&&(c)&&(!d));       //||(a&&d)))||(a&&(!b)&&(!c)&&d);

 stope=     (a&&b&&c&&d);
 
 lecture ();

   distance =  mesureDistance();  // on lit la valeur en cm

if (PasObstacle)  {
  
  z=digitalRead(1);
 w=digitalRead(2);
 
 if ((stope)&&(w==1))
{
  droite (); 
  delay(500);
}
else if ((stope)&&(z==1))
{
avant();
delay(500);
  }


  if (left)
  
   {
    gauche () ;          
   }
   
  else if (right)
  
    {
      droite();
    }
  
  else if (forward)
  
   {  
    avant(); 
   }
  
 else if (backward)
  
   {
    arrier ();
   }
    
  else if (stope)
{
  stopp();}
}
  else
  {
    stopp();}
  // on lit la valeur en cm
  }
unsigned int mesureDistance() {
  // déclaration des variables locales



  int  cm = sonar.ping_cm();


  if (cm > distanceObstacle || cm  <= minimumDistance) {
    PasObstacle =  true;  // on renvoie true s'il n'y pas d'obstacle
  }
  else  {
    PasObstacle = false;  // on renvoie false s'il y a un obstacle
  }

  return cm; // retourne la distance du capteur en cm

}

void lecture ()
 {
    Serial.print(a);
    Serial.print(b);
    Serial.print(c);
    Serial.println(d);

  }


void gauche ()
  {
    analogWrite(varmot1,100);
    digitalWrite(av1,0);
    digitalWrite(ar1,0);
    //dir.write(50);
    analogWrite(varmot2,255);
    digitalWrite(av2,1);
    digitalWrite(ar2,0);
    
  }
void droite () 
 {
    analogWrite(varmot1,255);
    digitalWrite(av1,1);
    digitalWrite(ar1,0);
    //dir.write(130);
  analogWrite(varmot2,100);
    digitalWrite(av2,0);
    digitalWrite(ar2,0);
 }
  
void avant () 

  {
    analogWrite(varmot1,250);
    digitalWrite(av2,HIGH);
    digitalWrite(ar2,LOW);
    //dir.write(90);
    analogWrite(varmot2,250);
    digitalWrite(av1,1);
    digitalWrite(ar1,0);
  }
void arrier () 
  {
    analogWrite(varmot1,150);
    digitalWrite(av2,LOW);
    digitalWrite(ar2,HIGH);
    analogWrite(varmot2,150);
    digitalWrite(av1,0);
    digitalWrite(ar1,1);
  }

void stopp ()
  {
    digitalWrite(av1,LOW);
    digitalWrite(ar1,LOW);
    digitalWrite(av2,LOW);
    digitalWrite(ar2,LOW);    
    }

Given that

int maximumDistance = 50;  // distance Maximale acceptée (de 0-450 cm)
int minimumDistance = 0;   // distance Minimale acceptée (en cm)

The code

if (cm > distanceObstacle || cm  <= minimumDistance) {

Will always be true. Would you mean to AND those two statements and not OR them?

That is && in place of ||

Please format your code properly before posting, the autoformat function of the IDE can help out.

This doesn't make sense:

  int val1,val2,val3,val4 ;
  val1 = digitalRead(cap1) ;
  a = val1 ;                  //< 500;
  • you declare a local variable, an int,
  • use that to store a 1 or a 0, depending on what the digitalRead() returns,
  • then store that in a global bool, not using the local int any more.

Yes it works, no it's not good practice. Just declare four bools there, and use them to store the pin state.

backward=   (((!a)&&(!c))&&((!b)&&(!d)));      //||(b&&d)))||((!b)&&(!d)&&a&&c);

The comment is even less readable as what you're doing here... and you are probably looking for the & operator, not the && operator. I'm sure these lines can be done in a readable manner. Or at least use comments that tell what is going on, not something that makes the Perl syntax look good.

  distance =  mesureDistance();  // on lit la valeur en cm

And then you do nothing with the distance, but you do look at the global bool PasObstacle.

  z=digitalRead(1);

Bad idea: that's the Serial interface. Don't use pins 0 and 1 unless you really don't have any others (and know what you're doing).

All in all the code is such a mess that I can't tell more than just these oddities. A reformat will go a long way making it readable and understandable. Actually using variables that you declare (like the button pin numbers) would be another great improvement.

Grumpy_Mike:
Given that

int maximumDistance = 50;  // distance Maximale acceptée (de 0-450 cm)

int minimumDistance = 0;  // distance Minimale acceptée (en cm)




The code 


if (cm > distanceObstacle || cm  <= minimumDistance) {



Will always be true. Would you mean to AND those two statements and not OR them?

That is && in place of ||

cm <= minimumDistance is false unless cm = 0. So it's pretty much redundant in this situation.

The thing evaluates to true the moment cm > distanceObstacle is true, which would be cm > 10. That's sensible. Then the PasObstacle is set true, and the normal movement is done. To me this part actually looks correct.

i am sorry for the bad comments in the code i just write them when i am testing

this my new code after reading your comments .. but nothing change .. he doesn't work

thank you very much for the reponse

#include <NewPing.h>
// capteur ultrasonic

#define trigPin   12  //  Pin Trigger branchée sur la broche 12 de l'arduino
#define echoPin   11  //  Pin Echo branchée sur la broche 11 de l'arduino

NewPing sonar(trigPin, echoPin);

int cm = 0; //declare une variable cm qui je l'utilise dans la comparaison 

boolean PasObstacle; 

const int distanceObstacle =10; //  Distance de détection d'un obstable : ici 10 cm
int distance = 0;

//définition des bouttons

int button1=20;  //vert 
int button=21;   //rouge
int z;
int w; 
// définition des capteur ultrason 
int cap1=3;  // cap gauche
int cap2=4;  // cap milieu
int cap3=5;  // cap milieu
int cap4=6;  // cap droite
// definition de boche de la carte de puissance 
int varmot2=9;
int av2=7;       //avant 
int ar2=8;       //arrière

int varmot1=14;
int av1=15;       //avant 
int ar1=16;

boolean a;
boolean b;//les deux capteurs au milieu 
boolean c;//les deux capteurs au milieu 
boolean d; 

boolean stope;// j'ecrit stope à la fin "e" car tt simplement lorque j'ecrit stop elle devient en rouge don je pense que c'est une fonction prédifine. 
boolean left;
boolean right;
boolean forward;
boolean backward;


void setup() {
 
  pinMode(varmot1,OUTPUT);
  pinMode(av1,OUTPUT);
  pinMode(ar1,OUTPUT);

  pinMode(varmot2,OUTPUT);
  pinMode(av2,OUTPUT);
  pinMode(ar2,OUTPUT);
  
  Serial.begin(9600);

pinMode(button,INPUT);
pinMode(button1,INPUT);

}

void loop() {
  
 a = digitalRead(cap1) ; // a recoi la valeur de cap1 (1 ou 0) 
                     
  b = digitalRead(cap2) ;// b recoi la valeur de cap2 (1 ou 0)
                    
 c = digitalRead(cap3) ;// c recoi la valeur de cap3  (1 ou 0)
                    
 d = digitalRead(cap4) ;// d recoi la valeur de cap4 (1 ou 0) 
                     

 right=(((!a)&&(d))&&(c||(!b)));  // le robot doit tourner à droite lorsque la condition est vrai c'est à dire ( le capteur à droite est en noir OU bien le capteur droite ET le milieu en noir )

 left=((a&&(!d))&&(b||(!c)));   // le robot doit tourner à gauche lorsque la condition est vrai c'est à dire ( le capteur à gauche est en noir OU bien le capteur gauche ET le milieu  en noir )

 backward=(((!a)&&(!c))&&((!b)&&(!d))); // le robot doit étre marche en arriére lorsque il sort de map c'est à dire les 4 capteur en blanc      
 
 forward=((!a)&&(b)&&(c)&&(!d)); // le robot doit étre marche en avant lorsque le 2 capteur au milieu est en noir      
 
 stope=(a&&b&&c&&d);// le robot fait un stop lorsque les 4 capteur en noir 
 
 lecture ();// fonction pour just affichier le valeur des capteur en moniteur série 

   distance =  mesureDistance();  // on lit la valeur en cm

if (PasObstacle)  {
  
  z=digitalRead(20);
 w=digitalRead(21);
 
 if ((stope)&&(w==1)) // si le robot est en stop est on appui sue le bouton rouge il tourne droite
{
  droite (); 
  delay(500);
}
else if ((stope)&&(z==1))  // si le robot est en stop est on appui sue le bouton vert rouge il marche avant 
{
avant();
delay(500);
  }
  
  if (left)
  
   {
    gauche () ;          
   }
   
  else if (right)
  
    {
      droite();
    }
  
  else if (forward)
  
   {  
    avant(); 
   }
  
 else if (backward)
  
   {
    arrier ();
   }
    
  else if (stope)
{
  stopp();}
}
  else
  {
    stopp();}
  }
unsigned int mesureDistance() { // fonctin pour comparer la distance calculé avec la distanceobstacle

  int  cm = sonar.ping_cm();


  if (cm > distanceObstacle) {
    PasObstacle =  true;  // on renvoie true s'il n'y pas d'obstacle
  }
  else  {
    PasObstacle = false;  // on renvoie false s'il y a un obstacle
  }

  return cm; // retourne la distance du capteur en cm

}

void lecture ()
 {
    Serial.print(a);
    Serial.print(b);
    Serial.print(c);
    Serial.println(d);

  }


void gauche ()
  {
    analogWrite(varmot1,100);
    digitalWrite(av1,0);
    digitalWrite(ar1,0);
    analogWrite(varmot2,255);
    digitalWrite(av2,1);
    digitalWrite(ar2,0);
    
  }
void droite () 
 {
    analogWrite(varmot1,255);
    digitalWrite(av1,1);
    digitalWrite(ar1,0);
  analogWrite(varmot2,100);
    digitalWrite(av2,0);
    digitalWrite(ar2,0);
 }
  
void avant () 

  {
    analogWrite(varmot1,250);
    digitalWrite(av2,HIGH);
    digitalWrite(ar2,LOW);
    analogWrite(varmot2,250);
    digitalWrite(av1,1);
    digitalWrite(ar1,0);
  }
void arrier () 
  {
    analogWrite(varmot1,150);
    digitalWrite(av2,LOW);
    digitalWrite(ar2,HIGH);
    analogWrite(varmot2,150);
    digitalWrite(av1,0);
    digitalWrite(ar1,1);
  }

void stopp ()
  {
    digitalWrite(av1,LOW);
    digitalWrite(ar1,LOW);
    digitalWrite(av2,LOW);
    digitalWrite(ar2,LOW);    
    }

Grumpy_Mike:
Given that

int maximumDistance = 50;  // distance Maximale acceptée (de 0-450 cm)

int minimumDistance = 0;  // distance Minimale acceptée (en cm)




The code 


if (cm > distanceObstacle || cm  <= minimumDistance) {



Will always be true. Would you mean to AND those two statements and not OR them?

That is && in place of ||

i just want that my robot stop when the distance <10

Please start by making your code readable, as I requested in #2.

Some decent formatting, remove unnecessary whitelines, that kind of things. It helps a lot in finding out what it does and where it goes wrong.

#include <NewPing.h>
// capteur ultrasonic
#define trigPin   12  //  Pin Trigger branchée sur la broche 12 de l'arduino
#define echoPin   11  //  Pin Echo branchée sur la broche 11 de l'arduino
NewPing sonar(trigPin, echoPin);
int cm = 0; //declare une variable cm qui je l'utilise dans la comparaison
boolean PasObstacle;
const int distanceObstacle = 10; //  Distance de détection d'un obstable : ici 10 cm
int distance = 0;
//définition des bouttons
int button1 = 20; //vert
int button = 21; //rouge
int z;
int w;
// définition des capteur ultrason
int cap1 = 3; // cap gauche
int cap2 = 4; // cap milieu
int cap3 = 5; // cap milieu
int cap4 = 6; // cap droite
// definition de boche de la carte de puissance
int varmot2 = 9;
int av2 = 7;     //avant
int ar2 = 8;     //arrière
int varmot1 = 14;
int av1 = 15;     //avant
int ar1 = 16;
boolean a;
boolean b;//les deux capteurs au milieu
boolean c;//les deux capteurs au milieu
boolean d;
boolean stope;// j'ecrit stope à la fin "e" car tt simplement lorque j'ecrit stop elle devient en rouge don je pense que c'est une fonction prédifine.
boolean left;
boolean right;
boolean forward;
boolean backward;
void setup() {
  pinMode(varmot1, OUTPUT);
  pinMode(av1, OUTPUT);
  pinMode(ar1, OUTPUT);
  pinMode(varmot2, OUTPUT);
  pinMode(av2, OUTPUT);
  pinMode(ar2, OUTPUT);
  Serial.begin(9600);
  pinMode(button, INPUT);
  pinMode(button1, INPUT);

}

void loop() {
  a = digitalRead(cap1) ; // a recoi la valeur de cap1 (1 ou 0)
  b = digitalRead(cap2) ;// b recoi la valeur de cap2 (1 ou 0)
  c = digitalRead(cap3) ;// c recoi la valeur de cap3  (1 ou 0)
  d = digitalRead(cap4) ;// d recoi la valeur de cap4 (1 ou 0)
  right = (((!a) && (d)) && (c || (!b))); // le robot doit tourner à droite lorsque la condition est vrai c'est à dire ( le capteur à droite est en noir OU bien le capteur droite ET le milieu en noir )
  left = ((a && (!d)) && (b || (!c))); // le robot doit tourner à gauche lorsque la condition est vrai c'est à dire ( le capteur à gauche est en noir OU bien le capteur gauche ET le milieu  en noir )
  backward = (((!a) && (!c)) && ((!b) && (!d))); // le robot doit étre marche en arriére lorsque il sort de map c'est à dire les 4 capteur en blanc
  forward = ((!a) && (b) && (c) && (!d)); // le robot doit étre marche en avant lorsque le 2 capteur au milieu est en noir
  stope = (a && b && c && d); // le robot fait un stop lorsque les 4 capteur en noir
  lecture ();// fonction pour just affichier le valeur des capteur en moniteur série
  distance =  mesureDistance();  // on lit la valeur en cm
  if (PasObstacle)  {
    z = digitalRead(20);
    w = digitalRead(21);
    if ((stope) && (w == 1)) // si le robot est en stop est on appui sue le bouton rouge il tourne droite
    {
      droite ();
      delay(500);
    }
    else if ((stope) && (z == 1)) // si le robot est en stop est on appui sue le bouton vert rouge il marche avant
    {
      avant();
      delay(500);
    }
    if (left)
    {
      gauche () ;
    }
    else if (right)
    {
      droite();
    }
    else if (forward)
    {
      avant();
    }
    else if (backward)
    {
      arrier ();
    }
    else if (stope)
    {
      stopp();
    }
  }
  else
  {
    stopp();
  }
}
unsigned int mesureDistance() { // fonctin pour comparer la distance calculé avec la distanceobstacle
  int  cm = sonar.ping_cm();
  if (cm > distanceObstacle) {
    PasObstacle =  true;  // on renvoie true s'il n'y pas d'obstacle
  }
  else  {
    PasObstacle = false;  // on renvoie false s'il y a un obstacle
  }
  return cm; // retourne la distance du capteur en cm
}

void lecture ()
{
  Serial.print(a);
  Serial.print(b);
  Serial.print(c);
  Serial.println(d);
}
void gauche ()
{
  analogWrite(varmot1, 100);
  digitalWrite(av1, 0);
  digitalWrite(ar1, 0);
  analogWrite(varmot2, 255);
  digitalWrite(av2, 1);
  digitalWrite(ar2, 0);
}
void droite ()
{
  analogWrite(varmot1, 255);
  digitalWrite(av1, 1);
  digitalWrite(ar1, 0);
  analogWrite(varmot2, 100);
  digitalWrite(av2, 0);
  digitalWrite(ar2, 0);
}

void avant ()
{
  analogWrite(varmot1, 250);
  digitalWrite(av2, HIGH);
  digitalWrite(ar2, LOW);
  analogWrite(varmot2, 250);
  digitalWrite(av1, 1);
  digitalWrite(ar1, 0);
}
void arrier ()
{
  analogWrite(varmot1, 150);
  digitalWrite(av2, LOW);
  digitalWrite(ar2, HIGH);
  analogWrite(varmot2, 150);
  digitalWrite(av1, 0);
  digitalWrite(ar1, 1);
}
void stopp ()
{
  digitalWrite(av1, LOW);
  digitalWrite(ar1, LOW);
  digitalWrite(av2, LOW);
  digitalWrite(ar2, LOW);
}

i just want that my robot stop when the distance <10

but the
cm <= minimumDistance
with
int minimumDistance = 0

means it won't.

Grumpy_Mike:
but the
cm <= minimumDistance
with
int minimumDistance = 0

means it won't.

i change that !
i put cm<=sonar.ping_cm();
if (cm > distanceObstacle) {
PasObstacle = true; // on renvoie true s'il n'y pas d'obstacle
}
else {
PasObstacle = false; // on renvoie false s'il y a un obstacle
}
return cm; // retourne la distance du capteur en cm
}

can you please check my post #7?

Also here

AWOL:
Also here

is that a problem that i ask the same question in frensh ?
i just need some help.. but it seems that i am wasting your time and mine too
ps :I am beginner .. I am not professional with the arduino ..
when i first see your comment and you put a link.. i just think it's a useful link or a solution hh..it's very painful when you are full of stress and you are doing your best in a project and you call some help and get comments like this..
anyway thank you very much and sorry for the disturbance i will find my solution alone :slight_smile:

safa_1997:
is that a problem that i ask the same question in frensh ?
i just need some help.. but it seems that i am wasting your time and mine too
ps :I am beginner .. I am not professional with the arduino ..
when i first see your comment and you put a link.. i just think it's a useful link or a solution hh..it's very painful when you are full of stress and you are doing your best in a project and you call some help and get comments like this..
anyway thank you very much and sorry for the disturbance i will find my solution alone :slight_smile:

I have no problems with you posting in different languages, but it would be polite to inform people that you have done so.

I am not professional with the arduino ..

Me neither.

I don't see that posting another post is impolite behavior!! and i think that nobody will mind ! Anyway, as I say I solved the problem by myself and I decide to share my new code for other people that may have my same problem

#include <NewPing.h>
// capteur ultrasonic
#define trigPin   24  //  Pin Trigger branchée sur la broche 12 de l'arduino
#define echoPin   25  //  Pin Echo branchée sur la broche 11 de l'arduino

NewPing sonar(trigPin, echoPin);
int maximumDistance = 50;  // distance Maximale acceptée (de 0-450 cm)
int minimumDistance = 0;   // distance Minimale acceptée (en cm)
int cm = 0; //declare une variable cm qui je l'utilise dans la comparaison 
boolean PasObstacle; 
const int distanceObstacle =10; //  Distance de détection d'un obstable : ici 10 cm
int distance = 0;
//Define Pins
int button1 = 22; //vert
int button = 23; //rouge
int z=0;
int w=0;

int ENA = 3; //Enable Pin of the Right Motor (must be PWM)
int IN1 = 7; //Control Pin
int IN2 = 2;

int ENB = 6; //Enable Pin of the Left Motor (must be PWM)
int IN3 = 4;
int IN4 = 5;

//Speed of the Motors
#define ENASpeed 250
#define ENBSpeed 250

int Sensor1 = 0;
int Sensor2 = 0;
int Sensor3 = 0;
int Sensor4 = 0;

void setup() {
Serial.begin(9600);
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(Sensor1, INPUT);
  pinMode(Sensor2, INPUT);
  pinMode(Sensor3, INPUT);
  pinMode(Sensor4, INPUT);

  pinMode(button, INPUT);
  pinMode(button1, INPUT);
}

void loop() {

  //Use analogWrite to run motor at adjusted speed
  analogWrite(ENA, ENASpeed);
  analogWrite(ENB, ENBSpeed);

  //Read the Sensor if HIGH (BLACK Line) or LOW (WHITE Line)
  Sensor1 = digitalRead(10);
  Sensor2 = digitalRead(11);
  Sensor3 = digitalRead(12);
  Sensor4 = digitalRead(13);
  z = digitalRead(22);
  w = digitalRead(23);
  //Set conditions for FORWARD, LEFT and RIGHT
distance =  mesureDistance();  // on lit la valeur en cm
if (PasObstacle)  {
  if (Sensor4 == HIGH && Sensor3 == LOW && Sensor2 == LOW && Sensor1 == LOW) 
  {
    //Turn LEFT
    //motor A Backward
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);

    //motor B Forward
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
  }

  else if (Sensor4 == LOW && Sensor3 == LOW && Sensor2 == LOW && Sensor1 == HIGH) 
    {
      //Turn RIGHT
    
    //motor A Forward
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);

    //motor B Backward
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
  }

  
  else if (Sensor4 == HIGH && Sensor3 == HIGH && Sensor2 == HIGH && Sensor1 == HIGH)
  {


  
       if  (w == 1)
  {
    //Turn RIGHT
    //motor A Forward
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);

    //motor B Backward
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    delay(500);
  }
   else  if  (z == 1)
  {
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    delay(500);
  }    
 else {
    // stop
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
 }  

  }
  else if (Sensor4 == LOW && Sensor3 == LOW && Sensor2 == LOW && Sensor1 == LOW)
  {
    // backward
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
  }


else 
  {
    //FORWARD
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
  }

 
}
else {
   digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
}
   
}
unsigned int mesureDistance() { // fonctin pour comparer la distance calculé avec la distanceobstacle
  int  cm = sonar.ping_cm();
  if (cm > distanceObstacle || cm  <= minimumDistance) {
    PasObstacle =  true;  // on renvoie true s'il n'y pas d'obstacle
  }
  else  {
    PasObstacle = false;  // on renvoie false s'il y a un obstacle
  }
 
  return cm; // retourne la distance du capteur en cm

}

safa_1997:
I don't see that posting another post is impolite behavior!! and i think that nobody will mind !

Well, many people believe all sorts of weird stuff, so you're not alone.

Just don't do it here.

AWOL:
Well, many people believe all sorts of weird stuff, so you're not alone.

Just don't do it here.

believe me ! this is the last time that i post something here ..

with all my respect for the people that really help :smiley:

safa_1997:
I don't see that posting another post is impolite behavior!! and i think that nobody will mind !

You COMPLETELY missed the point of AWOLs comment.

The problem is not the post in the French section. The problem is not informing both sections of the forum about the existence of the other post.

Duplicate posts result in duplicate effort of volunteer services. In other words, you're wasting the time of people offering free help.