ultrasonic sensor with temp inbuilt

i have two ultrasonic sensors and the code is working fine individually and now i want want to use both at same time using arduino uno i tried a code but it only gives sensor 2 values and doesnt give value of sensor 1

this the code i used for both to work at same time
#include<SoftwareSerial.h>
SoftwareSerial myserial(2,3);
SoftwareSerial myserial1(4,5);
char data;
char data1;
int finish=0;
int complt=0;
int i=0;
int j=0;
char a[15];
char b[15];

void setup() {
Serial.begin(9600);
myserial.begin(9600);
myserial1.begin(9600);

}

void loop()
{
sensor();
sensor1();
if(finish=1, complt=1)
{
Serial.print(“depth1:”);
Serial.print(a);
Serial.println("*C");
Serial.print(“depth2:”);
Serial.print(b);
Serial.println("*C");
finish=0;
complt=0;
i=0;
j=0;
}

}

void sensor()
{
while(myserial.available()>0)
{
data= myserial.read();
if(data !=0x0D && finish==0)
{
a[i++]=data;
}
if(data==0x0D)
{
finish=1;
}
}
}

void sensor1()
{
while(myserial1.available()>0)
{
data1= myserial1.read();
if(data1 !=0x0C && complt==0)
{
b[j++]=data1;
}
if(data1==0x0C )
{
complt=1;
}
}
}

where did i go wrong… can anyone help?

  if(finish=1, complt=1)

I don't know what that does but I'll bet it's not what you think.

If else reference. Note that = is for assignment and == is for comparison.

Correct syntax is like:

if(finish == 1 && complt == 1);  // and comparison
or
if(finish == 1 || complt == 1);  // or comparison

You need to be careful using 2 instances of software serial. Only 1 instance can listen at a time and the software must choose which one is to listen. If you need that many serial ports a Mega board would be a good choice as it has 4 hardware serial ports.

Please read the "how to use the forum-please read" stickies to see how to post code properly.

thank you.
cant we use uno board to get values from 2 sensors at a time and also interface it with gprs shield???

I have no experience with a GPRS shield, but it looks like it requires a serial port. That would be at least 3 serial ports (plus 1 for program upload and debug). While it may be possible to run 3 software serial ports on an Uno, I cannot see it being practical. Here is a tutorial on using 2 soft serial ports on an Uno that shows how to switch between soft serial ports. Maybe you can extend this to 3 ports, I don't know.

You could use hardware serial for the GPRS and soft serial for the sensors, but that would require disconnecting the GPRS shield to upload code and you would have no serial port for debug prints.

Bottom line, get a controller board with more hardware ports. Like a Mega.