GPS Neo 6m and Pulse sensor not working together

Hi everyone

I am doing a project where I need to get the location and bpm(beats per minute) of a person. I am using the GPS Neo 6m and a pulse sensor.

I am having some problems in the code. When I run it, everything starts working correctly. I call the GPS function and get the data, then I call the PulseSensor function and everything run perfect. The problem is when I try to call the GPS function again, it doesn't show me the data, when firstly it was working very well.

I believe the problem is in the pulseSensor.begin();. Because when the code pass through this line, it starts the "library" and the GPS stops working. I tried initializing the GPS again in the loop but it doesn't work.

Hope you guys can help me.

Sorry for my bad english, it is not my native language.

This is my code

#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.  

TinyGPS gps;//Declaramos el objeto gps
SoftwareSerial serialgps(4,3);//Declaramos el pin 4 Tx y 3 Rx
//Declaramos la variables para la obtención de datos
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int x=0, y=0;

//  Variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
                              // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                              // Otherwise leave the default "550" value. 
                              
PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup()
{
/pinMode(7,OUTPUT);
Serial.begin(115200);//Iniciamos el puerto serie
serialgps.begin(9600);//Iniciamos el puerto serie del gps
Serial.println("Inicio de Programa\nIngresa un 1 para acceder al GPS\nIngresa un 2 para acceder al Sensor de pulso\nIngresa 3 para no realizar ninguna accion\n\n");

// Configure the PulseSensor object, by assigning our variables to it. 
 pulseSensor.analogInput(PulseWire);   
 pulseSensor.setThreshold(Threshold);      
}

void loop()
{
  x=Serial.read();
 //Serial.println(y);
 if(x==49)
 {
   y=x;
   digitalWrite(7, LOW);
   Serial.println(" GPS\n---Buscando senal--- ");
  }
   else if(x==50){
   y=x;
   digitalWrite(7, HIGH);
   Serial.println("Sensor de Pulso\nObteniendo Datos\n");}
   else if(x==48)
   y=x;
   
 switch (y)
 {
   case 49: localizar(); break;
   case 50: pulso(); break;
 }
}

void localizar()
{
 serialgps.begin(9600);//Iniciamos el puerto serie del gps
 while(serialgps.available()) 
{
int c = serialgps.read(); 
if(gps.encode(c)) 
{
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
Serial.print("Latitud/Longitud: "); 
Serial.print(latitude,5); 
Serial.print(", "); 
Serial.println(longitude,5);
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
Serial.print("Fecha: "); Serial.print(day, DEC); Serial.print("/"); 
Serial.print(month, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Hora: "); Serial.print(hour, DEC); Serial.print(":"); 
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
Serial.print("."); Serial.println(hundredths, DEC); 
Serial.print("Velocidad(kmph): "); Serial.println(gps.f_speed_kmph());
Serial.println();
gps.stats(&chars, &sentences, &failed_checksum);
}
}
}

void pulso()
{
pulseSensor.begin();
int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
                                              // "myBPM" hold this BPM value now. 

if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened". 
Serial.println("♥  A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: ");                        // Print phrase "BPM: " 
Serial.println(myBPM);                        // Print the value inside of myBPM. 
}
 delay(20);                    // considered best practice in a simple sketch.
}

Maybe here:
~~ x=Serial.read();~~
~~ //Serial.println(y);~~
~~ if(x==49)~~
Look at parseint()

Edit:
The above is OK. It looks like you are getting the ASCII values of 0,1&2 in your code, not an arbitrary integer as I originally thought.

  1. It is not clear what is on pin 7 and it looks like you have half commented out the pinMode() statement for it. I guess LOW enables the GPS device but it may require time to lock back on before it is readable.

  2. I'm not sure how Software Serial reacts to multiple begin() calls without a matching end() call. Why do you do this on each function call and not simply once in setup() :

serialgps.begin(9600);//Iniciamos el puerto serie del gps
  1. Maybe you should post a wiring diagram to make things clearer.

  2. Maybe try setting this to false:

#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.

5. Maybe you should put your code in code tags so we can read it.

Modify your post. Select "More" in the lower right corner of your post and select "Modify...". Then insert code tags before and after your code, like this:

```
**[code]#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>    // Includes the PulseSensorPlayground Library.

TinyGPS gps;//Declaramos el objeto gps
  ...
[/code]**
```

