module using Arduino

Basically , I have implemented a circuit that measures the heartbeat and in order to process the heart signal and display in an LCD, I used Arduino. In addition, I want to use gsm module to send the heart rate (let's say the last 5 reading).

I think I need to save the heart rate measurement in an array and then use it with the gsm send/receive code.

Yes, you do. Once you have an array of 5 values, sprintf() can convert the 5 values to a string, which you can then send using SendMessage().

PaulS:
Yes, you do. Once you have an array of 5 values, sprintf() can convert the 5 values to a string, which you can then send using SendMessage().

The problem is that I don’t have good experience in coding, especially in arrays. However, I will write what I think I correct and please if you can validate my code , I will appreciate very much.

The Send/Recieve code after modification

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);
void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor  (Arduino)
delay(100);
}


void loop()
{
if (Serial.available()>0)
  switch(Serial.read())
  {
    case 's':
      SendMessage();
     break;
    case 'r':
      RecieveMessage();
      break;
  }

 if (mySerial.available()>0)
   Serial.write(mySerial.read());
}


 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
  delay(1000);
  **mySerial.println("sprintf(HPM)");// The SMS text you want to send**
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
   }


void RecieveMessage()
 {
    mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
    delay(1000);
   }

The Heartbeat Code after modification

nt LED = 13; //LED to blink when pulsing
        int din = 2; // digital pin 2 to read 0V or 5V
        int check; // checks current status of digital pin 2
        int prevcheck;// previous check status
        int pulsecount = 0; //number of pulses (highs) seen on the digital pin
         int BPM = 0; //beats perminute = counter value * 10
        int totalBeats = 5;  
        int []BPMA = new int[totalBeats]; //BPM[]: Is the Beat Per Minute (BPM) array - to hold 5 BPM calculations
        unsigned long firstpulse =0; //time of first pulse
        unsigned long timecount = 0;//cumulative time of total pulses
        unsigned long latestpulse=0;
        unsigned long interval = 10000; //setting 10 seconds as max read time
        #include <LiquidCrystal.h> //include LCD
        LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
        
        void setup()
        
        {
         pinMode(LED, OUTPUT);
         pinMode(din,INPUT);
         lcd.begin(16, 2);// set up the LCD's number of columns and rows:
         lcd.print("AV. HEART RATE:");// Print a message to the LCD.
         Serial.begin(9600);
        }
        
        void loop()
        {
        check = digitalRead(din);
        delay(100);
        if(check != prevcheck)
         {
         if (check == LOW)
           {
           digitalWrite(LED, LOW);
           }
        
         if (check == HIGH)
           {
           digitalWrite(LED, HIGH);
        
           if (pulsecount == 0 ) // if this is the first count
             {
             firstpulse = millis(); // recording time of first pulse
             pulsecount = pulsecount +1; //increment the counter
             }
        
           if (pulsecount >=1 )
             {
             pulsecount = pulsecount + 1; // increment pulse counter when detected
             latestpulse = millis(); // recording latest pulse time
             }
           }
         }
        
        //-----DISPLAY------///
        
        if (latestpulse - firstpulse > interval) //checking if 6 seconds has elapsed
         {
         BPM= pulsecount*6;
         BPMA[totalBeats]=BPM
         Serial.println(BPM); //display the number of counts over 6 seconds
         pulsecount = 0; // counter restarted
         firstpulse = 0; // restart for time of new first-pulse read 
         latestpulse = 0; // restart for new time readings
         lcd.setCursor(0, 1); //setting LCD cursor to 1st column, second row
         lcd.print(BPM); // print the HR on the LCD as well
         lcd.setCursor(5,1); // setting cursor in 5th column, row 2
         lcd.print("BPM"); // printing text next to BPM
         
        }
        prevcheck = check;
        }
  **mySerial.println("sprintf(HPM)");// The SMS text you want to send**

Well, clearly the only thing you know about sprintf() is how to spell it.

This project is clearly beyond your skill level at this time.

Do some research on sprintf(), println(), etc. and UNDERSTAND what the functions do. THEN, you can use them properly.

Well, that's whyI am here, to ask for some help and proper guidance.

EElive:
Well, that's whyI am here, to ask for some help and proper guidance.

No, you are here to be handed answers. You won't learn a thing that way.