Sadiya Chowdhry
Published © GPL3+

Heart rate monitor using Embware sensor and Bolt wifi module

This project measures heart rate using plethysmography and gives the result in bpm in the form of a gauge chart and an SMS alert.

IntermediateFull instructions provided10 hours1,185

Things used in this project

Hardware components

Embware Iron Heart Beat Sensor
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
SMS Messaging API
Twilio SMS Messaging API
Plotly - free and open-source graphing library for Python

Story

Read more

Schematics

Circuit Connections

The jumper colors correspond to the ones mentioned in the story as well as images for ease of relation.

Code

conf.py

Python
Configuration code
SSID = 'XXXX'
AUTH_TOKEN = 'XXXX'
FROM_NUMBER = 'XXXX'
TO_NUMBER = 'XXXX'
API_KEY = 'XXXX'
DEVICE_ID = 'XXXX'

heartrate.py

Python
Main code
#importing required libraries
from boltiot import Bolt
from boltiot import Sms
import conf
import json
import time
import plotly.io as pio
import plotly.graph_objects as go


#fetching credentials from conf.py
myBolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SSID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)


#initialization of variables
minimum_limit = 57
maximum_limit = 100
highCounter = 0
pulse = 0
val = 0
lastPulse = "LOW"
oldmillis = int(round(time.time()*1000))


print("\nMaking sure you are not a Zombie...")


#reading sensor value and processing it
while True :
	pulse = myBolt.digitalRead('0')
	if pulse != lastPulse :
		lastPulse = pulse
		c=pulse.count('1')
		if c == 2 :
			highCounter += 1
		millis = int(round(time.time()*1000))
		if millis - oldmillis >= 10000 :
			oldmillis = millis
			val = highCounter*6
			if highCounter > 1 :
				print("\nYOUR HEART RATE IS : "+str(val)+" bpm")
				highCounter = 0
				sensor_value = int(val)


#comparing reading with standard range and sending twilio alerts
				try :
					sensor_value = int(val)
					if sensor_value > maximum_limit :
						print("\nYour heart rate is above the maximum threshold")
						print("\nMaking request to Twilio to send an SMS...")
						response = sms.send_sms("Critical Alert! Your current Heart rate is "+str(sensor_value))
						print("\nMessage sent successfully. Press ^C to Exit")
					elif sensor_value < minimum_limit :
						print("\nYour heart rate is below the minimum threshold")
						print("\nMaking request to Twilio to send an SMS...")
						response = sms.send_sms("Critical Alert! Your current Heart rate is "+str(sensor_value))
						print("\nMessage sent successfully. Press ^C to Exit")
					else :
						print("\nYour heart rate is within the normal range")
						print("\nMaking request to Twilio to send an SMS...") 
						response = sms.send_sms("Alert. Your current Heart rate is "+str(sensor_value))
						print("\nMessage sent successfully. Press ^C to Exit")

				except Exception as e :
					print(e)


#plotly gauge graph specifications
				fig = go.Figure(go.Indicator(
					mode = "gauge+number+delta",
					value = sensor_value,
					domain = {'x' : [0,0.5], 'y' : [0,0.5]},
					title = {'text' : "Heart Rate", 'font' : {'size' : 25}},
					gauge = {
						'axis' : {'range' : [27, 130], 'tickwidth' : 1, 'tickcolor' : "darkblue"},
						'bar' : {'color' : "darkblue"},
						'bgcolor' : "white",
						'borderwidth' : 2,
						'bordercolor' : "gray",
						'steps' : [
							{'range' : [27,57], 'color' : 'red'},
							{'range' : [57, 100], 'color' : "green"},
							{'range' : [100, 130], 'color' : "red"}],
						'threshold' : {
							"line" : {'color' : "green", "width" :1},
							'thickness' : 0.15,
							'value': 75}}))
				fig.update_layout(paper_bgcolor = "lavender", font = {'color' : "black", 'family' : "Arial"})
				fig.show()

				time.sleep(20)

Credits

Sadiya Chowdhry

Sadiya Chowdhry

1 project • 1 follower
Thanks to Bolt Documentation.

Comments