Help with patient monitoring project ASAP

This project entails using a GSM module to send messages to patients when their heart rate and temperature are above a given threshold. An error keeps appearing on the line "String message = "NHS ALERT!" + patientname + " (" + nhsnum + ") ";" saying "expected initializer before 'String'". The full code is below:

#include <Adafruit_SSD1306.h>

#include <splash.h>

#include <RTClib.h>

#include <SoftwareSerial.h>

#include <SD.h>

#include <SPI.h>

#include <String.h>
 

// Include the libraries we need

#include <OneWire.h>

#include <DallasTemperature.h>

 

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

#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.  

 

//  Variables

const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0

const int LED = 13;          // The on-board Arduino LED, close to PIN 13.

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.

// Data wire is plugged into port 2 on the Arduino

#define ONE_WIRE_BUS 8

 

#define SCREEN_WIDTH 128 // OLED display width,  in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

 

// declare an SSD1306 display object connected to I2C

RTC_DS3231 rtc;

SoftwareSerial mySerial(10, 11); // RX, TX

const int chipSelect = 4;
File alertFile;      // Reading from SD card
File dateFile;
File timeFile;
File patientFile;
File nhsnumFile;
File heartRateFile;
File temperatureFile;


Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

 

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

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)

OneWire oneWire(ONE_WIRE_BUS);

 

// Pass our oneWire reference to Dallas Temperature.

DallasTemperature sensors(&oneWire);


// Defining thresholds
String patientname = "50 Cent";
String nhsnum = "50505050";

float tempCthreshold = 20.0;
int bpmthreshold = 50;


void setup() {  

 
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);          // For Serial Monitor

  while (!Serial); // wait for serial port to connect. Needed for native USB

  Wire.begin();

  rtc.begin();

  // The following lines can be uncommented to set the date and time

  rtc.adjust(DateTime(2023, 3, 17, 16, 01, 0));

  Serial.println("Dallas Temperature IC Control Library Demo");

 

// initialize OLED display with address 0x3C for 128x64

  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {

   Serial.println(F("SSD1306 allocation failed"));

   while (true);

}

 

  delay(2000);         // wait for initializing

  oled.clearDisplay(); // clear display

 

  oled.setTextSize(1);          // text size

  oled.setTextColor(WHITE);     // text color

  oled.setCursor(0, 0);        // position to display

  oled.println("NHS ALERT!"); // text to display

  oled.display();               // show on OLED

 

 

  // Start up the library

  sensors.begin();

  // Configure the PulseSensor object, by assigning our variables to it.

  pulseSensor.analogInput(PulseWire);  

  pulseSensor.blinkOnPulse(LED);       //auto-magically blink Arduino's LED with heartbeat.

  pulseSensor.setThreshold(Threshold);  

 

  // Double-check the "pulseSensor" object was created and "began" seeing a signal.

   if (pulseSensor.begin()) {

    Serial.println("We created a pulseSensor Object !");  //This prints one time at Arduino power-up,  or on Arduino reset.

  }

    // Start serial communication with the module

  mySerial.begin(9600);

  while (!mySerial) {

    ; // wait for serial port to connect. Needed for native USB port only

  }
 

  // Initialize SD card

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {

    Serial.println("SD card initialization failed!");

    return;

  }

  Serial.println("SD card initialization done.");

}


 
 

