# Send & receive multiple data from a arduino to another arduino via bluetooth

**URL:** <https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082>\
**Category:** General Guidance\
**Created:** [February 19, 2022, 12:58pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082 "2022-02-19T12:58:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![binukadasunpriya](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@binukadasunpriya](https://forum.arduino.cc/u/binukadasunpriya)\
**Post date:** [February 19, 2022, 12:58pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/1 "2022-02-19T12:58:38Z")

</div>

Hi!, I'm currently building my project using Arduino. I need to send & receive 2 sensor values using 2 HC-05 modules Using **Hardware Serial communication**. there are a Pir & an ultrasonic sensor as the sensors **in the master arduino**. I used **Serial.parseInt();** to receive data to **slave Arduino**. That works good but sometimes my Pir value is 1 in the **slave Arduino** when the master Arduino sends value 0. I think it's my Master Arduino code's fault. But I don't know to fix it. help me!. This is the code below I used for **Master Arduino**.

```cpp
#define trig 7
#define pir_pin 5
#define echo 4
 

String pir_read;

int c;

void setup() {
  /*int memory=EEPROM.read(0);
    distance=memory * 10;*/

  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(pir_pin, INPUT);

  Serial.begin(38400);

}

void loop() {
    digitalWrite(trig, LOW);
    delayMicroseconds(2);
    digitalWrite(trig, HIGH);
    delayMicroseconds(10);
    digitalWrite(trig, LOW);

    int pir = digitalRead(pir_pin);

    long t = pulseIn(echo, HIGH);
    long Cm = t / 29 / 2;

  

    Serial.print("C");
    Serial.println(Cm);
    delay(5);
    Serial.print("\tP");
    Serial.print(pir);
    Serial.print(" ");
    delay(5);

}

```

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 19, 2022, 1:15pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/2 "2022-02-19T13:15:30Z")

</div>

Let the master send a message to the slave to pull of a PIR reading. Then the master stays silent giving the slave the needed time slot do do its sensor reading.

---

<div class="post-metadata">

**Author:** ![binukadasunpriya](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@binukadasunpriya](https://forum.arduino.cc/u/binukadasunpriya)\
**Post date:** [February 19, 2022, 1:28pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/3 "2022-02-19T13:28:58Z")

</div>

I need to receive two values at the same time

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 19, 2022, 1:43pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/4 "2022-02-19T13:43:09Z")

</div>

Then let the master be silent so the slave can collect and send 2 sets of data.

---

<div class="post-metadata">

**Author:** ![binukadasunpriya](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@binukadasunpriya](https://forum.arduino.cc/u/binukadasunpriya)\
**Post date:** [February 19, 2022, 1:46pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/5 "2022-02-19T13:46:44Z")

</div>

the problem is when the master sends Pir value 0, the slave detects it as 1

---

<div class="post-metadata">

**Author:** ![binukadasunpriya](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@binukadasunpriya](https://forum.arduino.cc/u/binukadasunpriya)\
**Post date:** [February 19, 2022, 1:59pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/6 "2022-02-19T13:59:01Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/7/8/678c32afaeed3c7eb5ba2a7433a80e37e90c3cc8.png)

Like this

---

<div class="post-metadata">

**Author:** ![binukadasunpriya](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@binukadasunpriya](https://forum.arduino.cc/u/binukadasunpriya)\
**Post date:** [February 19, 2022, 2:00pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/7 "2022-02-19T14:00:30Z")

</div>

this is the slave code 👇

```cpp
if (Serial.available()) {
    char type = Serial.read();

    if (type == 'C') {
      cm = Serial.parseInt();
      display.clearDisplay();
      display.setCursor(0, 0);
      display.print("Cm: ");
      display.setCursor(10, 0);
      display.print(" ");
      display.print(cm);
      display.print("cm");
      display.display();
    }

    if (type == 'P') {
      pir = Serial.parseInt();
      display.setCursor(0, 30);
      display.print("Human: ");
      display.setCursor(40, 30);
      display.print(" ");
      display.print(pir);
      display.display();
    }

```

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 19, 2022, 2:01pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/8 "2022-02-19T14:01:55Z")

</div>

Post a block drawing of the setup. When the master sends data the slave should **read** that data. You tell **detect**. Too many unknown things to give any more suggestion.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 19, 2022, 5:16pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/9 "2022-02-19T17:16:57Z")

</div>

> [@binukadasunpriya](#):
>
> this is the slave code

No, it's not! It's a cut out. Always post the entire code. All helpers are complete newbies to Your code and need the entire code to get some idea what it tries to do.

If You want to claim You write code then use comments telling what the lines are intended to do. We have no clue. It will be the same for You after time has passed.

That tabell of master and slave output tells nothing so far.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 18, 2022, 5:17pm UTC](https://forum.arduino.cc/t/send-receive-multiple-data-from-a-arduino-to-another-arduino-via-bluetooth/961082/10 "2022-08-18T17:17:29Z")

</div>

Closed on August 18, 2022, 5:17pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
