Pulse Oximeter is not working simultaneously with gps (neo 6m) and accelerometer in esp32

I have a project, in which I am using Pulse oximeter sensor(MAX30100), GPS(NEO-6M), Accelerometer (MPU6050). Here, I am trying to use all three sensors simultaneously and send the data to BLYNK app. This is the code I am using - ( )

#include <TinyGPSPlus.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <Arduino.h>
#include <HardwareSerial.h>

char auth[] = "VUjbOe139IPotsyC2Sjx-MQbB54al9s0";   
float latitude , longitude;
String  lat_str , lng_str;

// For Pulse sensor
PulseOximeter pox;
float BPM, SpO2;
uint32_t tsLastReport = 0;

// For Accelerometer sensor
const int MPU_addr=0x68;
int16_t accelX, accelY, accelZ, gyroX, gyroY, gyroZ;
float gForceX, gForceY, gForceZ,rotX, rotY, rotZ, Tmp;
WiFiClient client;
TinyGPSPlus gps;
HardwareSerial SerialGPS(2);

void onBeatDetected()
{
    Serial.println("Beat Detected!");
}

void setup() {
  Serial.begin(115200);

  WiFi.begin("Dhoni Finishes off in Style", "123456789");

  // Wait for wifi to be connected
  uint32_t notConnectedCounter = 0;
  while (WiFi.status() != WL_CONNECTED) {
      delay(100);
      Serial.println("Wifi connecting...");
      notConnectedCounter++;
      if(notConnectedCounter > 50) { // Reset board if not connected after 5s
          Serial.println("Resetting due to Wifi not connecting...");
          ESP.restart();
      }
  }
  Serial.print("Wifi connected, IP address: ");
  Serial.println(WiFi.localIP());
  SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
  
  Blynk.begin(auth,"Dhoni Finishes off in Style", "123456789");
  Serial.println("Initializing Pulse Oximeter..");
 
    if (!pox.begin())
    {
         Serial.println("FAILED");
         for(;;);
    }
    else
    {
         Serial.println("SUCCESS");
         pox.setOnBeatDetectedCallback(onBeatDetected);
    }
 
    // The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
        pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
        
  Wire.begin(); 
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}

void loop()
{
   
  // Reading data from Accelerometer sensor
  
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  accelX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  accelY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  accelZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();
  gyroX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  gyroY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  gyroZ=Wire.read()<<8|Wire.read();

  gForceX = (accelX-2050) / 16384.0;
  gForceY = (accelY-77) / 16384.0; 
  gForceZ = (accelZ-1947) / 16384.0;

  rotX = (gyroX+270) / 131.0;
  rotY = (gyroY-351) / 131.0; 
  rotZ = (gyroZ+136) / 131.0;

  // calculating Amplitute vactor for 3 axis
  float Raw_Amp = pow(pow(gForceX,2)+pow(gForceY,2)+pow(gForceZ,2),0.5);
  int Amp = Raw_Amp * 10;  // Mulitiplied by 10 bcz values are between 0 to 1
  int angleChange = pow(pow(rotX,2)+pow(rotY,2)+pow(rotZ,2),0.5);

  // Reading data from pulseoximeter sensor
  pox.update();
  BPM = pox.getHeartRate();
  SpO2 = pox.getSpO2();
  
   if (SerialGPS.available() > 0) {
    if (gps.encode(SerialGPS.read()))
    {
      if (gps.location.isValid())
      {
        latitude = gps.location.lat();
        lat_str = String(latitude , 6);
        longitude = gps.location.lng();
        lng_str = String(longitude , 6);
      }
    }
  }

  // Uploading data to Blynk server AND printing data on serial monitor
  if (millis() - tsLastReport > REPORTING_PERIOD_MS)
    {
      Blynk.run();
      
      Blynk.virtualWrite(V3, BPM);
      Blynk.virtualWrite(V4, SpO2);
      

      Serial.println(Amp);
      Serial.println(angleChange);

      Serial.print("Heart rate:");
      Serial.print(BPM);
      Serial.print(" bpm / SpO2:");
      Serial.print(SpO2);
      Serial.println(" %");
      
      Serial.print("Latitude = ");
        Serial.println(lat_str);
        Serial.print("Longitude = ");
        Serial.println(lng_str);
        //Blynk.virtualWrite(V0, 1, latitude, longitude, "Location");

      tsLastReport = millis();
    }
}

It works completely fine. But when I'm trying to send gps coordinates to blynk app then pulse sensor stops working. i.e. -

Blynk.virtualWrite(V0, 1, latitude, longitude, "Location");

Can you point out what's wrong with the program.

Do not cross-post. Other thread removed.

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