Arduino Heartbeat Monitoring System
Components Needed
- Arduino Uno/Nano
- KY-039 Heartbeat Sensor
- DS18B20 Temperature Sensor
- 128x64 OLED Display (SSD1306, I2C)
- 4.7kΩ Resistor
- Breadboard and Jumper Wires
Wiring Instructions
DS18B20 Temperature Sensor
- VCC → 5V
- GND → GND
- Data → D2
- 4.7kΩ resistor between Data and VCC
KY-039 Heartbeat Sensor
- Signal → A0
- VCC → 5V
- GND → GND
OLED Display (SSD1306 I2C)
- SDA → A4(On a MEGA or Leonardo SDA goes to pin 20)
- SCL → A5 (On a MEGA or Leonardo SCL to pin 21.
- VCC → 5V
- GND → GND
Required Libraries
- Adafruit_GFX
- Adafruit_SSD1306
- OneWire
- DallasTemperature
Arduino Code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define HEART_PIN A0
int signal;
unsigned long lastBeat = 0;
int bpm = 0;
int beatCount = 0;
unsigned long startTime;
void setup() {
Serial.begin(9600);
sensors.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("OLED failed");
while (true);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
startTime = millis();
}
void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
signal = analogRead(HEART_PIN);
if (signal > 512 && (millis() - lastBeat) > 300) {
lastBeat = millis();
beatCount++;
}
if (millis() - startTime >= 10000) {
bpm = beatCount * 6;
beatCount = 0;
startTime = millis();
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("Heartbeat Monitor");
display.print("Temp: ");
display.print(temperature);
display.println(" C");
display.print("Signal: ");
display.println(signal);
display.print("BPM: ");
display.println(bpm);
display.display();
delay(100);
}
Notes
- Keep finger steady on the KY-039 sensor for accurate reading.
- Use good lighting conditions to reduce noise in heartbeat signal.
- Advanced implementations can include digital filters or use more accurate pulse sensors.