Arduino Nano Heart Rate and SpO2 Monitor with OLED Display and Alarm
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit designed to measure heart rate and SpO2 levels using a MAX30102 sensor, display the data on a 128x64 OLED display, and trigger a piezo speaker and vibration motor if the heart rate is outside predefined limits. The circuit is controlled by an Arduino Nano microcontroller.
Component List
MAX30102
- Description: Heart rate and SpO2 sensor.
- Pins: VIN, SDA, SCL, GND, RD, IRD, INT
Piezo Speaker
- Description: Audio output device.
- Pins: pin1, pin2
Vibration Motor
- Description: Provides haptic feedback.
- Pins: +, -
Arduino Nano
- Description: Microcontroller board.
- Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
128x64 OLED Display (I2C IIC SPI Serial)
- Description: Display module for visual output.
- Pins: GND, SDA, SCL, VCC
Wiring Details
MAX30102
- VIN connected to 5V of Arduino Nano
- SDA connected to A6 of Arduino Nano
- SCL connected to A7 of Arduino Nano
- GND connected to GND of Arduino Nano
Piezo Speaker
- pin1 connected to GND of Arduino Nano
- pin2 connected to 5V of Arduino Nano
Vibration Motor
- + connected to 3V3 of Arduino Nano
- - connected to GND of Arduino Nano
Arduino Nano
- GND connected to GND of MAX30102, Piezo Speaker, Vibration Motor, and OLED Display
- 5V connected to VIN of MAX30102 and VCC of OLED Display
- A6 connected to SDA of MAX30102
- A7 connected to SCL of MAX30102
- A4 connected to SDA of OLED Display
- A5 connected to SCL of OLED Display
- D4 (BUZZER_PIN) connected to Piezo Speaker
- D5 (VIBRATION_MOTOR_PIN) connected to Vibration Motor
128x64 OLED Display (I2C IIC SPI Serial)
- GND connected to GND of Arduino Nano
- SDA connected to A4 of Arduino Nano
- SCL connected to A5 of Arduino Nano
- VCC connected to 5V of Arduino Nano
Code Documentation
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MAX30105.h>
#include "spo2_algorithm.h"
// Konfigurasi OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Pin untuk buzzer dan motor getar
#define BUZZER_PIN 4
#define VIBRATION_MOTOR_PIN 5
MAX30105 particleSensor;
// Buffer data
uint16_t irBuffer[100];
uint16_t redBuffer[100];
int32_t spo2;
int8_t validSPO2;
int32_t heartRate;
int8_t validHeartRate;
// Batas detak jantung
const int HEART_RATE_MAX = 120;
const int HEART_RATE_MIN = 50;
void setup() {
Serial.begin(9600);
// Inisialisasi OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.display();
// Inisialisasi sensor MAX30105
if (!particleSensor.begin(Wire, I2C_SPEED_STANDARD)) {
Serial.println("MAX30105 tidak terdeteksi. Periksa koneksi.");
while (1);
}
// Atur pengambilan data sensor
particleSensor.setPulseAmplitudeRed(0x0A); // Mengatur kekuatan LED merah
particleSensor.setPulseAmplitudeIR(0x0A); // Mengatur kekuatan LED inframerah
// Atur pin sebagai output
pinMode(BUZZER_PIN, OUTPUT);
pinMode(VIBRATION_MOTOR_PIN, OUTPUT);
}
void loop() {
// Baca data dari sensor
for (byte i = 0; i < 100; i++) {
while (particleSensor.check() == false); // Tunggu data tersedia
irBuffer[i] = (uint16_t)particleSensor.getIR();
redBuffer[i] = (uint16_t)particleSensor.getRed();
}
// Hitung SpO2 dan detak jantung
maxim_heart_rate_and_oxygen_saturation(irBuffer, 100, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
// Tampilkan data di OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Heart Rate: ");
if (validHeartRate) {
display.print(heartRate);
display.println(" BPM");
} else {
display.println("-- BPM");
}
display.setCursor(0, 16);
display.print("SpO2: ");
if (validSPO2) {
display.print(spo2);
display.println("%");
} else {
display.println("--");
}
// Cek kondisi dan aktifkan alarm jika detak jantung di luar batas
if (validHeartRate && (heartRate > HEART_RATE_MAX || heartRate < HEART_RATE_MIN)) {
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(VIBRATION_MOTOR_PIN, HIGH);
delay(500);
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(VIBRATION_MOTOR_PIN, LOW);
}
display.display();
delay(1000);
}
This code initializes the OLED display and MAX30105 sensor, reads heart rate and SpO2 data, displays the data on the OLED, and triggers the piezo speaker and vibration motor if the heart rate is outside the predefined limits.