test.ino 664 Bytes
/* Utilisation du capteur Ultrason HC-SR04 */

// définition des broches utilisées
int trig1 = 7;
int echo1 = 6;

int trig2 = 8;
int echo2 = 5;
long lecture_echo;
long cm;

void setup()
{
  pinMode(trig1, OUTPUT);
  digitalWrite(trig1, LOW);
  pinMode(echo1, INPUT);
  
  pinMode(trig2, OUTPUT);
  digitalWrite(trig2, LOW);
  pinMode(echo2, INPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(trig1, HIGH);
  digitalWrite(trig2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig1, LOW);
  digitalWrite(trig2, LOW);
  lecture_echo = pulseIn(echo2, HIGH);
  cm = lecture_echo / 58;
  Serial.print("Distancem : ");
  Serial.println(cm);
  delay(500);
}