Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
vinay y.n
Published © GPL3+

Blood Pressure Sensor Interfacing with Raspberry Pi

Blood pressure measuring and Detailed Report Emailing system using Raspberry Pi.

IntermediateFull instructions provided6 hours9,702
Blood Pressure Sensor Interfacing with Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
Capacitor 470 µF
Capacitor 470 µF
×1
5 mm LED: Red
5 mm LED: Red
×1
Bridge rectifier
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
Blood Pressure Sensor
×1
Through Hole Resistor, 470 ohm
Through Hole Resistor, 470 ohm
×1
DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
TaydaElectronics DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
×1
5 volt 2 amp dc adapter for raspberry pi
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Schematics

SCHEMATIC

Code

project code

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

Credits

vinay y.n

vinay y.n

26 projects • 45 followers
An electronic product engineer with 8 years of experience in the field. The passion for electronics began as a hobby 11 years ago.

Comments