How to increase serial data quality?

I am trying to build a system which basically detects the position of a transmitter on a 2D plane.
I am using 3 Hc-SR04 modules with 3 Arduino Unos. One of them sends the sound. A second one reads data from 2 HC-Sr04(their transmitters are covered) and sends to a third one. Third one sends the data to PC.

I will use this system on a kind of robot, so the third one represents the main board of this system.

The issue is, I get different values when I use Serial communication with the third one and get the data from third, or get the data directly from the second one

All I use is SoftwareSerial with 2 pieces of jumper cables. And I only change between Serial.print() or
[whateverthenamewrites]Serial.print()

Reducing the number of Serial.print functions seems helping, and also Increasing Baud rate, but I simply could not go any further.

So, any idea is helpful :slight_smile:

Thanks...

Further explanation down (Con provide better explanation if necessary)

Code for the transmitter(first)

void setup() {
 pinMode(6, OUTPUT);
 pinMode(5, INPUT);

}

void loop() {
digitalWrite(6, LOW);
digitalWrite(6, HIGH);
delayMicroseconds(1);
digitalWrite(6, LOW);
delayMicroseconds(5);
}

Code for receiver(second)

#include <SoftwareSerial.h>
SoftwareSerial ALTSerial(9, 10);
void setup() {
 pinMode(5, INPUT);
 pinMode(11, INPUT);
 pinMode(6, OUTPUT);
 pinMode(12, OUTPUT);
 Serial.begin(115200);
 ALTSerial.begin(115200);
 long duration, distance;
  digitalWrite(6, LOW);
  delayMicroseconds(2);
  digitalWrite(6, HIGH);
  delayMicroseconds(10);
  digitalWrite(6, LOW);
  duration=pulseIn(5, HIGH, 20000);
ALTSerial.println("basla");
}
long mesafe()
{
  long duration3, distance3;
  digitalWrite(6, LOW);
  digitalWrite(6, HIGH);
  digitalWrite(6, LOW);
  duration3=pulseIn(5, HIGH);
  distance3=duration3/58.2;
  ALTSerial.print(distance3);
  ALTSerial.print("  ");
  }
 long mesafe2()
{
  long duration2, distance2;
  digitalWrite(12, LOW);
  digitalWrite(12, HIGH);
  digitalWrite(12, LOW);
  duration2=pulseIn(11, HIGH);
  distance2=duration2/58.2;
  ALTSerial.println(distance2);
  } 
  int sayac=1;
  unsigned long timmes;
void loop() {

 mesafe();
 mesafe2(); 


}

If I want to get data from this one, I just change ALTSerial.println(); to Serial.println();

Code for the third one

#include <SoftwareSerial.h>
SoftwareSerial ALTSerial(5, 6);
void setup() {
Serial.begin(115200);
ALTSerial.begin(115200);
}
char c;
void loop() {
if(ALTSerial.available())
{
  c=ALTSerial.read();
  Serial.write(c);
  }

}

A photo describing the idea
https://postimg.org/image/xuayfml3x

You are aware that pulseIn is a blocking function. So probably only one of the two sensors will pick up the signal.

All I use is SoftwareSerial with 2 pieces of jumper cables.

Connecting what to what? Is one of them the GND? If not, add a third jumper cable to connect the grounds of Uno 2 and Uno 3

What you want to do is incomprehensible, but what ever it is, this

ALTSerial.begin(115200);

is surely the kiss of death for it. The most you can expect from software serial is 38400, and 19200 is a safer bet.

sterretje:
You are aware that pulseIn is a blocking function. So probably only one of the two sensors will pick up the signal.
Connecting what to what? Is one of them the GND? If not, add a third jumper cable to connect the grounds of Uno 2 and Uno 3

It just reads data from both receivers, one by one. So, I tried to make it working on the same period with the transmitter. Once it catchs the signal, it keeps the same period.

I missed GND, thanks for this info

Nick_Pyner:
What you want to do is incomprehensible, but what ever it is, this

ALTSerial.begin(115200);

is surely the kiss of death for it. The most you can expect from software serial is 38400, and 19200 is a safer bet.

So, thansmission speed is a factor which disturbs the data?

"disturbs the data" is putting it too kindly. It not only completely stuffs it up but software serial at any speed also slows down your Arduino, and thereby may cause grief in other parts of your project. I have no idea of what you are doing, or even why you have so many Arduinos. It is not even clear to me that you need software serial, or that your code is complete, but

  1. If you slow down software serial, it might work OK
  2. If you really need fast serial, you would be better off with a Mega, which has four hardware serial ports.

Nick_Pyner:
"disturbs the data" is putting it too kindly. It not only completely stuffs it up but software serial at any speed also slows down your Arduino, and thereby may cause grief in other parts of your project. I have no idea of what you are doing, or even why you have so many Arduinos. It is not even clear to me that you need software serial, or that your code is complete, but

  1. If you slow down software serial, it might work OK
  2. If you really need fast serial, you would be better off with a Mega, which has four hardware serial ports.

What if I use 12C instead of SoftwareSerial? Or if there is any other type of communication?

I understand the other buses are only good for very short distances.

I think you should re-examine the whole thing and be more clear about your intentions. I have no idea of what you are trying to do, but I know junk code when I see it, and that is what your second set of code is. It is not even clear why you have posted it but , as it is, it calls for hardware serial to start at 115200 but has no hardware serial commands - just software serial ones that won't work.