Sunday 14 February 2016

Eclipse Open IoT Challenge 2.0 - Update #7 : Now the doctor at distant knows your Heart Rate(bpm)

Whenever we visit a doctor , first and the foremost parameter which is recorded by the doctor is our heartbeat.As we are building a health monitoring device, it was very important that we include a heart rate sensor in our device too.

This post will guide you through the whole process:

Literature :
According to Wikipedia :
Heart rate is the speed of the heartbeat measured by the number of contractions of the heart per unit of time, typically beats per minute (bpm). The heart rate can vary according to the body's physical needs, including the need to absorb oxygen and excrete carbon dioxide. It is usually equal or close to the pulse measured at any peripheral point.

Why Heart Rate Sensor ?

Heart rate(pulse rate) is considered an important parameter for primary diagnosis due to following factors:
  • To see how well the heart is working. In an emergency situation, your pulse rate can help find out if the heart is pumping enough blood.
  • Help find the cause of symptoms, such as an irregular or rapid heartbeat (palpitations), dizziness, fainting, chest pain, or shortness of breath.
  • Check for blood flow after an injury or when a blood vessel may be blocked.
  • Check on medicines or diseases that cause a slow heart rate. Doctor may need to monitor patients pulse every day if the patient has a heart disease or if he/she is taking certain medicines that can slow the heart rate, such as digoxin or beta-blockers (such as atenolol or propranolol).
Principle of the sensor:

The heartbeat sensor is based on the principle of photo phlethysmography. It measures the change in volume of blood through any organ of the body which causes a change in the light intensity through that organ (a vascular region). In case of applications where heart pulse rate is to be monitored, the timing of the pulses is more important. The flow of blood volume is decided by the rate of heart pulses and since light is absorbed by blood, the signal pulses are equivalent to the heart beat pulses.

Descriptive diagram of Heart rate sensor


Working of Heart Rate sensor:

The basic heartbeat sensor consists of a light emitting diode and a detector like a light detecting resistor or a Photo diode. The heart beat pulses causes a variation in the flow of blood to different regions of the body.  When a tissue is illuminated with the light source, i.e. light emitted by the led, it reflects (a finger tissue) the light. Some of the light is absorbed by the blood and the transmitted or the reflected light is received by the light detector. The amount of light absorbed depends on the blood volume in that tissue. The detector output is in form of electrical signal and is proportional to the heart beat rate.

This signal is actually a DC signal relating to the tissues and the blood volume and the AC component synchronous with the heart beat and caused by pulsate changes in arterial blood volume is superimposed on the DC signal. Thus the major requirement is to isolate that AC component as it is of prime importance.
Schematic of the Hear Rate Module: Designed using EAGLE

Once the sensor is ready , we need to connect it to the Raspberry pi.

Note:Unlike beaglebone and Arduino , Raspberry Pi doesn't have any analog pins.Hence we need to connect an External ADC  such as MCP3008 to it.

Potentiometer is connected to Channel 0 of MCP3008, which is interfaced to Raspberry Pi 
MCP3008 is connected to Raspberry Pi using SPI protocol.
For Raspberry Pi B+ following is the pin configuration:
  • MCP3008 VDD -> 3.3V 
  • MCP3008 VREF -> 3.3V 
  • MCP3008 AGND -> GND 
  • MCP3008 CLK -> #14 (SCLK)
  • MCP3008 DOUT -> #13(MISO) 
  • MCP3008 DIN -> #12 (MOSI)
  • MCP3008 CS -> #10 (CE0)
  • MCP3008 DGND -> GND 
Once the hardware is ready , it's time to shift focus on the software.

On the software side we have a IBM IoT application that is developed with Reactive Blocks. The application runs on a Raspberry Pi with Eclipse Kura OSGi framework. Internet of Things (IoT) protocol MQTT is utilized to send data to IBM IoT foundation service.

In the IBM IoT application the heart rate data is sent continuously to the IBM Bluemix Foundation service via MQTT .

A brief description about the technologies used:

Kura:


Kura provides an OSGi-based container for IoT applications running in service gateways. By installing Kura on a device, not only can you turn it into a powerful IoT router that can be managed remotely, but you also have access to a complete application framework for deploying custom applications.
Learn more about Kura on the project’s website: http://www.eclipse.org/kura

MQTT:


Eclipse Paho is an open-source project that provides MQTT client implementations in many programming languages, and Kura is using Paho to provide high-level OSGi services for IoT communications between a gateway and the Internet.
Learn more about Paho on the project’s website: http://www.eclipse.org/paho

Reactive Blocks:


Reactive Blocks is an Eclipse plugin that helps developers create robust and flexible IoT applications block-by-block. This tool makes it straight-forward to express concurrency, an inherent property in IoT applications running on gateways which need to weave together streams of events.

For Kura, Reactive Blocks provides a special code generator, a library of building blocks for using Kura services and receiving configuration updates.

To explore more about Reactive Blocks and Kura follow these articles:
IBM IoT Foundation:


With the IBM Internet of Things Foundation you can collect event data from devices, forward it to other applications, and retrieve historical data.
For getting started with IBM IoT foundation , visit following link: IBM IoT Cloud

Finally , how the application was built:

For building the application which records ADC values and then sends it to IBM Foundation Cloud using MQTT , Reactive Blocks were used.


  1. Initialize the "IBM IoT Quickstart" block with a manual/random device id.
  2. Once the device is registered, the "IBM IoT Quickstart" Block generates a URI corresponding to it, which is then passed to "Open Browser" block which opens it in the browser(optional if you are running the application on Raspberry Pi)
  3. Set the Sampling rate for ADC
  4. The "GP2Y0A21YK0F" block fetches the data from ADC using MCP3008 block and passes it to the adcEvent operation.
  5. The adcEvent operation converts the double value into an event object, which is then send to the IBM IoT cloud by MQTT using IBM IoT Quickstart block.
Build and Deploy:

After building the application you need to upload it on the Raspberry Pi.

For building a kura based application , follow the link:http://reference.bitreactive.com/reference/develop-kura-app.html



Note:In addition to the application deployment package, you also need to deploy Reactive Blocks libraries and runtime bundles. This can be found in as a deployment package ReactiveBlocksLibraries.dp in the project target-definition-with-rb of your Package Explorer window.

Once the Kura application is successfully build,follow the instructions below:

  • Open the Kura's web console of your Raspberry Pi.
  • Choose Packages section on the left menu.
  • Install the two deployment packages: ReactiveBlocksLibraries.dp and HeartBeat.dpp
  • You might need to use the refresh button in order to see packages you installed.
Output on the Bluemix console:


Once the bundle is installed on the raspberry, output can be seen on the IBM Internet of Things Foundation Quickstart service .
Note: If you manually assigned a deviceid to your application , you need to enter it on the webpage.


Other Resources(You may find Useful):
In coming week we would be uploading more information about other sensors.








1 comment:

  1. This comment has been removed by the author.

    ReplyDelete