back to the pings))

I am really sorry but i still can't get this code to work it uploads fine to the board, but the problem is the sensors are giving me 0s and 1s back in the serial monitor. Can anyone suggest what is going wrong please?

int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
long vala, valb;
long timecounta;
long timecountb;
long startTime;
int ledPin = 13; // LED connected to digital pin 13
boolean pulseAin, pulseBin;

void setup() {
 beginSerial(9600);                  // Sets the baud rate to 9600
 pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
 timecounta = 0;
 timecountb = 0;
 vala = 0;
 valb = 0;
 pinMode(pingpina, OUTPUT);
 pinMode(pingpinb, OUTPUT); // Switch signalpin to output

 /* Send low-high-low pulse to activate the trigger pulse of the sensor
  * -------------------------------------------------------------------
  */

  digitalWrite(pingpina, LOW); // Send low pulse
  digitalWrite(pingpinb, LOW); // Send low pulse

 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(pingpina, HIGH); // Send high pulse
 digitalWrite(pingpinb, HIGH); // Send high pulse
 delayMicroseconds(5);
 digitalWrite(pingpina, LOW); // Send low pulse
 digitalWrite(pingpinb, LOW);
//

 pulseAin = false;
 pulseBin = false;

 pinMode(pingpina, INPUT); // Switch signalpin A to input
 pinMode(pingpinb, INPUT); // Switch signalpin B to input
 startTime = millis();

 while(pulseAin == false || pulseBin == false) { // Loop until both pins reads a high value
 if( digitalRead(pingpina) != 0 && pulseAin == false){
 vala = millis() - startTime;
 pulseAin = true;
    }
if( digitalRead(pingpinb) != 0 && pulseBin == false){
 valb = millis() - startTime;
 pulseBin = true;
    }
 }
 /* Writing out values to the serial port
  * -------------------------------------------------------------------
  */

  Serial.print("Sensor A value =");
  Serial.println(vala);
 Serial.print("Sensor b value =");
  Serial.println(valb);
delay (10);
}

Have you gotten the ping)))s to work with the demo code one at a time?

the sensors work fine with other pieces of code like the ones at the playground, I just can't get two working at the same time, i started a thread last year called 2 pings 1 diecimilia and am just getting stuck in loop!

Try putting brackets in your conditional statements

while(pulseAin == false || pulseBin == false)
change to
while((pulseAin == false) || (pulseBin == false))

if( digitalRead(pingpinb) != 0 && pulseBin == false)
change to
if( (digitalRead(pingpinb) != 0 ) && (pulseBin == false))

As logical precedents are not always what you think

yeah i changed the brackets and still 0s and 1s and the sensors out put the same number at the same time so surely some things going wrong.

so this is the other piece of code that sort of works. In the serial monitor it gives out randomy numbers, does anyone know which way is the best to go.

int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
int vala;
int valb;
int pingValuea = 0;
int pingValueb = 0;
int timecounta;
int timecountb;
int ledPin = 13; // LED connected to digital pin 13


void setup() {
 beginSerial(9600);                  // Sets the baud rate to 9600
 pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
 timecounta = 0;
 timecountb = 0;
 vala = 0;
 valb = 0;
 pinMode(pingpina, OUTPUT);
 pinMode(pingpinb, OUTPUT); // Switch signalpin to output

 /* Send low-high-low pulse to activate the trigger pulse of the sensor
  * -------------------------------------------------------------------
  */

  digitalWrite(pingpina, LOW); // Send low pulse
  digitalWrite(pingpinb, LOW); // Send low pulse

 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(pingpina, HIGH); // Send high pulse
 digitalWrite(pingpinb, HIGH); // Send high pulse
 delayMicroseconds(5);
 digitalWrite(pingpina, LOW); // Send low pulse
 digitalWrite(pingpinb, LOW);
//


 pinMode(pingpina, INPUT); // Switch signalpin A to input
 pinMode(pingpinb, INPUT); // Switch signalpin B to input


vala = digitalRead(pingpina);
while(vala == LOW) {
  vala = digitalRead(pingpina);
}
  valb = digitalRead(pingpinb);
while(valb == LOW) {
  valb = digitalRead(pingpinb);
}

while(vala == HIGH) {
  vala = digitalRead(pingpina);
  timecounta = timecounta +1;
}

while(valb == HIGH) {
  valb = digitalRead(pingpinb);
  timecountb = timecountb +1;
}
 /* Writing out values to the serial port
  * -------------------------------------------------------------------
  */
  pingValuea = timecounta;
  pingValueb = timecountb;
  

  Serial.print("Sensor A value = ");
  Serial.println(pingValuea);
 Serial.print("Sensor b value = ");
  Serial.println(pingValueb);
delay (10); // put any delay you need here to slow down the loop
}

In your code you are not using pulsein like the other code in the playground. I think your way of doing it may be taking too much time and you are missing the return pulses. Also remember the sonic waves are not very directional and bounce off objects so you need to find a way to isolate the two pings from hearing the others echo.

right so i have changed the code so that it uses the pulseIn function, it uploads to the board and works for a few seconds but doesn't sustain itself, i hope i haven't broken my adruino!
here's the code:

int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
long vala;
long valb;
int ledPin = 13; // LED connected to digital pin 13
boolean pulseAin, pulseBin;

void setup() {
 beginSerial(9600);                  // Sets the baud rate to 9600
 pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
 pinMode(pingpina, OUTPUT);
 pinMode(pingpinb, OUTPUT); // Switch signalpin to output

 /* Send low-high-low pulse to activate the trigger pulse of the sensor
  * -------------------------------------------------------------------
  */

  digitalWrite(pingpina, LOW); // Send low pulse
  digitalWrite(pingpinb, LOW); // Send low pulse

 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(pingpina, HIGH); // Send high pulse
 digitalWrite(pingpinb, HIGH); // Send high pulse
 delayMicroseconds(5);
 digitalWrite(pingpina, LOW); // Send low pulse
 digitalWrite(pingpinb, LOW);
//

 pulseAin = false;
 pulseBin = false;

 pinMode(pingpina, INPUT); // Switch signalpin A to input
 pinMode(pingpinb, INPUT); // Switch signalpin B to input

 while(pulseAin == false || pulseBin == false) { // Loop until both pins reads a high value
 if( digitalRead(pingpina) != 0 && pulseAin == false){
 vala = pulseIn(pingpina, HIGH);
 pulseAin = true;
    }
if( digitalRead(pingpinb) != 0 && pulseBin == false){
 valb = pulseIn(pingpinb, HIGH);
 pulseBin = true;
    }
 }
 /* Writing out values to the serial port
  * -------------------------------------------------------------------
  */
// do the scalling of your results here
  Serial.print("Sensor A value =");
  Serial.println(vala);
 Serial.print("Sensor b value =");
  Serial.println(valb);
delay(40);
}

it seems like it works but it just doesn't last very long and sort of crashes! does any know what's going wrong? Any help will be greatly appreciated.
cheers