Setting Up Your Arduino Pulse Sensor Project
Are you ready to start your Arduino Pulse Sensor project? This guide will walk you through the necessary connections and library installations to get your project up and running smoothly.
[1] Hardware Connections:-
1. Pulse Sensor:
- Power Supply:
- The Pulse Sensor module can be supplied with either 3.3V or 5V.
- Connect the positive voltage to the ‘+’ pin.
- Connect the ground to the ‘-’ pin.
- Analog Signal:
- The third wire, labeled ‘S,’ is the analog signal output from the sensor.
- Connect this wire to the Arduino’s A0 analog input.
2. I2C Module:
- Power Supply:
- Connect the *VCC* pin of the I2C module to the *VIN* or *5V* pin on the Arduino.
- Connect the *GND* pin to the *GND* pin on the Arduino.
- Data Lines:
- Connect the *SCL* pin to the *A5* pin on the Arduino.
- Connect the *SDA* pin to the *A4* pin on the Arduino.
If you face any problem while making project then you can watch the video!
[2] Library Installation:-
To run the following sketches, you must first install the ‘PulseSensor Playground’ library. Follow these steps to install the necessary library:
1. Open the Arduino IDE.
2. Navigate to **Sketch > Include Library > Manage Libraries…**
3. Wait for the Library Manager to download the libraries index and update the list of installed libraries.
4. In the Library Manager's search bar, type ‘pulsesensor’ to filter your search.
5. There should be a single entry named ‘PulseSensor Playground.’ Click on it.
6. Click the ‘Install’ button to install the library.
Now, you're all set to start coding for your project!
[3] Sample Code:
Here is a sample code to get you started with your Pulse Sensor project. This code reads the analog signal from the Pulse Sensor and prints the values to the Serial Monitor.
NOTE:- This code will not work with I2c module [For codes with I2c module scroll down ].
#include <PulseSensorPlayground.h>
// Pulse Sensor Variables
const int PulseWire = A0; // Pulse Sensor connected to Analog Pin 0
const int LED13 = 13; // The on-board Arduino LED, close to pin 13
int Threshold = 550; // Determine which Signal to count as a beat
PulseSensorPlayground pulseSensor; // Create an instance of the PulseSensorPlayground object
void setup() {
pinMode(LED13, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Start the Serial communication
// Initialize the PulseSensor instance
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13);
pulseSensor.setThreshold(Threshold);
// Check if PulseSensor initialization was successful
if (pulseSensor.begin()) {
Serial.println("PulseSensor successfully initialized");
} else {
Serial.println("PulseSensor initialization failed");
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute(); // Calculate the Beats Per Minute (BPM)
// Print BPM value to the Serial Monitor if it's above 0
if (pulseSensor.sawNewBeat()) {
Serial.print("BPM: ");
Serial.println(myBPM);
}
delay(20); // Small delay to avoid overwhelming the Serial Monitor
}
Upload this code to your Arduino, open the Serial Monitor, and you should start seeing your pulse rate displayed. Enjoy working on your Pulse Sensor project!
[4] Codes for Project with I2c:-
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with the correct I2C address (found using the scanner)
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD's address
// Pulse Sensor connections
const int pulsePin = A0; // Pulse sensor connected to analog pin A0
// Variables to store pulse data
int pulseValue = 0;
int threshold = 512; // Initial threshold value
boolean pulseDetected = false;
unsigned long lastBeatTime = 0;
unsigned int beatsPerMinute = 0;
unsigned int beatCounter = 0;
void setup() {
// Initialize the LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Pulse Rate:");
// Initialize Serial Monitor for debugging
Serial.begin(9600);
// Configure pulse sensor pin
pinMode(pulsePin, INPUT);
}
void loop() {
// Read the pulse sensor value
pulseValue = analogRead(pulsePin);
// Check for pulse detection
if (pulseValue > threshold && !pulseDetected) {
pulseDetected = true;
unsigned long currentTime = millis();
unsigned long beatDuration = currentTime - lastBeatTime;
lastBeatTime = currentTime;
if (beatDuration > 0) {
beatsPerMinute = 60000 / beatDuration;
}
beatCounter++;
// Display the pulse rate on the LCD
lcd.setCursor(0, 1);
lcd.print("BPM: ");
lcd.print(beatsPerMinute);
lcd.print(" "); // Clear any previous values
}
// Reset pulse detection
if (pulseValue < threshold) {
pulseDetected = false;
}
// Debugging info in Serial Monitor
Serial.print("Pulse Value: ");
Serial.print(pulseValue);
Serial.print(" BPM: ");
Serial.println(beatsPerMinute);
delay(20); // Small delay to stabilize readings
}


Thank you
ReplyDelete