void loop() {

 

  // call sensors.requestTemperatures() to issue a global temperature

  // request to all devices on the bus

  Serial.print("Requesting temperatures...");

  sensors.requestTemperatures(); // Send the command to get temperatures

  Serial.println("DONE");

  // After we got the temperatures, we can print them here.

  // We use the function ByIndex, and as an example get the temperature from the first sensor only.

  float tempC = sensors.getTempCByIndex(0);

 

  // Check if reading was successful

  if(tempC != DEVICE_DISCONNECTED_C)

  {

    Serial.print("Temperature for the device 1 (index 0) is: ");

    oled.setCursor(0,5);

    Serial.println(tempC);

  }

  else

  {

    Serial.println("Error: Could not read temperature data");

  }


  if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened".

    int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".

    //                                                // "myBPM" hold this BPM value now.

    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.

 

if (pulseSensor.sawStartOfBeat()) {

    // ...

    File alertFile = SD.open("alert.txt", FILE_WRITE);

    if (alertFile) {

      alertFile.print("NHS ALERT!");

      alertFile.close();

    }

    File dateFile = SD.open("date.txt", FILE_WRITE);

    if (dateFile) {

      dateFile.print("17/03/2023");

      dateFile.close();

    }

   File timeFile = SD.open("time.txt", FILE_WRITE);

    if (timeFile) {

      timeFile.print("16:00:00");

      timeFile.close();

    }

    File patientFile = SD.open("patient.txt", FILE_WRITE);

    if (patientFile) {

      patientFile.print("50 Cent");

      patientFile.close();

    }

    File nhsnumFile = SD.open("nhsnum.txt", FILE_WRITE);

    if (nhsnumFile) {

      nhsnumFile.print("5050505050");

      nhsnumFile.close();

    }

    // Write the heart rate to the SD card

    File heartRateFile = SD.open("heart_rate.txt", FILE_WRITE);

    if (heartRateFile) {

      heartRateFile.print(myBPM);

      heartRateFile.close();

    }

    // Write the temperature to the SD card

    File temperatureFile = SD.open("temperature.txt", FILE_WRITE);

    if (temperatureFile) {

      temperatureFile.print(tempC);

      temperatureFile.close();

    }

  }  

 

// Wait one second before repeating :)

  delay (1000);

  DateTime now = rtc.now();

 

  oled.clearDisplay(); // clear display

  oled.setTextSize(1);          // text size

  oled.setTextColor(WHITE);     // text color

  oled.setCursor(0, 0);        // position to display

  oled.println("NHS ALERT!"); // text to display

 

  oled.setCursor(0, 10);

  oled.print(now.year(), DEC);

  oled.print('/');

  oled.print(now.month(), DEC);

  oled.print('/');

  oled.print(now.day(), DEC);

  oled.print(' ');

  oled.print(now.hour(), DEC);

  oled.print(':');

  oled.print(now.minute(), DEC);

  oled.print(':');

  oled.print(now.second(), DEC);

 

  oled.setCursor(0,20);

  oled.println("PATIENT NAME: 50 Cent");

 

  oled.setCursor(0,30);

  oled.println("NHS NUMBER: 50505050");

 

  oled.setCursor(0, 40);

  oled.print("TEMPERATURE: ");

  oled.print(tempC);

  oled.print(" C");

 

  oled.setCursor(0, 50);

  oled.print("HEART RATE: ");

  oled.print(myBPM);

  oled.print(" BPM");

 

  oled.display();

 

  // Wait for a short period before updating the display again

  delay(1000);

}

  // Get data from SD card
  alertFile = SD.open("alert.txt");
  if (alertFile) {
    while (alertFile.available()) {
      // Read the data from the file and store it in a variable
      String alert = alertFile.readStringUntil('\n');

  alertFile.close();
     }
  }
  else {
    Serial.println("Error opening data file!");
 
 
  dateFile = SD.open("date.txt");
    if (dateFile) {
    while (dateFile.available()) {
      // Read the data from the file and store it in a variable
      String date = dateFile.readStringUntil('\n');

  dateFile.close();
  }
    }
    else {
    Serial.println("Error opening data file!");
 
     
  timeFile = SD.open("time.txt");
    if (timeFile) {
    while (timeFile.available()) {
      // Read the data from the file and store it in a variable
      String time = timeFile.readStringUntil('\n');

  timeFile.close();
  }
    }
    else {
    Serial.println("Error opening data file!");
 
  patientFile = SD.open("patient.txt");
    if (patientFile) {
    while (patientFile.available()) {
      // Read the data from the file and store it in a variable
      String patient = alertFile.readStringUntil('\n');

  patientFile.close();
  }
   
    }  else {
    Serial.println("Error opening data file!");
 
     
  nhsnumFile = SD.open("nhsnum.txt");
    if (nhsnumFile) {
    while (nhsnumFile.available()) {
      // Read the data from the file and store it in a variable
      String nhsnum = nhsnumFile.readStringUntil('\n');

  nhsnumFile.close();
  }
    } else {
    Serial.println("Error opening data file!");
 
     
  heartRateFile = SD.open("heart_rate.txt");
    if (heartRateFile) {
    while (heartRateFile.available()) {
      // Read the data from the file and store it in a variable
      String heartRate = heartRateFile.readStringUntil('\n');

  heartRateFile.close();
  }
    } else {
    Serial.println("Error opening data file!");
 
     
  temperatureFile = SD.open("temperature.txt");
    if (temperatureFile) {
    while (temperatureFile.available()) {
      // Read the data from the file and store it in a variable
      String temperature = temperatureFile.readStringUntil('\n');

  temperatureFile.close();
  }
    } else {
    Serial.println("Error opening data file!");
  }
  // Send text message
  void SendMessage()

  // Format the message
  String message = "NHS ALERT!" + patientname + " (" + nhsnum + ") ";
//  message += "Patient Name: 50 Cent\n";
//  message += "NHS Number: 50505050\n";
  message += "Heart Rate: " + String(myBPM) + " bpm\n";
  message += "Temperature: " + String(tempC) + " C\n";

  mySerial.println("AT+CMGF=1");                    // Sets the GSM Module in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+447448377315\"\r");  // Replace with your mobile number
  delay(1000);
  mySerial.print(message);
  mySerial.println((char)26);                       // ASCII code of CTRL+Z
  delay(1000);

 

}

}

What is the hurry?

Hint: get rid of all the extra blank lines and format the code in the IDE using CTRL-T, which will reveal missing braces, faulty program structure, etc.

[code]
#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <SPI.h>
#include <String.h>
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.  
//  Variables
const int PulseWire = 0;       // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED = 13;          // The on-board Arduino LED, close to PIN 13.
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.

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 8
#define SCREEN_WIDTH 128 // OLED display width,  in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// declare an SSD1306 display object connected to I2C
RTC_DS3231 rtc;
SoftwareSerial mySerial(10, 11); // RX, TX
const int chipSelect = 4;
File alertFile;      // Reading from SD card
File dateFile;
File timeFile;
File patientFile;
File nhsnumFile;
File heartRateFile;
File temperatureFile;
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);// Defining thresholds
String patientname = "50 Cent";
String nhsnum = "50505050";
float tempCthreshold = 20.0;
int bpmthreshold = 50;

void setup() {
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);          // For Serial Monitor
  while (!Serial); // wait for serial port to connect. Needed for native USB
  Wire.begin();
  rtc.begin();
  // The following lines can be uncommented to set the date and time
  rtc.adjust(DateTime(2023, 3, 17, 16, 01, 0));
  Serial.println("Dallas Temperature IC Control Library Demo");
  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  {
    Serial.println(F("SSD1306 allocation failed"));
    while (true);
  }
  delay(2000);         // wait for initializing
  oled.clearDisplay(); // clear display
  oled.setTextSize(1);          // text size
  oled.setTextColor(WHITE);     // text color
  oled.setCursor(0, 0);        // position to display
  oled.println("NHS ALERT!"); // text to display
  oled.display();               // show on OLED
  // Start up the library
  sensors.begin();
  // Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.blinkOnPulse(LED);       //auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);
  // Double-check the "pulseSensor" object was created and "began" seeing a signal.

  if (pulseSensor.begin())
  {
    Serial.println("We created a pulseSensor Object !");  //This prints one time at Arduino power-up,  or on Arduino reset.
  }
  // Start serial communication with the module
  mySerial.begin(9600);
  while (!mySerial)
  { ; // wait for serial port to connect. Needed for native USB port only

  }
  // Initialize SD card
  Serial.print("Initializing SD card...");
  if (!SD.begin(chipSelect))
  {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialization done.");
}

void loop()
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  float tempC = sensors.getTempCByIndex(0);
  // Check if reading was successful
  if (tempC != DEVICE_DISCONNECTED_C)
  {
    Serial.print("Temperature for the device 1 (index 0) is: ");
    oled.setCursor(0, 5);
    Serial.println(tempC);
  }
  else
  {
    Serial.println("Error: Could not read temperature data");
  }
  if (pulseSensor.sawStartOfBeat())
  { // Constantly test to see if "a beat happened".
    int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
    //                                                // "myBPM" hold this BPM value now.
    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.

    if (pulseSensor.sawStartOfBeat())
    { // ...
      File alertFile = SD.open("alert.txt", FILE_WRITE);
      if (alertFile)
      {
        alertFile.print("NHS ALERT!");
        alertFile.close();
      }
      File dateFile = SD.open("date.txt", FILE_WRITE);
      if (dateFile)
      {
        dateFile.print("17/03/2023");
        dateFile.close();
      }
      File timeFile = SD.open("time.txt", FILE_WRITE);
      if (timeFile)
      {
        timeFile.print("16:00:00");
        timeFile.close();
      }
      File patientFile = SD.open("patient.txt", FILE_WRITE);
      if (patientFile)
      {
        patientFile.print("50 Cent");
        patientFile.close();
      }
      File nhsnumFile = SD.open("nhsnum.txt", FILE_WRITE);
      if (nhsnumFile)
      {
        nhsnumFile.print("5050505050");
        nhsnumFile.close();
      }
      // Write the heart rate to the SD card
      File heartRateFile = SD.open("heart_rate.txt", FILE_WRITE);
      if (heartRateFile)
      {
        heartRateFile.print(myBPM);
        heartRateFile.close();
      }
      // Write the temperature to the SD card
      File temperatureFile = SD.open("temperature.txt", FILE_WRITE);
      if (temperatureFile)
      {
        temperatureFile.print(tempC);
        temperatureFile.close();
      }
    }
    // Wait one second before repeating :)
    delay (1000);
    DateTime now = rtc.now();
    oled.clearDisplay(); // clear display
    oled.setTextSize(1);          // text size
    oled.setTextColor(WHITE);     // text color
    oled.setCursor(0, 0);        // position to display
    oled.println("NHS ALERT!"); // text to display
    oled.setCursor(0, 10);
    oled.print(now.year(), DEC);
    oled.print('/');
    oled.print(now.month(), DEC);
    oled.print('/');
    oled.print(now.day(), DEC);
    oled.print(' ');
    oled.print(now.hour(), DEC);
    oled.print(':');
    oled.print(now.minute(), DEC);
    oled.print(':');
    oled.print(now.second(), DEC);
    oled.setCursor(0, 20);
    oled.println("PATIENT NAME: 50 Cent");
    oled.setCursor(0, 30);
    oled.println("NHS NUMBER: 50505050");
    oled.setCursor(0, 40);
    oled.print("TEMPERATURE: ");
    oled.print(tempC);
    oled.print(" C");
    oled.setCursor(0, 50);
    oled.print("HEART RATE: ");
    oled.print(myBPM);
    oled.print(" BPM");
    oled.display();
    // Wait for a short period before updating the display again
    delay(1000);
  }  // Get data from SD card
  alertFile = SD.open("alert.txt");
  if (alertFile)
  {
    while (alertFile.available())
    {
      // Read the data from the file and store it in a variable
      String alert = alertFile.readStringUntil('\n');
      alertFile.close();
    }
  }
  else
  {
    Serial.println("Error opening data file!");
    dateFile = SD.open("date.txt");
    if (dateFile)
    {
      while (dateFile.available())
      {
        // Read the data from the file and store it in a variable
        String date = dateFile.readStringUntil('\n');
        dateFile.close();
      }
    }
    else
    {
      Serial.println("Error opening data file!");
      timeFile = SD.open("time.txt");
      if (timeFile)
      {
        while (timeFile.available()) 
        {
          // Read the data from the file and store it in a variable
          String time = timeFile.readStringUntil('\n');
          timeFile.close();
        }
      }
      else 
      {
        Serial.println("Error opening data file!");
        patientFile = SD.open("patient.txt");
        if (patientFile)
        {
          while (patientFile.available())
          {
            // Read the data from the file and store it in a variable
            String patient = alertFile.readStringUntil('\n');
            patientFile.close();
          }

        } 
        else
        {
          Serial.println("Error opening data file!");
          nhsnumFile = SD.open("nhsnum.txt");
          if (nhsnumFile)
          {
            while (nhsnumFile.available())
            {
              // Read the data from the file and store it in a variable
              String nhsnum = nhsnumFile.readStringUntil('\n');
              nhsnumFile.close();
            }
          }
          else
          {
            Serial.println("Error opening data file!");
            heartRateFile = SD.open("heart_rate.txt");
            if (heartRateFile)
            {
              while (heartRateFile.available())
              {
                // Read the data from the file and store it in a variable
                String heartRate = heartRateFile.readStringUntil('\n');
                heartRateFile.close();
              }
            }
            else
            {
              Serial.println("Error opening data file!");
              temperatureFile = SD.open("temperature.txt");
              if (temperatureFile)
              {
                while (temperatureFile.available())
                {
                  // Read the data from the file and store it in a variable
                  String temperature = temperatureFile.readStringUntil('\n');
                  temperatureFile.close();
                }
              }
              else
              {
                Serial.println("Error opening data file!");
              }

            }    <<< <<< <<< <<< <>
          } <<< <<< <<<,
        } <<< <<< <<< <
      } <<< <<< <<<
    } <<< <<< <<
  } <<< <<< <<<
} <<< <<< <<< <
// Send text message
void SendMessage()
{ //<<<<<<<<<<<<
  // Format the message
  String message = "NHS ALERT!" + patientname + " (" + nhsnum + ") ";
  //  message += "Patient Name: 50 Cent\n";
  //  message += "NHS Number: 50505050\n";
  message += "Heart Rate: " + String(myBPM) + " bpm\n";
  message += "Temperature: " + String(tempC) + " C\n";
  mySerial.println("AT+CMGF=1");                    // Sets the GSM Module in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+447448377315\"\r");  // Replace with your mobile number
  delay(1000);
  mySerial.print(message);
  mySerial.println((char)26);                       // ASCII code of CTRL+Z
  delay(1000);
}

//}      >>>>>>>>>
[/code]

You should post the web site from which this was copy/pasted.

Easy to find copy/paste errors like [code] which is the portion of the article that you do not copy/paste. Others are the <<< <<< <<< <<< <> which will not compile, and < < < < < < < < <, with a stray comma after the waca train, and nearly every conditional test of a data file access failed to have a close brace. What a mess. I found some of the "authors" from where this came. They, too, copy/pasted, errors and all. Good luck in "your" project.

// Include the libraries we need
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include <SD.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <String.h>
#include <splash.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <PulseSensorPlayground.h>  // Includes the PulseSensorPlayground Library.

//  Variables
#define USE_ARDUINO_INTERRUPTS true  // Set-up low-level interrupts for most acurate BPM math.
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED = 13; // The on-board Arduino LED, close to PIN 13.
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.

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 8
#define SCREEN_WIDTH 128  // OLED display width,  in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

RTC_DS3231 rtc;
SoftwareSerial mySerial(10, 11);  // RX, TX
const int chipSelect = 4;

// Reading from SD card
File alertFile;
File dateFile;
File timeFile;
File patientFile;
File nhsnumFile;
File heartRateFile;
File temperatureFile;

// declare an SSD1306 display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

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

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);  // Defining thresholds
String patientname = "50 Cent";
String nhsnum = "50505050";
float tempCthreshold = 20.0;
int bpmthreshold = 50;

void setup() {
  mySerial.begin(9600);  // Setting the baud rate of GSM Module
  Serial.begin(9600);    // For Serial Monitor
  while (!Serial)
    ;  // wait for serial port to connect. Needed for native USB

  Wire.begin();
  rtc.begin();

  // The following lines can be uncommented to set the date and time
  rtc.adjust(DateTime(2023, 3, 17, 16, 01, 0));
  Serial.println("Dallas Temperature IC Control Library Demo");

  // initialize OLED display with address 0x3C for 128x64
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  {
    Serial.println(F("SSD1306 allocation failed"));
    while (true)
      ;
  }
  delay(2000);                 // wait for initializing
  oled.clearDisplay();         // clear display
  oled.setTextSize(1);         // text size
  oled.setTextColor(WHITE);    // text color
  oled.setCursor(0, 0);        // position to display
  oled.println("NHS ALERT!");  // text to display
  oled.display();              // show on OLED

  // Start up the library
  sensors.begin();

  // Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.blinkOnPulse(LED);  // auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);

  // Double-check the "pulseSensor" object was created and "began" seeing a signal.
  if (pulseSensor.begin())
  {
    Serial.println("We created a pulseSensor Object !");    // This prints one time at
    // Arduino power-up,  or on
    // Arduino reset.
  }

  // Start serial communication with the module
  mySerial.begin(9600);
  while (!mySerial)
  {
    ;  // wait for serial port to connect. Needed for native USB port only
  }

  // Initialize SD card
  Serial.print("Initializing SD card...");
  if (!SD.begin(chipSelect))
  {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialization done.");
}

void loop() {
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();  // Send the command to get temperatures
  Serial.println("DONE");

  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the
  // first sensor only.
  float tempC = sensors.getTempCByIndex(0);

  // Check if reading was successful
  if (tempC != DEVICE_DISCONNECTED_C)
  {
    Serial.print("Temperature for the device 1 (index 0) is: ");
    oled.setCursor(0, 5);
    Serial.println(tempC);
  } else
  {
    Serial.println("Error: Could not read temperature data");
  }

  // Constantly test to see if "a beat happened".
  if (pulseSensor.sawStartOfBeat())
  {
    int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object
    // that returns BPM as an "int".
    // "myBPM" hold this BPM  value now.
    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.

    if (pulseSensor.sawStartOfBeat())
    {

      File alertFile = SD.open("alert.txt", FILE_WRITE);
      if (alertFile)
      {
        alertFile.print("NHS ALERT!");
        alertFile.close();
      }

      File dateFile = SD.open("date.txt", FILE_WRITE);
      if (dateFile)
      {
        dateFile.print("17/03/2023");
        dateFile.close();
      }

      File timeFile = SD.open("time.txt", FILE_WRITE);
      if (timeFile)
      {
        timeFile.print("16:00:00");
        timeFile.close();
      }

      File patientFile = SD.open("patient.txt", FILE_WRITE);
      if (patientFile)
      {
        patientFile.print("50 Cent");
        patientFile.close();
      }

      File nhsnumFile = SD.open("nhsnum.txt", FILE_WRITE);
      if (nhsnumFile)
      {
        nhsnumFile.print("5050505050");
        nhsnumFile.close();
      }

      // Write the heart rate to the SD card
      File heartRateFile = SD.open("heart_rate.txt", FILE_WRITE);
      if (heartRateFile)
      {
        heartRateFile.print(myBPM);
        heartRateFile.close();
      }

      // Write the temperature to the SD card
      File temperatureFile = SD.open("temperature.txt", FILE_WRITE);
      if (temperatureFile)
      {
        temperatureFile.print(tempC);
        temperatureFile.close();
      }
    }

    // Wait one second before repeating :)
    delay(1000);
    DateTime now = rtc.now();

    oled.clearDisplay();         // clear display
    oled.setTextSize(1);         // text size
    oled.setTextColor(WHITE);    // text color
    oled.setCursor(0, 0);        // position to display
    oled.println("NHS ALERT!");  // text to display
    oled.setCursor(0, 10);
    oled.print(now.year(), DEC);
    oled.print('/');
    oled.print(now.month(), DEC);
    oled.print('/');
    oled.print(now.day(), DEC);
    oled.print(' ');
    oled.print(now.hour(), DEC);
    oled.print(':');
    oled.print(now.minute(), DEC);
    oled.print(':');
    oled.print(now.second(), DEC);

    oled.setCursor(0, 20);
    // oled.println("PATIENT NAME: 50 Cent");
    oled.print("PATIENT NAME: ");
    oled.print(patientname);

    oled.setCursor(0, 30);
    // oled.println("NHS NUMBER: 50505050");
    oled.println("NHS NUMBER: ");
    oled.println(nhsnum);

    oled.setCursor(0, 40);
    oled.print("TEMPERATURE: ");
    oled.print(tempC);
    oled.print(" C");

    oled.setCursor(0, 50);
    oled.print("HEART RATE: ");
    oled.print(myBPM);
    oled.print(" BPM");
    oled.display();

    // Wait for a short period before updating the display again
    delay(1000);
  }

  // Get data from SD card
  alertFile = SD.open("alert.txt");
  if (alertFile)
  {
    while (alertFile.available())
    {
      // Read the data from the file and store it in a variable
      String alert = alertFile.readStringUntil('\n');
      alertFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  dateFile = SD.open("date.txt");
  if (dateFile)
  {
    while (dateFile.available())
    {
      // Read the data from the file and store it in a variable
      String date = dateFile.readStringUntil('\n');
      dateFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  timeFile = SD.open("time.txt");
  if (timeFile)
  {
    while (timeFile.available())
    {
      // Read the data from the file and store it in a variable
      String time = timeFile.readStringUntil('\n');
      timeFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  patientFile = SD.open("patient.txt");
  if (patientFile)
  {
    while (patientFile.available())
    {
      // Read the data from the file and store it in a variable
      String patient = alertFile.readStringUntil('\n');
      patientFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  nhsnumFile = SD.open("nhsnum.txt");
  if (nhsnumFile)
  {
    while (nhsnumFile.available())
    {
      // Read the data from the file and store it in a variable
      String nhsnum = nhsnumFile.readStringUntil('\n');
      nhsnumFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  heartRateFile = SD.open("heart_rate.txt");
  if (heartRateFile)
  {
    while (heartRateFile.available())
    {
      // Read the data from the file and store it in a variable
      String heartRate = heartRateFile.readStringUntil('\n');
      heartRateFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }

  temperatureFile = SD.open("temperature.txt");
  if (temperatureFile)
  {
    while (temperatureFile.available())
    {
      // Read the data from the file and store it in a variable
      String temperature = temperatureFile.readStringUntil('\n');
      temperatureFile.close();
    }
  } else
  {
    Serial.println("Error opening data file!");
  }
}

// Send text message
void SendMessage()
{
  // Format the message
  String message = "NHS ALERT!" + patientname + " (" + nhsnum + ") ";
  //  message += "Patient Name: 50 Cent\n";
  //  message += "NHS Number: 50505050\n";
  message += "Heart Rate: " + String(myBPM) + " bpm\n";
  message += "Temperature: " + String(tempC) + " C\n";

  // Sets the GSM Module in Text Mode
  mySerial.println("AT+CMGF=1");
  delay(1000);

  // Replace with your mobile number
  mySerial.println("AT+CMGS=\"+447448377315\"\r");
  delay(1000);

  mySerial.print(message);
  mySerial.println((char)26);  // ASCII code of CTRL+Z
  delay(1000);
}

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