Blood pressure measuring and Detailed Report Emailing system using Raspberry Pi.
A blood pressure monitoring system provides a useful tool for users to measure and manage their daily blood pressure values. This system can measure the blood pressure and heart rate and then store and forward the measuring information to the management through email. The email will contain the details of the blood pressure in a text file. the text file contains the details of the systolic, diastolic, and heart rate details.
In this project, I have created the classification of blood pressure and Emailing system using raspberry pi and BP Sensor.
Blood Pressure Basics Understanding
Blood pressure is the pressure of the blood in the arteries as it is pumped around the body by the heart. When your heart beats, it contracts and pushes blood through the arteries to the rest of your body. This force creates pressure on the arteries. Blood pressure is recorded as two numbers— the systolic pressure (as the heart beats) over the diastolic pressure (as the heart relaxes between beats). The unit which measures this is called a Sphygmomanometer.
Monitoring blood pressure at home is important for many people, especially if you have high blood pressure. Blood pressure does not stay the same all the time. It changes to meet your body’s needs. It is affected by various factors including body position, breathing or emotional state, exercise, and sleep. It is best to measure blood pressure when you are relaxed and sitting or lying down.
Classification of blood pressure for adults (18 years and older).
Block Diagram of the System
All The BP Sensors available in the market are not suitable to interface with the external microcontroller. Here I have used a customized Bp sensor interface with the raspberry pi.
BP Sensor
Here I have used a wrist wearable Blood pressure sensor. The sensor gives the data Output Through UART Communication.
Features
- Intelligent automatic compression and decompression
- Easy to operate, switching button to start measuring
- 60 store groups memory measurements
- Can read single or all measures
- 3 minutes the automatic power-saving device
- Intelligent device debugging, automatic power to detect
- Local tests for wrist circumference as 135-195mm
- Large-scale digital liquid crystal display screen, Easy to Read Display
- Fully Automatic, Clinical Accuracy, High-accuracy
- Power by External +5V DC
- Serial output data for external circuit processing or display.
Specification
- Working Voltage: +5V, 200mA regulated
- Output Format: Serial Data at 9600 baud rate(8 bits data, No parity, 1 stop bits). Outputs three parameters in ASCII.
The sensing unit wire length is 2 meters
Sensor Pinouts
- TX-OUT = Transmit output. Output serial data of 3V logic level, Usually connected to RXD pin of microcontrollers/RS232/USB-UART.
- +5V = Regulated 5V supply input.
- GND = Board Common Ground
- Status = Indicates the BP sensor is active or Not.
How the System Works.
Raspberry pi 3 B+ Is used in this project to receive the data from the BP Sensor and to process the data. The BP sensor provides the data through the UART Communication to Raspberry pi. The raspberry pi receives the data from the sensor Through the UART channel, The Sensor Baud rate is fixed to 9600 hence we need to set the baud rate settings of the Raspberry pi to 9600.
The output reading is an 8-bit value in ASCII format fixed digits, from 000 to 255.
Typical reading will be like below where the three values are separated by comma and space.
- Systolic
- Diastolic
- Pulse
Example: 129, 107, 095
After Converting the values the data is classified by comparing the systolic and diastolic data according to Standard format.
For Emailing the report I have stored the converted data into a text format. after the classification, the file will be attached to the Email By creating subject details according to the Blood pressure data. For email, I have used SMTP Libraries.
Text File Screenshot
Email Screenshot
Demo Video
Schematics
Project code
import serial, time
import RPi.GPIO as GPIO
import re
import smtplib,ssl
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import formatdate
from email import encoders
bp = 2 // Bp sensor status pin
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(bp,GPIO.IN)
ser = serial.Serial("/dev/ttyS0",9600)
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
ser.timeout = 1 #non-block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
file = open('sensor_readings.txt', 'w')
#file.write('time and date, systolic(b), diastolic(c),Pulse(d)\n')
file.write(' Your Blood Pressure Details Are As Follows\n')
def send_an_email_normal():
toaddr = 'to@gmail.com' # To id
me = 'your email id' # your id
subject = "Normal Blood pressure" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
def send_an_email_Hypotension():
toaddr = 'to@gmail.com' # To id
me = 'mailto:your email id' # your id
subject = "Hypotension" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
def send_an_email_prehypertension():
toaddr = 'to@gmail.com' # To id
me = 'mailto:your email id' # your id
subject = "Prehypertension" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
def send_an_email_stage1():
toaddr = 'to@gmail.com' # To id
me = 'mailto:your email id' # your id
subject = "Stage 1 Hypertension" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
def send_an_email_stage2():
toaddr = 'to@gmail.com' # To id
me = 'mailto:your email id' # your id
subject = "Stage 2 Hypertension" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
def send_an_email_hypertensive():
toaddr = 'to@gmail.com' # To id
me = 'mailto:your gmail id' # your id
subject = "Hypertensive Crisis" # Subject
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = me
msg['To'] = toaddr
msg.preamble = "test "
#msg.attach(MIMEText(text))
part = MIMEBase('application', "octet-stream")
part.set_payload(open("sensor_readings.txt", "rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="sensor_readings.txt"') # File name and format name
msg.attach(part)
try:
s = smtplib.SMTP('smtp.gmail.com', 587) # Protocol
s.ehlo()
s.starttls()
s.ehlo()
s.login(user = 'mailto:xxxxx@gmail.com', password = 'your email password') # User id & password
#s.send_message(msg)
s.sendmail(me, toaddr, msg.as_string())
s.quit()
#except:
# print ("Error: unable to send email")
except SMTPException as error:
print ("Error") # Exception
while True:
response = ser.readline().decode('ASCII')
x = len(response)# checking the avalible bytes in the serial data
if x >= 10:
print("systolic,diastolic,Pulse")
print(response)
y = response.split(',') #spliting the each bytes with comma
print(y)
z = re.findall('[0-9]+', response) # extracting each byte
print(z)
a = [z] # creating extracted each byte in a array
b = int(z[0]) # first byte in a array (Systollic)
c = int(z[1]) # second byte in a array (diastollic)
d = int(z[2]) # third byte in a array (pulse)
print("Systolic :", b)
print("Diastollic :",c)
print("Pulse:" , d)
file.write(time.strftime('%H:%M:%S %d/%m/%Y') + ' Systollic:' + str(b) + ' Diastollic:'+ str(c)+' Pulse rate:' + str(d) + '\n')
time.sleep(1)
file.close()
print("file written")
if b < 90 and c < 60:
print('Hypotension')
send_an_email_Hypotension()
if b > 120 and b < 139 and c > 80 and c < 90:
print('Prehypertension')
send_an_email_prehypertension()
if b > 140 and b < 159 and c > 90 and c < 99:
print('stage 1 Hypertension')
send_an_email_stage1()
if b > 160 and b < 179 and c > 100 and c < 109:
print('stage 2 Hypertension')
send_an_email_stage2()
if b > 180 and c > 110:
print('Hypertensive Crisis')
send_an_email_hypertensive()
else:
send_an_email_normal()
print('sent_the_mail')