Go Down

Topic: Robot Sumo with 3 ultrasonic ans one with grove (Read 1 time) previous topic - next topic

limOP

Hello, i need help for program: Grove Ultrasonic Ranger V2.0. My problem is I can not program the sensor when there is an obstacle to 50cm and must push it on. I have only succeeded with the simple HC-SR04:
Code: [Select]

#define trigPin 12 //je défini les broches du capteur
#define echoPin 13

int IN1=3; //je déclare une variable de type int appelée IN1 et valant 3
int IN2=4;
int ENA=5;
int us;
int IN3=6;
int IN4=7;
int ENB=8;

void setup()
{
 pinMode(trigPin, OUTPUT);
 digitalWrite(trigPin, LOW);
 pinMode(echoPin, INPUT);
 us = 40 ;
 pinMode(IN1,OUTPUT);
 pinMode(IN2,OUTPUT);
 pinMode(ENA,OUTPUT);
 pinMode(IN3,OUTPUT);
 pinMode(IN4,OUTPUT);
 pinMode(ENB,OUTPUT);

}
void loop()
{
 int duration, distance;
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(2);
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 distance = (duration/2) / 29.1;// convertir en cm
 if (distance >90) //si distance supérieur à 90 cm, robot tourne sur lui-même
  {
    analogWrite(ENA,180);//Tourne le robot sur lui même
    digitalWrite(IN1,LOW);
    digitalWrite(IN2,HIGH);
    digitalWrite(IN3,HIGH);
    digitalWrite(IN4,LOW);
    analogWrite(ENB,180);
  }
else //détecte l'obstacle il avance
  {
   digitalWrite(ENA,HIGH);//avance
   digitalWrite(IN1,LOW);
   digitalWrite(IN2,HIGH);
   digitalWrite(IN3,LOW);//avance
   digitalWrite(IN4,HIGH);
   digitalWrite(ENB,HIGH);
  }
}

thank for help :D

AWOL

Quote
with 3 ultrasonic ans one with grove
What does that mean, please?

"Pete, it's a fool 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.

AWOL

Quote
I can not make it se-him for the grove?
Still problematic in the comprehension domain.
"Pete, it's a fool 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.

Go Up