hice este programa que les pegare al ultimo del post. mi problema es que a la hora de correrlo solo me funciona un sensor y el otro no, y cheque que los sensores funcionaran por separado y si lo hacen, pero con este programa que hice nadamas sirve uno, me podrian ayudar en identificar la solucion, o que le puedo modificar a mi programa para que me funcionen los dos sensores ultrasonicos a la vez.
Estoy casi seguro que el problema esta en el programa, ojala y me puedan ayudar,gracia
este es el programa:
int led1=13;
int led2=8;
int pingPin = 7;
int pingPin2 = 6;
int value = 0; // Valor del pulsador
int value2 =0;
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration,duration2, cm,cm2;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
pinMode(pingPin2, OUTPUT);
digitalWrite(pingPin2, LOW);
delayMicroseconds(2);
digitalWrite(pingPin2, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin2, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin2, INPUT);
duration2 = pulseIn(pingPin2, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
cm2 = microsecondsToCentimeters(duration2);
value = duration / 29 / 2;
value2 = duration2 / 29 / 2;
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
Serial.print(cm2);
Serial.print("cm2");
Serial.println();
delay(100);
if
( cm <=20 )
{digitalWrite (led1,HIGH);}
else
{digitalWrite (led2,LOW);}
if
( value2 <= 20)
{digitalWrite (led2,HIGH);
}
else
{digitalWrite (led2,LOW);}
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
les agradeceria mucho sus respuestas.
_9_de_octubre_prueba_ultrasonidos.ino (2.18 KB)