This circuit integrates an Arduino Nano microcontroller with a 0.96" OLED display, a Heart Pulse Sensor, and a power supply consisting of a 3.7v LiPo battery. A toggle switch is included to control the power flow, and a resistor is used for current limiting or pull-up/down purposes. The Arduino Nano is programmed to read the pulse signal from the Heart Pulse Sensor and display the beats per minute (BPM) on the OLED screen. An LED on the Arduino Nano blinks with each detected heartbeat.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PulseSensorPlayground.h>
#define OLED_RESET -1 // Reset pin not used
Adafruit_SSD1306 display(OLED_RESET);
const int PulseWire = A0; // Analog pin connected to Heart Pulse Sensor
const int LED13 = 13; // Onboard LED
int Threshold = 550; // Threshold value for detecting a heartbeat
PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object
void setup() {
pinMode(LED13, OUTPUT); // Set the onboard LED as an output
display.begin(SSD1306_I2C_ADDRESS, 0x3C); // Initialize the OLED display
display.clearDisplay();
display.setTextColor(WHITE);
pulseSensor.analogInput(PulseWire); // Configures the pin to read the pulse signal
pulseSensor.setThreshold(Threshold); // Sets the threshold for detecting a beat
// Check if the pulse sensor is ready and display a message on the OLED
if (pulseSensor.begin()) {
displayMessage("Pulse Sensor Ready!");
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute(); // Read the BPM from the sensor
// If a beat is detected, blink the LED and display the BPM on the OLED
if (pulseSensor.sawStartOfBeat()) {
digitalWrite(LED13, HIGH);
delay(50);
digitalWrite(LED13, LOW);
displayBPM(myBPM);
}
delay(20); // Short delay for loop stability
}
// Function to display a message on the OLED
void displayMessage(String message) {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print(message);
display.display();
}
// Function to display the BPM value on the OLED
void displayBPM(int bpm) {
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 10);
display.print("BPM: ");
display.print(bpm);
display.display();
}
This code initializes the OLED display and the pulse sensor, then continuously reads the BPM and displays it on the OLED. The onboard LED blinks with each detected heartbeat.