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
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