Vasanth VaseemusthafaVinoth RJ (Agent Angel 97)
Published © GPL3+

Heart Rate Monitor Using IoT

This project displays the heart rate at the unit of beats per minute over the Internet so that it can be monitored from anywhere.

IntermediateFull instructions provided3 hours57,266
Heart Rate Monitor Using IoT

Things used in this project

Story

Read more

Schematics

circuit Diagram

Code

IR_Pulsr.ino

Arduino
This is the code that must be uploaded into the arduino
int UpperThreshold = 518;
int LowerThreshold = 490;
    int reading = 0;
    float BPM = 0.0;
    bool IgnoreReading = false;
    bool FirstPulseDetected = false;
    unsigned long FirstPulseTime = 0;
    unsigned long SecondPulseTime = 0;
    unsigned long PulseInterval = 0;

    void setup(){
      Serial.begin(9600);
    }

    void loop(){

      reading = analogRead(0); 
      if(reading > UpperThreshold && IgnoreReading == false){
        if(FirstPulseDetected == false){
          FirstPulseTime = millis();
          FirstPulseDetected = true;
        }
        else{
          SecondPulseTime = millis();
          PulseInterval = SecondPulseTime - FirstPulseTime;
          FirstPulseTime = SecondPulseTime;
        }
        IgnoreReading = true;
      }
      if(reading < LowerThreshold){
        IgnoreReading = false;
      }  

      BPM = (1.0/PulseInterval) * 60.0 * 1000;
       // uncomment these lines in case you want to view the various values in the console.....
      /*Serial.print(reading);
      Serial.print("\t");
      Serial.print(PulseInterval);
      Serial.print("\t");*/
      Serial.print(BPM);
      Serial.println(" BPM");
      Serial.flush();
    }

run.js

JavaScript
this contains the code to establish an connection between serial data and the server........
var SerialPort = require('serialport')
var Readline = SerialPort.parsers.Readline
var express = require('express');
var socket = require('socket.io');

var app = express();
var server = app.listen(3005);

app.use(express.static('public'));

var io = socket(server);

io.on('connection', function(socket){
    
    console.log(socket.id);
    
});

var serialPort = new SerialPort('/dev/tty.usbmodem1421', {
  baudRate: 9600
})

var parser = new Readline()
serialPort.pipe(parser)
parser.on('data', function (data) {
  //console.log('data received: ' + data)
  io.sockets.emit('map', data);
})

serialPort.on('open', function () {
  console.log('Communication is on!')
})

page.html

HTML
This is the web page which is gonna display the number of heart beats per minute in it.
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
         <script src='nerve.js'></script>
        <script src='speech.js'></script>
        <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1" />
         <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.0/socket.io.dev.js"></script>
        <title></title>
        <style>
            body
            {
                margin: 0;
                background-image: url('https://www.skipprichard.com/wp-content/uploads/2015/07/bigstock-Red-Heart-On-Wooden-Background-56485448.jpg')
            }
            #speech
            {
                overflow: auto;
            }
            .sender
            {
                border-bottom-right-radius: 5px;
                border-top-right-radius: 5px;
                border-top-left-radius: 5px;
                text-align: left;
                background-color: yellow;
            }
            .receiver
            {
                border-bottom-left-radius: 5px;
                border-top-right-radius: 5px;
                border-top-left-radius: 5px;
                text-align: right;
                background-color: white;
            }
            .bub
            {
                border: 1px solid #000;
                padding: 5px;
                margin-right: auto;
                margin-left: auto;
                width: 90%;
                max-width: 500px;
            }
            #name
            {
                font-family: arial;
                font-size: 20px;
                color: black;
                white-space: nowrap;
                font-weight: 600;
            }
            #rank
            {
                font-family: arial;
                font-size: 15px;
                color: black;
                white-space: nowrap;
            }
            .bubble
            {
                font-family: arial;
                font-size: 20px;
                font-weight: 400;
            }
            .dot
            {
                width: 10px;
                height: 10px;
                margin-left: auto;
                border-radius: 5px;
            }
            .read
            {
                border: 1px solid red;
            }
            .red
            {
                background-color: red;
            }
            .yellow
            {
                background-color: gold;
            }
            .green
            {
                background-color: green;
            }
            #stat
            {
               padding: 10px;
                margin-right: auto;
                margin-left: auto;
                width: 90%;
                max-width: 500px;
            }
            #nav
            {
                border-bottom: 1px solid #000;
                width: 100%;
                text-align: left;
                background-color: white;
                padding-bottom: 3px;
            }
            #photo
            {
                position: relative;
                top: 4px;
                left: 5px;
                border-radius: 40px; 
                height: 80px;
                float: left;
            }
            .time
            {
                font-weight: 400;
                font-family: arial;
            }
            #online
            {
                color: green;
            }
            #offline
            {
                color: red;
            }
            #foot
            {
                border-top: 1px solid #000;
                
                width: 100%;
                position: fixed;
                bottom: 0;
                background-color: white;
                padding: 10px;
            }
            #box
            {
                border: none;
                resize: none;
                width: 75%;
                
                font-weight: 400;
                font-size: 20px;
                font-family: arial;
                overflow: hidden;
            }
            #enter
            {
                border:0;
                background-color: white;
                color: #0BB5FF;
                font-size: 20px;
            }
            h1
            {
                padding-top: 100px;
                font-family: monospace;
                text-align: center;
                font-size: 100px;
            }
        </style>
    </head>
    <body>
        <h1 id="hello"></h1>
        <script>
            var socket = io.connect("http://localhost:3005");
            var socket_1 = io.connect("http://ec2-18-220-142-52.us-east-2.compute.amazonaws.com:4000");//give the link generated by the AWS after turning on for linking code with internet....
         
            socket.on('map', function(data){
                 //console.log(data);
                 
                 socket_1.emit('map', data);
                 document.getElementById('hello').innerHTML = data;
            });            
        </script>
    </body>
</html>

Credits

Vasanth Vasee

Vasanth Vasee

2 projects • 19 followers
HOBBYIST ,QUICK LEARNER , EAGER TO LEARN AND EXPLORE A LOT IN ELECTRONICS TECHNOLOGY AND AI SYSTEMS.......
musthafa

musthafa

1 project • 4 followers
Vinoth RJ (Agent Angel 97)

Vinoth RJ (Agent Angel 97)

1 project • 3 followers

Comments