Projek : Heart Beat Monitoring System-Siri 1

Published by faiz on

Sharing is caring!

heart rateheart rateHeart Beat Monitoring System adalah projek yang memantau denyutan jantung seorang manusia dan seterusnya memaparkan pada display. Paparan display adalah menerusi PC (web browser).

Komponen yang diperlukan :

  • Heart beat sensor MAX30100
  • ESP8266 (nodeMcu Board)
  • ESP8266-01 module
  • Raspberry Pi (bertindak sebagai MQTT Broker dan Webserver)
  • OLED display
  • Display (PC, Smartphone dan lain-lain yang mempunyai web browser)
  • WiFi Connection

Secara ringkasnya adalah seperti rajah di bawah:

Heart beat

block diagram

Pertama sekali mulakan dengan sambungan litar :

projek heart beat skematik

NodeMCU MAX30100 OLED
3.3v VCC VCC
GND GND GND
D1 SCL SCL
D2 SDA SDA

Seterusnya, program ditulis menggunakan Arduino IDE. Sebelum menulis program, library berikut perlu diinstall terlebih dahulu:

Code untuk NodeMCU dengan menggunakan Arduino IDE adalah seperti berikut:

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "SSD1306.h"

#define REPORTING_PERIOD_MS 1000

// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
// * pin connection 4(SDA) and 5(SCL)
PulseOximeter pox;
// D4 -&amp;amp;amp;amp;amp;gt; SDA
// D5 -&amp;amp;amp;amp;amp;gt; SCL
SSD1306 display(0x3c, D2, D1);

uint32_t tsLastReport = 0;
volatile boolean heartBeatDetected = false;

// Callback method will be fired when a pulse is detected
void onBeatDetected() {
heartBeatDetected = true;
//Serial.println("Beat!");
}

void setup() {
Serial.begin(115200);

//Serial.print("Initializing pulse oximeter..");

// Initialize the PulseOximeter instance and register a beat-detected callback
pox.begin();

// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
display.init();
display.setFont(ArialMT_Plain_16);
}

void loop() {
// Make sure to call update as fast as possible
pox.update();

// Asynchronously dump heart rate and oxidation levels to the serial
// For both, a value of 0 means "invalid"
if (millis() - tsLastReport &amp;amp;amp;amp;amp;gt; REPORTING_PERIOD_MS) {
float bpm = pox.getHeartRate();
float spO2 = pox.getSpO2();
//float temp = pox.getTemperature();
//Serial.print("Heart rate:");
//Serial.print(bpm);
//Serial.print("bpm / SpO2:");
//Serial.print(spO2);
//Serial.println("%");

tsLastReport = millis();

// If the values are valid and heart beat detected, publish to Firebase
if (heartBeatDetected &amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp; bpm != 0) {
display.clear(); //have to clear display first
display.drawString(0, 0, "HR: " + String(bpm) + " bpm");
display.drawString(0, 20, "SpO2: " + String(spO2) + " %");
//display.drawString(0, 40, "Temp: " + String(temp) + " C");
display.display();
Serial.println(String(bpm) + "|" + String(spO2) + "|");
} else {
display.clear();
display.display();
}
}
}

Bersambung …

Sharing is caring!