IOT

ECG Display using Pulse Sensor with OLED & Arduino

The healthcare sector is being swiftly transformed by Arduino, IoT, and embedded systems, as well as a plethora of new healthcare technology start-ups. In this project, we’ll discover how to create an ECG display using an Arduino, OLED, and pulse sensor. For the display of BPM and ECG waveforms, we will use a 0.96′′ OLED Display with 128×64 resolution. Only 2 wires, SDA and SCK, are used by the I2C OLED for serial communication.

The various project functionalities are implemented by the Arduino Sketch running on the apparatus. This includes reading sensor data, translating it to strings, sending it through I2C communication, and displaying the measured pulse rate on an I2C OLED display.

Components Required:

  • Arduino Nano
  • Pulse Sensor
  • 0.96″ I2C OLED Displa
  • 5V Active Buzzer
  • Connecting Wires
  • Breadboard

Block Diagram:

For the OLED & Pulse Sensor, we require 2 different power supplies. Due to its 3.3 V & 5V output voltage, the Arduino UNO Board is a good source for these components. Pulse sensor can be linked to 5V and OLED to 3.3V.

Similar to a CPU, Arduino translates code into specified output. I2C communication is the basis for how the OLED Display functions. For displaying the defined output, only 2 wires are needed.

What is a Pulse Sensor and How does it Work?

A pulse sensor also known as a Heartbeat sensor or heart rate sensor used to determine live heart rate data. Nowadays Heart rate data is widely used in most electronics projects. The sensor works on the principle of reflection of light. The working of this sensor is by simply connecting it from the fingertip or human ear to the Arduino board. The 24-inch colour code cable with standard male header connectors makes an easy connection to Arduino or a Breadboard. The Heart logo on the side is made in contact with the skin. A small round hole, which is where the LED shines through from the back, and there is also a little square just under the LED. This square consists of an ambient light sensor, used to adjust the screen brightness in different light conditions.

This sensor consists of two surfaces. Firstly, the light-emitting diode & ambient light sensor is connected. Next, on the second surface, the circuit is connected which is accountable for the noise cancellation or amplification. Pulse Sensor Amped adds this circuitry to the hardware, thus providing fast and easy to get reliable pulse readings.

The LED on the small round hole is placed above a vein in a human body like anear fingertip. Once the LED is fixed on the vein, then the LED starts emitting light. When the heart is pumping, then there will be a flow of blood within the veins. As a result, if we check the blood flow, then we can check the heart rates also. When the blood flow is sensed, the ambient light sensor will receive more light as it will be reproduced by the flow of blood. Hence this small change within obtained light is used to determine pulse rate. The sensor attaches to a fingertip or earlobe and connects to Arduino via jumper cables. It also comes with an open-source monitoring app that displays your pulse in real-time on a graph.

Pulse-Sensor-Pin-Configuration:

The pulse sensor has three pins which are as described below:

  • Pin-1: GND: Black Colour Wire – Connected to the GND terminal
  • Pin-2: VCC: Red Colour Wire – Connected to the supply voltage ( +5V otherwise +3.3V)
  • Pin-3: Signal: Purple Colour Wire – Connected to the pulsating o/p signal.

0.96″ I2C OLED Display:

A 0.96-inch blue OLED display module is shown here. Using SPI/IIC protocols, the display module can be connected to any microcontroller. It has a 128 x 64 resolution. Display board, a display, and a pre-soldered 4-pin male header are all included in the kit.

OLED Display

A thin, multi-layered organic film sandwiched between an anode and a cathode makes up the OLED (Organic Light-Emitting Diode), a self-illuminating device. OLED technology does not need a backlight, in contrast to LCD technology. OLED is thought to be the best technology for the upcoming generation of flat-panel displays and has a great application potential for practically all types of displays.

Circuit Diagram & Connections:

Assemble the parts as described in the diagram below to create an ECG display using a pulse sensor, an OLED display, and an Arduino.

ECG Display using Pulse Sensor with OLED & Arduino
  • Join the GND and VCC pins of the pulse sensor to the Arduino’s 5V pin. Its signal pin is connected to Arduino Analog pin A0.
  • Similarly, join the GND and VCC pins of the OLED display to the 3.3V pin of the Arduino. SDA and SCK pins should be connected to Arduino pins A4 and A5, respectively.
  • Connect a buzzer to digital pin 8 on the Arduino and another pin to ground (GND).

Working & Setup:

  • Pulse Sensor:

The pulse sensor operates by sending an infrared signal to the skin via an IR-Diode. Blood is carried through capillaries that are located just beneath the skin. Blood flow and pressure slightly increase each time the heart beats. As a result, the capillaries enlarge somewhat and reflect more infrared light than they would at other times when the heart is not pumping blood through them. The device’s infrared detector detects the various IR levels that are reflected. This is transformed into a voltage signal by some straightforward comparator circuitry, which we can read using the Arduino’s analogue inputs.

  • OLED 128×64 (SSD1306 Driver) display:

In this project, we also display BPM on the OLED display and plot an ECG waveform. SSD1306 Driver & GFX Library are the two distinct libraries that are required for this. Make sure you first purchase an OLED 12868 I2C display (SSD1306 driver). It needs to be connected to four things: 5V, GND, SDA, and SCK.

  • OLED Address:

This OLED has a specific device address because it is an I2C OLED. First use the I2C Scanner application to scan the OLED in order to determine the I2C address. The OLED Display typically has a device address of either 0x3C or 0X3D.

  • Final Displayed Output:

When code is uploaded to an Arduino board, no graph or waveform is initially visible. However, when the finger is positioned, the BPM value is displayed, the graph is generated, and the Buzzer beeps. The value may be erratic or unstable at first for a short period of time, but eventually the value stabilises. Due to its low cost, the sensor is not very precise. Therefore, do not use it for medical needs.

ECG Display using Pulse Sensor with OLED & Arduino
ECG Display using Pulse Sensor with OLED & Arduino

Note: The Adafruit SSD1306.h file in your libraries folder has the following lines that cause the trace to be at the bottom of some OLED displays and the BPM to be absent.

#define SSD1306_128_64

// #define SSD1306_128_32

// #define SSD1306_96_16

Source Code/Program:

You must add two libraries to the ECG Display utilising Pulse Sensor with OLED & Arduino project. Download the library from here first, then.

  1. Adafruit SSD1306 Library
  2. Adafruit GFX Library

Now compile and upload this code to your Arduino IDE.

#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C // 0x3C device address of I2C OLED. Few other OLED has 0x3D
Adafruit_SSD1306 oled(128, 64); // create our screen object setting resolution to 128×64

int a=0;
int lasta=0;
int lastb=0;
int LastTime=0;
int ThisTime;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 560
#define LowerThreshold 530

void setup() {
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
oled.clearDisplay();
oled.setTextSize(2);
}

void loop()
{
if(a>127)
{
oled.clearDisplay();
a=0;
lasta=a;
}

ThisTime=millis();
int value=analogRead(0);
oled.setTextColor(WHITE);
int b=60-(value/16);
oled.writeLine(lasta,lastb,a,b,WHITE);
lastb=b;
lasta=a;

if(value>UpperThreshold)
{
if(BeatComplete)
{
BPM=ThisTime-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
tone(8,1000,250);
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((value<LowerThreshold)&(BPMTiming))
BeatComplete=true;

oled.writeFillRect(0,50,128,16,BLACK);
oled.setCursor(0,50);
oled.print(“BPM:”);
oled.print(BPM);

oled.display();
a++;
}

Leave a Reply

Your email address will not be published.