Problem in Interfacing blood pressure sensor - Serial output with Arduino Uno

I tried interfacing Blood Pressure Sensor - Serial Output with Arduino Uno but every time when reading is taken, instead of current value the previous values are displayed on the Arduino’s serial Monitor.

This is the link of the blood - pressure Sensor that I’m using.
http://www.sunrom.com/p/blood-pressure-sensor-serial-output

#include <SoftwareSerial.h>
int sensorValue; // variable to store the value coming from the sensor

SoftwareSerial serial(9,10);

void setup() {
Serial.begin(9600);
serial.begin(9600);
}

void loop()
{
char serialData[30];
int lf = 10;
unsigned char read1,read2,read3;

while(serial.available())
{
serial.readBytesUntil(lf,serialData, 15);
}

read1 = ((serialData[1]-‘0’)*100) + ((serialData[2]-‘0’)*10) +(serialData[3]-‘0’);
read2 = ((serialData[6]-‘0’)*100) + ((serialData[7]-‘0’)*10) +(serialData[8]-‘0’);
read3 = ((serialData[11]-‘0’)*100) + ((serialData[12]-‘0’)*10) +(serialData[13]-‘0’);

Serial.println(read1);
Serial.println(read2);
Serial.println(read3);

Serial.flush();
serial.flush();
}

I'm not sure, but I think you are reading too fast. 9600 baud is slow by computer standards. serial.Available() will be true as soon as the first byte comes in, but the rest of the message still needs to be received. Try putting about 15-20mS delay after if (serial.Avalable()). By my calcs it will take about 12 mS to receive 14 bytes at 9600 baud.

Thank you but this is not helping.

I just noticed that you sending the values to your serial monitor every time loop() executes, but you are only updating the data from the serial buffer when data is new. If that doesn’t fix it I would try the following to debug.

flush the serial buffer at the end of init()

Change the while loop to an if statement and put everything (reading the buffer, printing) in the if block.

Get the number of bytes read and send it to the serial monitor

Print the raw data received to the serial monitor

clear out the old data so I know if I am seeing new data

something like this

#include <SoftwareSerial.h>
int sensorValue;       // variable to store the value coming from the sensor

SoftwareSerial serial(9,10);

void setup() {
  Serial.begin(9600);
  serial.begin(9600);
  delay(1);
  //flush serial buffers just in case, once it is working this probably isn't necessary and can be removed.
  Serial.flush();
  serial.flush();  
}

void loop() 
{
  char serialData[30];
  int lf = 10;
  unsigned char read1,read2,read3; 
  int temp_int;                       //temporary integer variable
  char temp_string[40];               //temporary string variable
    
  if(serial.available() >= 15)        //change to if() and wait until a full message is available
                                      //this might need to be >=14, I'm not sure
                                      //
                                      //while() can work, but if() seems more appropriate since you 
                                      //are waiting for something to happen, not executing code while 
                                      //something else if true. Maybe I'm being overly picky
  {
    // Find out how many bytes of data you are getting
    temp_int = serial.readBytesUntil(lf,serialData, 15);
    //Send the number of bytes to the serial monitor
    sprintf(temp_string, "Number of bytes read: %d", temp_int);
    Serial.println(temp_string);

    //send the raw data received to the serial monitor
    sprintf(temp_string, "%c %c %c %c %u", serialData[0],  serialData[1],  serialData[2],  serialData[3],  serialData[4]);
    Serial.println(temp_string);
    sprintf(temp_string, "%u %u %u %u %u", serialData[5],  serialData[6],  serialData[7],  serialData[8],  serialData[9]);
    Serial.println(temp_string);
    sprintf(temp_string, "%u %u %u %u %u", serialData[10],  serialData[11],  serialData[12],  serialData[13],  serialData[14]);
    Serial.println(temp_string);
        
    // Bring all your processing into the if() block
    read1 = ((serialData[1]-'0')*100) + ((serialData[2]-'0')*10) +(serialData[3]-'0');
    read2 = ((serialData[6]-'0')*100) + ((serialData[7]-'0')*10) +(serialData[8]-'0');
    read3 = ((serialData[11]-'0')*100) + ((serialData[12]-'0')*10) +(serialData[13]-'0');

    Serial.println(read1);
    Serial.println(read2);
    Serial.println(read3); 
        
    // Clear out old data
    for (int i = 0; i < 30; i++) {
      serialData[i] = 0;
    }
    read1=0;
    read2=0;
    read3=0;
                 
    Serial.flush();
    serial.flush();  
  }
}

if that doesn’t solve it, I am stumped. Maybe put a switch input use that to trigger a read of the serial buffer after you know there is new data.