Hello guys. So, i'm creating a blood pressure monitor using the mpx 5100 and the arduino that i use is the MKR ZERO. I can provide you the xircuit diagram that i use. Can you please help writing the code to calculate systolic and diastolic pressure and heartbeat?As you can see in the picture, the green frame is the arduino that i use and it has two inputs coming from the circuit. The first is the pressure and the second is the oscillation signal. Any help would be great!!!
Sure! You go first. You have the documentation and we don't. You have all the components and testing equipment and the calibration equipment and we don't.
Try the search phrase "blood pressure sensor arduino code"
Ok so here is the code that i tried yesterday. :
#include <Arduino.h>
const int pressurePin = A0; // Analog pin for pressure signal
const int oscillationPin = A1; // Analog pin for oscillation signal
const float maxPressure_kPa = 400.0; // Maximum pressure in kPa
const float sensitivity_mv_per_kPa = 45.0; // Sensitivity in mV/kPa
const unsigned int maxSystolicPressure = 240; // Maximum systolic pressure in mmHg
const unsigned int maxDiastolicPressure = 170; // Maximum diastolic pressure in mmHg
volatile unsigned int pressureRaw; // Raw pressure signal value
volatile unsigned int oscillationRaw; // Raw oscillation signal value
volatile float pressure_kPa; // Pressure in kPa
volatile unsigned int BPsys; // Systolic pressure
volatile unsigned int BPdia; // Diastolic pressure
// Conversion functions
float adc2pressure(unsigned int adc_val) {
return ((adc_val / 4095.0) * maxPressure_kPa); // Convert ADC value to pressure in kPa
}
unsigned int setSys(float pressure_kPa) {
// Convert pressure to systolic pressure value using your formula
return (unsigned int)((pressure_kPa / maxPressure_kPa) * maxSystolicPressure);
}
unsigned int setDia(float pressure_kPa) {
// Convert pressure to diastolic pressure value using your formula
return (unsigned int)((pressure_kPa / maxPressure_kPa) * maxDiastolicPressure);
}
void setup() {
Serial.begin(9600);
}
void loop() {
// Simulating raw pressure and oscillation values, replace with actual sensor readings
pressureRaw = analogRead(pressurePin);
oscillationRaw = analogRead(oscillationPin);
// Convert raw pressure ADC value to pressure in kPa
pressure_kPa = adc2pressure(pressureRaw);
// Calculate systolic and diastolic pressures
BPsys = setSys(pressure_kPa);
BPdia = setDia(pressure_kPa);
// Print results
Serial.print("Raw Pressure: ");
Serial.println(pressureRaw);
Serial.print("Pressure (kPa): ");
Serial.println(pressure_kPa, 2); // Print with 2 decimal places
Serial.print("Systolic Pressure: ");
Serial.println(BPsys);
Serial.print("Diastolic Pressure: ");
Serial.println(BPdia);
// Print oscillation signal value
Serial.print("Oscillation Signal: ");
Serial.println(oscillationRaw);
delay(1000); // Add a delay between measurements
}
The systolic and diastolic results that provides are quite good. However, the problem is that whenever I pressure the cuff in my hand, it always depicts the same numbers. Let meknow if I forgot to write something in my code.
Do you mean if you pump up the cuff and squeeze it the pressures don't change?
The MPX5100 is a 5volt-logic sensor and the MKR Zero is a 3.3volt-logic processor.
How did you solve that.
Leo..
I use an lf33cv which converts the 5vto 3.3v, in which i can supply the amplifier that i use
Yes exactly!
Which opamp (hopefully not an LM358).
Leo..
the opamp is the tlc272
All of your conversions are wrong.
Try this code:
#include <Arduino.h>
const int pressurePin = A0; // Analog pin for pressure signal
const int oscillationPin = A1; // Analog pin for oscillation signal
// const float maxPressure_kPa = 400.0; // Maximum pressure in kPa
// const unsigned int maxSystolicPressure = 240; // Maximum systolic pressure in mmHg
// const unsigned int maxDiastolicPressure = 170; // Maximum diastolic pressure in mmHg
const float sensitivity_mv_per_kPa = 90; // Sensitivity of MPX5050 in mV/kPa
const float kPa_to_mmHg = 7.501; // Convert kPa to mmHg
volatile unsigned int pressureRaw; // Raw pressure signal value
volatile unsigned int oscillationRaw; // Raw oscillation signal value
volatile float pressure_kPa; // Pressure in kPa
volatile unsigned int BPsys; // Systolic pressure
volatile unsigned int BPdia; // Diastolic pressure
// Conversion functions
float adc2pressure(unsigned int adc_val) {
// Convert ADC value to mV, then to pressure in kPa
return (((adc_val / 4095.0) * 5000.0) / sensitivity_mv_per_kPa);
}
unsigned int setSys(float pressure_kPa) {
// Convert pressure in kPa to mmHg
return (unsigned int) (pressure_kPa * kPa_to_mmHg);
}
unsigned int setDia(float pressure_kPa) {
// Convert pressure in kPa to mmHg
return (unsigned int) (pressure_kPa * kPa_to_mmHg);
}
void setup() {
Serial.begin(9600);
}
void loop() {
// Simulating raw pressure and oscillation values, replace with actual sensor readings
pressureRaw = analogRead(pressurePin);
oscillationRaw = analogRead(oscillationPin);
// Convert raw pressure ADC value to pressure in kPa
pressure_kPa = adc2pressure(pressureRaw);
// Calculate systolic and diastolic pressures
BPsys = setSys(pressure_kPa);
BPdia = setDia(pressure_kPa);
// Print results
Serial.print("Raw Pressure: ");
Serial.println(pressureRaw);
Serial.print("Pressure (kPa): ");
Serial.println(pressure_kPa, 2); // Print with 2 decimal places
Serial.print("Systolic Pressure: ");
Serial.println(BPsys);
Serial.print("Diastolic Pressure: ");
Serial.println(BPdia);
// Print oscillation signal value
Serial.print("Oscillation Signal: ");
Serial.println(oscillationRaw);
delay(1000); // Add a delay between measurements
}
Not a rail2rail opamp. Output swing (high) could be as low a 2volt when opamps are powered with 3.3volt. Which could mean clipping at higher blood pressures.
Maybe you should power the whole amp (and sensor) with 5volt, and have 10k resistors between opamp outputs and processor, for protection.
Leo..
I made a mistake:
Change
const float sensitivity_mv_per_kPa = 90; // Sensitivity of MPX5050 in mV/kPa
To
const float sensitivity_mv_per_kPa = 45.0; // Sensitivity of MPX5050 in mV/kPa
The title of the post says MPX5100, which is half the sensitivity of a 5050.
So indeed 100kPa over a 4.5volt range (45mV/kPa).
The sensor outputs ~1.2volt with 100mmHg, which is amplified 1.5 times.
Which brings the opamp close to it's clipping point when on a 3.3volt supply.
The code also doesn't subtract the (~0,2volt x1.5) offset of the sensor at zero pressure.
Which calculates to about 372 with a 12-bit A/D and 3.3volt VCC.
Leo..
Hello, we are also working on this kind of project. We liked your project very much. Could you please share the circuit diagram and code of your project?
Hi, we are working on a similar project and am very interested in the circuit diagram and the electrical components that you have used. Do contact me if you are able to help!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.