How to Send Data from Arduino to Other Arduino using ESP8266-01?

I have this code, and I would like to send the serial data (sensor output) to another arduino uno using ESP8266-01 as client-server (Peer to Peer communication). Can help me? thank you

#include <Wire.h>
#include "MAX30105.h"

#include "heartRate.h"

MAX30105 particleSensor;

const byte RATE_SIZE = 4;
byte rates[RATE_SIZE];
byte rateSpot = 0;
long lastBeat = 0;

float beatsPerMinute;
int beatAvg;

void setup()
{
  Serial.begin(115200);
  Serial.println("Initializing...");

  // Initialize sensor
  if (!particleSensor.begin(Wire, I2C_SPEED_FAST))
  {
    Serial.println("MAX30105 was not found. Please check wiring/power. ");
    while (1);
  }
  Serial.println("Place your index finger on the sensor with steady pressure.");

  particleSensor.setup(); 
  particleSensor.setPulseAmplitudeRed(0x0A); 
  particleSensor.setPulseAmplitudeGreen(0); 
}

void loop()
{
  long irValue = particleSensor.getIR();

  if (checkForBeat(irValue) == true)
  {
    //We sensed a beat!
    long delta = millis() - lastBeat;
    lastBeat = millis();

    beatsPerMinute = 60 / (delta / 1000.0);

    if (beatsPerMinute < 255 && beatsPerMinute > 20)
    {
      rates[rateSpot++] = (byte)beatsPerMinute;
      rateSpot %= RATE_SIZE;

     
      beatAvg = 0;
      for (byte x = 0 ; x < RATE_SIZE ; x++)
        beatAvg += rates[x];
      beatAvg /= RATE_SIZE;
    }
  }

  Serial.print("IR=");
  Serial.print(irValue);
  Serial.print(", BPM=");
  Serial.print(beatsPerMinute);
  Serial.print(", Avg BPM=");
  Serial.print(beatAvg);

  if (irValue < 50000)
    Serial.print(" No finger?");

  Serial.println();
}

{Please use the code tags button, </> on the menu, for future posts. Thanks, Moderator}

Why do you need the Arduino at all?
Write the program in the Arduino IDE for your ESP
and connect the sensor to the ESP
Leave away the Arduino UNO.

The ESP01 is somehow cumbersome for beginners.
Organize makerfriendly NodeMCU or Wemos D1 and program them with the Arduino IDE.

Reduce complexity!

You may like to consider using ESP-NOW rather than WiFi

...R

noiasca:
Why do you need the Arduino at all?
Write the program in the Arduino IDE for your ESP
and connect the sensor to the ESP
Leave away the Arduino UNO.

The ESP01 is somehow cumbersome for beginners.
Organize makerfriendly NodeMCU or Wemos D1 and program them with the Arduino IDE.

Reduce complexity!

thanks for the respone.
because, that's what my teacher ask me to do..I've to solve this problem..can you help me?

No.
The ESP is a microcontroller with far more capabilities than the Arduino. It makes no sense in real world to read a single sensor with the Arduino and let the ESP just do the communication.
The Arduino is useless in that usecase.
Come up with a solution without the Arduino.

noiasca:
The ESP is a microcontroller with far more capabilities than the Arduino. It makes no sense in real world to read a single sensor with the Arduino and let the ESP just do the communication.
The Arduino is useless in that usecase.

All that is true.

But if the student has been tasked with using a pair of Arduinos coupled with ESP8266-01s then it is not really relevant.

It is perfectly possible to use the ESP8266s as communication devices for the Arduinos. I have experimented with them in the past but I can't remember the details now.

I guess it's an option for the student to ask the teacher to change the terms of the assignment - might even be a good idea, but might be outside the teacher's comfort zone.

...R

But if the student has been tasked with using a pair of Arduinos coupled with ESP8266-01s then it is not really relevant.

Who knows? May be the teacher wants the student to search for a solution?

It's daily business to convince the client that constraints don't fit to the final target. That they even will cost more time/money/quality on mid term!

Or to cite Forrest Gump: dumb is as dumb does.

noiasca:
Who knows? May be the teacher wants the student to search for a solution?

It's daily business to convince the client that constraints don't fit to the final target. That they even will cost more time/money/quality on mid term!

Or to cite Forrest Gump: dumb is as dumb does.

I agree with that, especially about educating the client.

But it is (IMHO) very harsh to categorize a student as dumb because they are trying to implement a teacher's assignment.

And (look on the bright side), having implemented the assignment the student should better appreciate the advantage of just using the ESP8266 directly :slight_smile:

...R

For bi directional communications with the ESP8266 and the Uno you will have to use a software serial library.

There is a good write up on this site about using serial as a way of MCU to MCU communications.

noiasca:
No.
The ESP is a microcontroller with far more capabilities than the Arduino. It makes no sense in real world to read a single sensor with the Arduino and let the ESP just do the communication.
The Arduino is useless in that usecase.
Come up with a solution without the Arduino.

Actually, I've to add more sensors then, it's placed close together. And it's more efficence if I read all sensors data and collect it first in Arduino uno or mega than using so many ESP module. And then send all data using ESP8266-01 to another devices that placed in different room. I'm sorry first, I thought my question is representative but it's not. Because I'm a newbie here. Thank you

if you fear to run out of inputs, I suspect you haven't followed my links. The NodeMCU and the Wemos have fare more GPIOs than the ESP01. Not as much as an Uno, but there is another solution.
If you need more GPIOs than you have available on the NodeMCU/Wemos use I2C portexpanders.
If you still insist on using the the UNO - you can use it as I2C Slave - but put all logic on the NodeMCU/Wemos.

Idahowalker:
For bi directional communications with the ESP8266 and the Uno you will have to use a software serial library.

There is a good write up on this site about using serial as a way of MCU to MCU communications.

Hello,
Why would you have to use software serial with the esp8266? Any idea what that write-up was called?
Thanks.

If there is only 1 hardware serial port on the ESP8266,no? Perhaps, I'm wrong and will get educated.

Yes I think only one but why not use it?

No reason. My apologies for bothering you.