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.