ECG Display using Pulse Sensor with OLED & Arduino
With tons of new healthcare technology start-ups, Arduino along with IoT and Embedded System is rapidly revolutionizing the healthcare industry. In this project, we will learn how to design ECG Display using Pulse Sensor with OLED & Arduino. We will use 0.96″ OLED Display with 128×64 resolution for BPM & ECG waveform display. The I2C OLED uses only 2 wire, i.e SDA & SCK for serial communication.
The Arduino Sketch running over the device implements the various functionalities of the project. These functions are reading sensor data, converting them into strings, passing them to I2C communication, and displaying measured pulse rate in I2C OLED Display.
Before starting, you can check our previous projects related to Pulse Sensor if you are a beginner:
1.Heartbeat/Pulse/BPM Rate Monitor using Arduino & Pulse Sensor.
2.Pulse Rate Monitoring over Internet using ThingSpeak & ESP8266.
3.IoT Based Patient Health Monitoring System using ESP8266 & Arduino.
Block Diagram:
We need 2 different power Supply, each for OLED & Pulse Sensor. We can get these supplies from Arduino UNO Board as it has 3.3 V & 5V output voltage. OLED can be connected to 3.3V & Pulse Sensor to 5V.
Similarly, Arduino acts as a processor and converts code into predefined output. The OLED Display works on the principle of I2C Communication. It requires only 2 wires for displaying the defined output.
Components Required:
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | Arduino Nano Board | 1 | Amazon | AliExpress |
2 | Pulse Sensor | 1 | Amazon | AliExpress |
4 | 0.96" I2C OLED Display | 1 | Amazon | AliExpress |
5 | Buzzer 5V | 1 | Amazon | AliExpress |
6 | Connecting Wires | 10 | Amazon | AliExpress |
7 | Breadboard | 1 | Amazon | AliExpress |
Pulse Sensor:
The Pulse Sensor is a plug-and-play heart-rate sensor for Arduino. It can be used by students, artists, athletes, makers, and game & mobile developers who want to easily incorporate live heart-rate data into their projects. The essence is an integrated optical amplifying circuit and noise eliminating circuit sensor. Clip the Pulse Sensor to your earlobe or fingertip and plug it into your Arduino, you can ready to read heart rate. Also, it has an Arduino demo code that makes it easy to use.
The pulse sensor has three pins: VCC, GND & Analog Pin.
There is also a LED in the center of this sensor module which helps in detecting the heartbeat. Below the LED, there is a noise elimination circuitry that is supposed to keep away the noise from affecting the readings.
0.96″ I2C OLED Display:
This is a 0.96 inch blue OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128×64. The package includes display board, display,4 pin male header pre-soldered to board.
OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.
Circuit Diagram & Connections:
To design ECG Display using Pulse Sensor with OLED & Arduino, assemble the components as shown in the figure below.
Connect pulse sensor VCC pin to Arduino 5V Pin and GND to GND. Connects its signal pin to Arduino Analog pin A0.
Similarly connect the VCC Pin of OLED Display to Arduino 3.3V pin and GND to GND. Connect its SDA & SCK pins to Arduino A4 & A5 pins respectively.
Connect a buzzer to Arduino digital pin 8 and another pin to GND.
Working & Setup:
Pulse Sensor:
The pulse sensor works by emitting an Infra-Red signal from an IR-Diode onto the skin. Just underneath the skin, there are capillaries carrying blood. Every time heart pumps there is a small increase in blood flow/pressure. This swells the capillaries slightly, this slightly more filled capillary reflects more infra-red than at times when the heart is not giving your blood a “push”. An Infra-detector on the device senses the different reflected IR levels. Some simple comparator circuitry converts this into a voltage signal which we can read with the Arduino Analog inputs.
OLED 128×64 (SSD1306 Driver) display:
In this project, we’re adding an ECG waveform plotter along with BPM on the OLED display. For this we need 2 different library, i.e SSD1306 Driver & GFX Library. Firstly ensure you’ve bought an OLED 128×68 I²C display (SSD1306 driver) display. It should have four connections, i.e 5V, GND, SDA, and SCK.
OLED Address:
Since the OLED used here is an I2C OLED, so it has a particular device address. To find the I2C address first scan the OLED with the I2C Scanner program. Normally the OLED Display has a device address of 0x3C or 0X3D.
Final Displayed Output:
After code is uploaded to Arduino Board, at first no graph or waveform is seen. But when the finger is placed the BPM value is displayed as well as the graph is drawn along with the beep sound from Buzzer. The value may be irregular or unstable at starting for few seconds but later the value becomes stables. The sensor is not too accurate as it is cheap. So do not use it for medical purposes.
Note: For some OLED there is a problem with the trace being at the bottom and the BPM being missing then this is caused by the following lines in the Adafruit_SSD1306.h file in your libraries folder :
#define SSD1306_128_64
// #define SSD1306_128_32
// #define SSD1306_96_16
Source Code/Program:
For the project ECG Display using Pulse Sensor with OLED & Arduino, you need to add 2 libraries. So first download the library from here.
1. Adafruit SSD1306 Library
2. Adafruit GFX Library
Now compile and upload this code to your Arduino IDE.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#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 128x64 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++; } |
Video Tutorial & Explanation:
The video tutorial for ECG Display using Pulse Sensor with OLED & Arduino is given below. Watch the fulll video for setup & understanding.
10 Comments
if i was using 3.3 volt, which part of the code i need to change?
No
how to add in LED when pulse is detected and monitor tab code?
It completes to understand the project,
HI, great poject
for sh1106 how should i change the code?
Can anyone help me explain the code
is the librarys compatible with mplabs using a pick it 3?
hallo,
please can you send a photo which explain what will be displayed on the LCD screen?
(heart logo or BPM or sentence)
please explain me if you are understand it
I can get synopsis for this project