When you press Preview, it shows you the white code block. It will look like this:

#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.  

TinyGPS gps;//Declaramos el objeto gps
  ...

Press "Save" to update your post.

Always put your sketch in between those two tags,
** **[code]** **
and
** **[/code]** **
. This preserves the original code when we see it and makes it easier for us to copy it. This is described in How to use the forum. Read it.

6. Make sure the code you post will compile.

This will not compile:

void setup()
{
/pinMode(7,OUTPUT);

If you are asking about a compile error, show us the error messages. Copy the error messages from the IDE window and copy them into your post. USE CODE TAGS around the error messages. This is described in How to use the forum.

I also suggest that you indent your code. It will make your code easier to read and debug. Just press control-T in the IDE editor, and it will format your code for you.

7. The main problem is this:

void localizar()
{
  serialgps.begin(9600);//Iniciamos el puerto serie del gps
  while(serialgps.available()) 
{
int c = serialgps.read();

Everytime you call begin, it empties the Arduino receive buffer. If there were any GPS characters in that buffer, they will be discarded. Then, serialgps.available() will never be true, and you will never (or rarely) read any GPS characters.

Instead, you should call begin just once, in setup. Then you should constantly check for GPS characters in loop. If you don't keep reading them, the Arduino will eventually start ignoring them. Let the sketch constantly parse the characters to decode GPS data fields. Don't print the fields until the user enters the '1' command.

8. This works, but is not recommended:

void loop()
{
   x=Serial.read();
  //Serial.println(y);
  if(x==49)

You should always test Serial.available before calling Serial.read(). Serial.read() returns -1 if no characters are available. Your code only checks for '1' (ASCII 49) and '2' (ASCII 50), so your code ignores the -1 values.

9. Don't use SoftwareSerial. It is very inefficient, because it disables interrupts for long periods of time. This will interfere with other parts of your sketch, or with libraries like PulseSensor. I seriously doubt that these two libraries can coexist.

3. AGAIN, Post a wiring diagram

Because you didn't tell us which Arduino you are using, nor how the pieces are connected, I do not know what serial library to suggest for your system. This is described in How to use the forum.

If you have a Mega, Leo or Micro, use Serial1 instead of SoftwareSerial.

For other Arduinos, I would normally suggest using AltSoftSerial on the two pins it requires (8 & 9 on an UNO). Unfortunately, the PulseSensor library conflicts with the AltSoftSerial library, so you will have to use NeoSWSerial.

If NeoSWSerial doesn't work (it also uses interrupts), you will have to put the GPS device on Serial, pin 0 (required to receive GPS data) and pin 1 (optional, only needed if you send configuration commands to the GPS RX pin). Read more here about choosing and connecting the GPS device.

That page is from my NeoGPS library. It is smaller, faster, more reliable and more accurate than all other GPS libraries. Here is your sketch, modified to use AltSoftSerial and NeoGPS, along with the suggestions above, IN CODE TAGS:

#include <NeoSWSerial.h>
#include <NMEAGPS.h>

#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.

NMEAGPS gps;//Declaramos el objeto gps
gps_fix fix;

NeoSWSerial serialgps( 4, 3 ); // pin 4 to GPS Tx y 3 to GPS Rx


//  Variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
                               // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                               // Otherwise leave the default "550" value.

PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup()
{
  pinMode(7,OUTPUT);
  serialgps.begin(9600);//Iniciamos el puerto serie del gps
  Serial.begin(115200);//Iniciamos el puerto serie
  Serial.println( F("Inicio de Programa\nIngresa un 1 para acceder al GPS\nIngresa un 2 para acceder al Sensor de pulso\nIngresa 3 para no realizar ninguna accion\n\n") );

// Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.setThreshold(Threshold);
}

void loop()
{
  // Constantly read GPS characters.
  if(gps.available( serialgps ))
  {
    // Save new GPS data when it is available, once per second.
    fix = gps.read();
  }

  // Check for a command
  if (Serial.available()) {
    char c=Serial.read();
    //Serial.println(c);

    switch (c) {
      case '1':
        digitalWrite(7, LOW);
        Serial.println( F(" GPS\n---Buscando senal--- ") );
        localizar();
        break;

      case '2':
        digitalWrite(7, HIGH);
        Serial.println( F("Sensor de Pulso\nObteniendo Datos\n") );
        pulso();
        break;

      default:
        break;
    }
  }
}

void localizar()
{
  // Print the current GPS data fields

  Serial.print( F("Latitud/Longitud: ") );
  if (fix.valid.location) {
    Serial.print( fix.latitude(),5 );
    Serial.print(", ");
    Serial.print( fix.longitude(),5);
  }
  Serial.println();

  Serial.print( F("Fecha: ") );
  if (fix.valid.date) {
    Serial.print(fix.dateTime.date); Serial.print("/");
    Serial.print(fix.dateTime.month); Serial.print("/");
    Serial.print(fix.dateTime.year);
  }
  Serial.println();

  Serial.print( F("Hora: ") );
  if (fix.valid.time) {
    Serial.print(fix.dateTime.hours); Serial.print(":");
    Serial.print(fix.dateTime.minutes); Serial.print(":");
    Serial.print(fix.dateTime.seconds);
    if (fix.dateTime_cs < 10)
      Serial.print( '0' ); // leading zero when .04 hundredths
    Serial.print('.');
    Serial.print(fix.dateTime_cs);
  }
  Serial.println();

  Serial.print( F("Velocidad(kmph): ") );
  if (fix.valid.speed)
    Serial.print(fix.speed_kph());
  Serial.println();

  Serial.println();
}


void pulso()
{
  pulseSensor.begin();
  int myBPM = pulseSensor.getBeatsPerMinute();

  if (pulseSensor.sawStartOfBeat()) {
    Serial.println( F("♥  A HeartBeat Happened ! ") );
    Serial.print("BPM: ");
    Serial.println(myBPM);
  }
}

If you want to try it, NeoSWSerial and NeoGPS are available from the IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

Cheers,
/dev

1 Like

I will upload my code again with some corrections and I translate the comments to english for you guys, so you can read it easily.

I'm using an Arduino UNO for the record

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>      

TinyGPS gps;//
SoftwareSerial serialgps(4,3);  // pin 4 to GPS Tx y 3 to GPS Rx

int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;
int x=0, y=0;

const int PulseWire = 0;       // PulseSensor connected to ANALOG PIN 0
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
                               // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                               // Otherwise leave the default "550" value. 
                               
PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup()
{
pinMode(7,OUTPUT); //Pulse sensor voltage wire connected to pin 7
Serial.begin(115200);
serialgps.begin(9600);   //GPS serial port begins
Serial.println("Inicio de Programa\nIngresa un 1 para acceder al GPS\nIngresa un 2 para acceder al Sensor de pulso\n\n");
              // Program initialized\n Type 1 to access GPS\n Type 2 to access Pulse Sensor \n Type 3 to do nothing

              
// Configure the PulseSensor object, by assigning our variables to it. 
  pulseSensor.analogInput(PulseWire);   
  pulseSensor.setThreshold(Threshold);      
}

void loop()
{
   x=Serial.read();
  //Serial.println(y);
  if(x==49)  // In this case 1=49
  {
    y=x;
    digitalWrite(7, LOW); //We set pin 7 to low so the Pulse Sensor dont consume energy
    Serial.println(" GPS\n---Buscando senal--- ");
   }
    else if(x==50){  //2=50
    y=x;
    digitalWrite(7, HIGH); // Pin 7 to High only when we access to Pulse Sensor Function
    Serial.println("Sensor de Pulso\nObteniendo Datos\n");}
    else if(x==48) // 3 = 48
    y=x;
    
  switch (y)
  {
    case 49: localizar(); break; //GPS function begins  
    case 50: pulso(); break; // Pulse Sensor function begins
  }
}

void localizar()
{
  while(serialgps.available())   //Code to get GPS data from TinyGPS library
{
int c = serialgps.read(); 
if(gps.encode(c)) 
{
float latitude, longitude;
gps.f_get_position(&latitude, &longitude);
Serial.print("Latitud/Longitud: "); 
Serial.print(latitude,5); 
Serial.print(", "); 
Serial.println(longitude,5);
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
Serial.print("Fecha: "); Serial.print(day, DEC); Serial.print("/"); 
Serial.print(month, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Hora: "); Serial.print(hour, DEC); Serial.print(":"); 
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); 
Serial.print("."); Serial.println(hundredths, DEC); 
Serial.print("Velocidad(kmph): "); Serial.println(gps.f_speed_kmph());
Serial.println();
gps.stats(&chars, &sentences, &failed_checksum);
}
}
}

void pulso()
{
 pulseSensor.begin();
 int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
                                               // "myBPM" hold this BPM value now. 

if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened". 
 Serial.println("♥  A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
 Serial.print("BPM: ");                        // Print phrase "BPM: " 
 Serial.println(myBPM);                        // Print the value inside of myBPM. 
}
  delay(20);                    // considered best practice in a simple sketch.
}

I will try all the changes you guys told me, then I'll tell you if they work

Thanks.

My program is working!!!

I use the code you upload and now it is working pretty well. I just do some small changes in the loop.

void loop()
{
  x=Serial.read();
 //Serial.println(y);
 if(x==49)

As you said this is not recommended but I need it this way so it keeps calling the function until another number is written in the serial. So it can look like it is in a loop.

It seems that the error were the ones you told me /Dev

-dev:
The main problem is this:[/b]

Everytime you call begin, it empties the Arduino receive buffer. If there were any GPS characters in that buffer, they will be discarded. Then, serialgps.available() will never be true, and you will never (or rarely) read any GPS characters.

Instead, you should call begin just once, in setup. Then you should constantly check for GPS characters in loop. If you don't keep reading them, the Arduino will eventually start ignoring them. Let the sketch constantly parse the characters to decode GPS data fields. Don't print the fields until the user enters the '1' command.

And also this one

-dev:
Don't use SoftwareSerial. It is very inefficient, because it disables interrupts for long periods of time. This will interfere with other parts of your sketch, or with libraries like PulseSensor. I seriously doubt that these two libraries can coexist.

I will upload my final code if someone needs help one day

#include <NeoSWSerial.h>
#include <NMEAGPS.h>

#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.

NMEAGPS gps;//Declaramos el objeto gps
gps_fix fix;

NeoSWSerial serialgps( 4, 3 ); // pin 4 to GPS Tx y 3 to GPS Rx

int x, y;  //To save value written on serial monitor
//  Variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
                               // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                               // Otherwise leave the default "550" value.

PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup()
{
  pinMode(7,OUTPUT); //Pulse sensor voltage wire connected to pin 7
  serialgps.begin(9600);//GPS serial port begins
  Serial.begin(115200);//Serial Initialized
  Serial.println( F("Inicio de Programa\nIngresa un 1 para acceder al GPS\nIngresa un 2 para acceder al Sensor de pulso\nIngresa 3 para no realizar ninguna accion\n\n") );
                    // Program initialized\n Type 1 to access GPS\n Type 2 to access Pulse Sensor \n Type 3 to do nothing

// Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.setThreshold(Threshold);
}

void loop()
{
  // Constantly read GPS characters.
  if(gps.available( serialgps ))
  {
    // Save new GPS data when it is available, once per second.
    fix = gps.read();
    Serial.println("New data");
  }

  // Check for a command
  //To acces the functions just one time when you type a number
  /*if (Serial.available()) {  
    char c=Serial.read();
    //Serial.println(c);

    switch (c) {
      case '1':
        digitalWrite(7, LOW);
        Serial.println( F(" GPS\n---Buscando senal--- ") ); //GPS\m Searching for signal
        localizar();
        break;

      case '2':
        digitalWrite(7, HIGH);
        Serial.println( F("Sensor de Pulso\nObteniendo Datos\n") ); //Pulse Sensor/n Obtaining data
        pulso();
        break;

      default:
        break;
    }
  }*/ 
  
  //Keep in the loop until another number is written
  x=Serial.read();
  //Serial.println(y);
  if(x==49)   // In this case 1=49
  {
    y=x;
    digitalWrite(7, LOW); //We set pin 7 to low so the Pulse Sensor dont consume energy
    Serial.println(" GPS\n---Buscando senal--- ");   //GPS\m Searching for signal
   }
    else if(x==50){ //2=50
    y=x;
    digitalWrite(7, HIGH);  // Pin 7 to High only when we access to Pulse Sensor Function
    Serial.println("Sensor de Pulso\nObteniendo Datos\n");}   //Pulse Sensor/n Obtaining data
    else if(x==48) // 3 = 48
    y=x;
    
  switch (y)
  {
    case 49: localizar();break; //GPS function begins  
    case 50: pulso();break; // Pulse Sensor function begins
  }
}

void localizar()
{
  // Print the current GPS data fields

  Serial.print( F("Latitud/Longitud: ") );
  if (fix.valid.location) {
    Serial.print( fix.latitude(),5 );
    Serial.print(", ");
    Serial.print( fix.longitude(),5);
  }
  Serial.println();

  Serial.print( F("Fecha: ") );
  if (fix.valid.date) {
    Serial.print(fix.dateTime.date); Serial.print("/");
    Serial.print(fix.dateTime.month); Serial.print("/");
    Serial.print(fix.dateTime.year);
  }
  Serial.println();

  Serial.print( F("Hora: ") );
  if (fix.valid.time) {
    Serial.print(fix.dateTime.hours); Serial.print(":");
    Serial.print(fix.dateTime.minutes); Serial.print(":");
    Serial.print(fix.dateTime.seconds);
    if (fix.dateTime_cs < 10)
      Serial.print( '0' ); // leading zero when .04 hundredths
    Serial.print('.');
    Serial.print(fix.dateTime_cs);
  }
  Serial.println();

  Serial.print( F("Velocidad(kmph): ") );
  if (fix.valid.speed)
    Serial.print(fix.speed_kph());
  Serial.println();

  Serial.println();
  delay(1000);
}


void pulso()
{
  pulseSensor.begin();
  int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
                                               // "myBPM" hold this BPM value now. 

  if (pulseSensor.sawStartOfBeat()) {    // Constantly test to see if "a beat happened".
    Serial.println( F("♥  A HeartBeat Happened ! ") );   // If test is "true", print a message "a heartbeat happened".
    Serial.print("BPM: ");   // Print phrase "BPM: " 
    Serial.println(myBPM);     // Print the value inside of myBPM.
  }
}

And also a wiring diagram

Thank you guys!!!

this code not working for me

(Please use code tags, the </> button above. Thanks, Moderator)

////////////////////////////LIBRARIES//////////////////////////////////////////////////////////////////

#define USE_ARDUINO_INTERRUPTS false              //pulse sensor playground library use this intrerupts and we need it to make it fals in order to be sure that we will not use intrerupts
#include <PulseSensorPlayground.h>                //Pulse Sensor library
#include <TinyGPS++.h>                            //GPS library
#include <SoftwareSerial.h>                       //this library allow to use not dedicated pins for serial comunication,create a sw serial communication 

////////////////////////////VARIABLES//////////////////////////////////////////////////////////////////
//////////////////////LM35_Temperature_sensor///////////////////////////////////////////////////////////

const int LM35_sensor_output = A1;                //assigning analog pin A1 to variable 'LM35_sensor_output'
float temp;                                       //variable for temperature in Celsius
float vout;                                       //temporary variable to hold sensor digital reading
int contor_apelare = 0;

//////////////////////Pulse_sensor_Variables///////////////////////////////////////////////////////////

int Beat_per_minutes = 0;                         //variable for pulse
const int OUTPUT_TYPE = SERIAL_PLOTTER;           //the format of our pulse sensor output, choseed by us to being a serial monitor output0 (not mandatory in our program)

const int Pulse_sensor_output = A0;               //analog Input. Connected to the pulse sensor output
const int treshhold = 550;                        //the trashhold used to helping us reading the pulse waves (heart beat moments)

byte samplesUntilReport;                          //the number of samples remaining to read until we want to report a sample over the serial connection.
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;        //after 10 samples measurment we will calculate the Pulse

//////////////////////////GPS_Variables/////////////////////////////////////////////////////////////////

double latidude = 0;                              //variable for latitude
double longitude = 0;                             //variable for longitude
int years, mounth,days;                           //variables for date
int hours,minutes,seconds;                        //variables for time
static const uint32_t GPSBaud = 9600;             //define the GPS baudrate for serial communication
static const int RXPin = 9, TXPin = 8;            //asign of the rx and tx pins to the variables RXPin,TXPin for our sw serial communication with GPS
SoftwareSerial gps_bus(RXPin, TXPin);             //the serial connection to the GPS sw serial comm

////////////////////////////FUNCTION OBJECT FOR DEDICATED LIBRARY//////////////////////////////////////////////////////////////////

PulseSensorPlayground pulseSensor;                //the object created for pulse library 
TinyGPSPlus GPS;                                  //the object created for GPS library

////////////////////////////COMMUNICATION SETUP AND OTHERS SETUP//////////////////////////////////////////////////////////////////

void setup() 
{
 pinMode(LM35_sensor_output,INPUT);              // configuring pin A1 as input
 Serial.begin(9600);                             //sets the data rate in bits per second (baud) for serial monitor communication         
 gps_bus.begin(GPSBaud);                         //sets the data rate in bits per second (baud) for sw serial communication with GPS   
 
 // Configure the PulseSensor manager.
 pulseSensor.analogInput(Pulse_sensor_output);   //assignation of the variable to the analog pin(A0) of arduino
 pulseSensor.setSerial(Serial);                  //set the serial monitor to output data
 pulseSensor.setOutputType(OUTPUT_TYPE);         //set the output type (not mandatory for us)
 pulseSensor.setThreshold(treshhold);            //set the trashhold


 samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE; // Skip the first SAMPLES_PER_SERIAL_SAMPLE in the loop().

 
 if (!pulseSensor.begin())                       // Now that everything is ready, start reading the PulseSensor signal.
 {
   Serial.print("Pulse sensor start reading the pulse");
 }
}

////////////////////////////MAIN FUNCTION//////////////////////////////////////////////////////////////////
void loop()
{
 
 if(contor_apelare == 25)
 {
   vout = analogRead(LM35_sensor_output);
   vout = analogRead(LM35_sensor_output);
   vout = vout * 5 / 1023;
   temp = vout / 0.01; 
   contor_apelare = 0;
 }
 
 if (pulseSensor.sawNewSample()) 
 {
   contor_apelare++;
   if (--samplesUntilReport == (byte) 0) 
   {
     
     samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;

     if (pulseSensor.sawStartOfBeat()) 
     {
       
       Beat_per_minutes = pulseSensor.getBeatsPerMinute();
       Beat_per_minutes = pulseSensor.getBeatsPerMinute();
     }
     
   }

    if (gps_bus.available() > 0)               // check for gps data on the serial comm
     {
       GPS.encode(gps_bus.read());                 // encode gps data
       if (GPS.location.isUpdated())
       {
   ///////////////////LOCATION//////////////////
         // Latitude in degrees (double)
         latidude = GPS.location.lat();
         Serial.print("Latitude = "); 
         Serial.print(latidude, 6); 
             
         // Longitude in degrees (double)
         longitude = GPS.location.lng();
         Serial.print(" Longitude = "); 
         Serial.println(longitude, 6);
         
  ///////////////////DATE//////////////////////
         // Year (2000+) (u16)
         years = GPS.date.year();
         Serial.print("Year = "); 
         Serial.print(years); 
         
         // Month (1-12) (u8)
         mounth = GPS.date.month();
         Serial.print("  Month = "); 
         Serial.print(mounth); 
         
         // Day (1-31) (u8) 
         days = GPS.date.day();
         Serial.print("  Day = ");
         Serial.println(days); 
         
  /////////////////TIME/////////////////////////
         // Hour (0-23) (u8)
         hours = GPS.time.hour();
         hours = hours + 2;
         Serial.print("Hour = "); 
         Serial.print(hours); 
         
         // Minute (0-59) (u8)
         minutes = GPS.time.minute();
         Serial.print("  Minute = "); 
         Serial.print(minutes); 
         
         // Second (0-59) (u8)
         seconds = GPS.time.second();
         Serial.print("  Second = "); 
         Serial.println(seconds); 

         //Puls
         Serial.print("BPM: ");
         Serial.println(Beat_per_minutes);

         //Temperature
         Serial.print("Temperature = ");
         Serial.print(temp);
         Serial.println(" °C");
         Serial.println(" ");
         
     }
     
    } 

 }     
 
}

This is my code where i used neo 6m module with pulse sensor and lm35 temperature sensor!

The problem of interfacing this 2 devices with arduino, is that the pulse sensor library use interrupts, and if we use a software serial to communicate with the GPS, the interrupt will cause problem to the software communication. So the solution is to use pulse library without interrupts. GPS, lm35 and pulse sensor are supplyed by the arduino 5v.