element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Blood Pressure Sensor Interfacing with Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vinayyn
  • Date Created: 20 Dec 2021 2:46 PM Date Created
  • Views 6726 views
  • Likes 7 likes
  • Comments 4 comments
Related
Recommended
  • raspberry pi3
  • Health
  • iot

Blood Pressure Sensor Interfacing with Raspberry Pi

vinayyn
vinayyn
20 Dec 2021

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).

image

Block Diagram of the System

image

image

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

image

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.

image

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

image

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

image

Email Screenshot

image

Demo Video

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Schematics

image

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')
            
       

  • Sign in to reply
  • vinayyn
    vinayyn over 1 year ago in reply to congkxtb95

    Customization can be made to the normal bp sensors.  you can purchase the customized sensor using the link www.sunrom.com/.../ecg-bp

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • congkxtb95
    congkxtb95 over 1 year ago

    Can you share information about your BP sensor, how to buy or customize it ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vinayyn
    vinayyn over 1 year ago in reply to DAB

    Actually, it's my brother's hand he is now in primary school, hence the readings are good.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 1 year ago

    Your readings are significantly lower than mine.

    Given that I have several restricted arteries, you should be in great shape.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube