Week 4 18bce118

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 18

PULSE RATE SENSOR

Submitted by

ASHIQ – 18BLC
R.VIGNESH– 18BEC
VAISHNAVI – 18BEC

GOKUL-18BLC

YESHWANT PREM-18BLC

ECE1005 – Sensors and Instrumentation


ACKNOWLDGEMENT

I sincerely express my gratitude to those who helped me in the


completion of this project. I thank my faculty Peer Fathima mam
in guiding me with this project. This project helped me learn a
lot about sensors and its applications . It gave me a wide view on
real life sensors and it contribution in technology . I thank my
team members for their contribution without whom this project
would not have been possible . I also thank my parents for
motivating me to do this project . I would take up more sensors
project in future to get a better and deeper understanding about
the subject . I also thank VIT UNIVERSITY for incorporating
projects with learning which makes us outstanding engineers .
CIRCUIT DIAGRAM

CONNECTIONS:
• Signal pin of Pulse Rate Sensor to A0 of the Arduino
• VCC pin of Pulse Rate sensor to 5V supply of the Arduino
• GND pin to the GND of the Arduino
• VSS, K of the LCD to the GND of Arduino and the 10k potentiometer
• A and VDD of the LCD to the 5V supply of the Arduino
• VO of the LCD to the 10k potentiometer
• RS of LCD to pin 12 on the Arduino
• RW of the LCD to the GND of the Arduino
• E of the LCD to pin 11 of the Arduino
• D4, D5, D6, D7 of the LCD to 5, 4, 3, 2 pins of the Arduino
COMPONENTS:

• Arduino UNO R3
• Breadboard
• Jumper Wires
• Pulse Rate Sensor
• LCD 16 x 2 display
• 16x2 LCD Base

BLOCK DIAGRAM:
COST OF THE PROJECT (INR)

Arduino – 460/-

Breadboard – 50/-

Pulse Rate Sensor – 300/-

LCD Base – 80/-

LCD Display – 100/-

Jumper Wires – 60/-

TOTAL - 1050 INR /-


SPECIFICATIONS:
Arduino:

• Microcontroller: ATmega328P
• Operating Voltage: 5V
• Input Voltage (recommended): 7-12V
• Inout Voltage (limit): 6-20V
• Digital I/O Pins: 14 (of which 6 provide PWM output)
• PWM Digital I/O Pins: 6
• Analog Input Pins: 6
• DC Current per I/O Pin: 20 mA
• DC current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB (ATmega328P) of which 0.5 KB used by bootloader
• SRAM: 2 KB (ATmega328P)
• EEPROM: 1 KB (ATmega328P)
• Clock Speed: 16 MHz
• LED_BUILTIN: 13
• Length: 68.6 mm
• Width: 58.4 mm
• Weight: 25 g
Powering up the Arduino:

The Arduino Uno board can be powered via a USB connection or with an external
power supply. The power source is selected automatically. External (non-USB)
power can come either from an AC-to-DC adapter (wall-wart) or battery. The
adapter can be connected by plugging a 2.1mm center-positive plug into the
board's power jack. Leads from a battery can be inserted in the GND and Vin pin
headers of the POWER connector. The board can operate on an external supply
from 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply
less than five volts and the board may become unstable. If using more than 12V,
the voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.

The power pins are as follows:

• Vin. The input voltage to the Arduino/Genuino board when it's using an external
power source (as opposed to 5 volts from the USB connection or other regulated
power sources). You can supply voltage through this pin, or, if supplying
voltage via the power jack, access it through this pin.
• 5V.This pin outputs a regulated 5V from the regulator on the board. The board
can be supplied with power either from the DC power jack (7 - 12V), the USB
connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via
the 5V or 3.3V pins bypasses the regulator, and can damage your board. We
don't advise it.
• 3V3. A 3.3 volt supply generated by the on-board regulator. The maximum
current draw is 50 mA.
• GND. Ground pins.
Pulse Rate Sensor:

• Operating voltage: 3.3V – 5V


• Current: 4mA
• Indicator LED

The Pulse Sensor can be connected to Arduino, or plugged into a breadboard. The
front of the sensor is the pretty side with the Heart logo. This is the side that makes
contact with the skin. On the front you see 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. The square is an ambient light sensor, exactly like the one used in
cellphones, tablets, and laptops, to adjust the screen brightness in different light
conditions. The LED shines light into the fingertip or earlobe, or other capillary
tissue, and sensor reads the light that bounces back. The back of the sensor is
where the rest of the parts are mounted.

Hardware Connections:
The Pulse Rate Sensor should be connected to Uno as follows:

• Signal(S) to A0
• VCC(+) to 5V
• GND(-) to GND
Project Board: Breadboard:

A modern solderless breadboard socket consists of a perforated block of plastic


with numerous tin plated phosphor bronze or nickel silver alloy spring clips under
the perforations. The clips are often called tie points or contact points. The number
of tie points is often given in the specification of the breadboard.
The spacing between the clips (lead pitch) is typically 0.1 inches
(2.54 mm). Integrated circuits (ICs) in dual in-line packages (DIPs) can be inserted to
straddle the centerline of the block. Interconnecting wires and the leads of discrete
components (such as capacitors, resistors, and inductors) can be inserted into the
remaining free holes to complete the circuit. Where ICs are not used, discrete
components and connecting wires may use any of the holes. Typically the spring clips
are rated for 1 ampere at 5 volts and 0.333 amperes at 15 volts
(5 watts). The edge of the board has male and female dovetail notches so boards
can be clipped together to form a large breadboard.
LCD Display (16x2):

Pin Description:

Pin
Function Name
No
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) VCC
3 Contrast adjustment; through a variable resistor VEE
Selects command register when low; and data register Register
4
when high Select
Low to write to the register; High to read from the
5 Read/write
register
Sends data to data pins when a high to low pulse is
6 Enable
given
7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC(5V) Led+
16 Backlight Ground (0V) Led-
Potentiometer(3296W-103-ND):

Track Resistance : 10kohm

No.of Turns : 25 turns

Potentiometer Mounting: Through Hole

Power Rating: 500mW

Resistance Tolerance: ± 10%

Temperature Coefficient: ± 100ppm/°C


CODE:
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;


LiquidCrystal lcd(12,11,5,4,3,2);

int pulsePin = A0; // Pulse Sensor purple wire connected to analog pin A0
int blinkPin = 13; // pin to blink led at each beat

// Volatile Variables, used in the interrupt service routine!


volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when
not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino
Serial Monitor ASCII Visual Pulse

volatile int rate[10]; // array to hold last ten IBI values


volatile unsigned long sampleCounter = 0; // used to determine pulse timing
volatile unsigned long lastBeatTime = 0; // used to find IBI
volatile int P = 512; // used to find peak in pulse wave, seeded
volatile int T = 512; // used to find trough in pulse wave, seeded
volatile int thresh = 525; // used to find instant moment of heart beat, seeded
volatile int amp = 100; // used to hold amplitude of pulse waveform, seeded
volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable
BPM
volatile boolean secondBeat = false; // used to seed rate array so we startup with
reasonable BPM

void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE
BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF
PIN
// analogReference(EXTERNAL);
lcd.begin(16, 2);
lcd.clear();
//Serial.print(BPM);
}

// Where the Magic Happens


void loop()
{
serialOutput();

if (QS == true) // A Heartbeat Was Found


{
// BPM and IBI have been Determined
// Quantified Self "QS" true when arduino finds a heartbeat
serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
}

delay(20); // take a break


}

void interruptSetup()
{
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}

void serialOutput()
{ // Decide How To Output Serial.
if (serialVisual == true)
{
arduinoSerialMonitorVisual('-', Signal); // goes to function that makes Serial Monitor
Visualizer
}
else
{
sendDataToSerial('S', Signal); // goes to sendDataToSerial function
}
}

void serialOutputWhenBeatHappens()
{
if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work
{
Serial.print(" Heart-Beat Found "); //ASCII Art Madness
Serial.print("BPM: ");
Serial.println(BPM);
lcd.print("Heart-Beat Found ");
lcd.setCursor(1,1);
lcd.print("BPM: ");
lcd.setCursor(5,1);
lcd.print(BPM);
delay(3000);
lcd.clear();
}
else
{
sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix
sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix
}
}

void arduinoSerialMonitorVisual(char symbol, int data )


{
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1024; // sensor maximum, discovered through experiment
int sensorReading = data; // map the sensor range to a range of 12 options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 11);
// do something different depending on the
// range value:
}

void sendDataToSerial(char symbol, int data )


{
Serial.print(symbol);
Serial.println(data);
}

ISR(TIMER2_COMPA_vect) //triggered when Timer2 counts to 124


{
cli(); // disable interrupts while we do this
Signal = analogRead(pulsePin); // read the Pulse Sensor
sampleCounter += 2; // keep track of the time in mS with this variable
int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid
noise
// find the peak and trough of the pulse wave
if(Signal < thresh && N > (IBI/5)*3) // avoid dichrotic noise by waiting 3/5 of last IBI
{
if (Signal < T) // T is the trough
{
T = Signal; // keep track of lowest point in pulse wave
}
}

if(Signal > thresh && Signal > P)


{ // thresh condition helps avoid noise
P = Signal; // P is the peak
} // keep track of highest point in pulse wave

// NOW IT'S TIME TO LOOK FOR THE HEART BEAT


// signal surges up in value every time there is a pulse
if (N > 250)
{ // avoid high frequency noise
if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) )
{
Pulse = true; // set the Pulse flag when we think there is a pulse
digitalWrite(blinkPin,HIGH); // turn on pin 13 LED
IBI = sampleCounter - lastBeatTime; // measure time between beats in mS
lastBeatTime = sampleCounter; // keep track of time for next pulse

if(secondBeat)
{ // if this is the second beat, if secondBeat == TRUE
secondBeat = false; // clear secondBeat flag
for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup
{
rate[i] = IBI;
}
}

if(firstBeat) // if it's the first time we found a beat, if firstBeat == TRUE


{
firstBeat = false; // clear firstBeat flag
secondBeat = true; // set the second beat flag
sei(); // enable interrupts again
return; // IBI value is unreliable so discard it
}
// keep a running total of the last 10 IBI values
word runningTotal = 0; // clear the runningTotal variable

for(int i=0; i<=8; i++)


{ // shift data in the rate array
rate[i] = rate[i+1]; // and drop the oldest IBI value
runningTotal += rate[i]; // add up the 9 oldest IBI values
}

rate[9] = IBI; // add the latest IBI to the rate array


runningTotal += rate[9]; // add the latest IBI to runningTotal
runningTotal /= 10; // average the last 10 IBI values
BPM = 60000/runningTotal; // how many beats can fit into a minute? that's BPM!
QS = true; // set Quantified Self flag
// QS FLAG IS NOT CLEARED INSIDE THIS ISR
}
}

if (Signal < thresh && Pulse == true)


{ // when the values are going down, the beat is over
digitalWrite(blinkPin,LOW); // turn off pin 13 LED
Pulse = false; // reset the Pulse flag so we can do it again
amp = P - T; // get amplitude of the pulse wave
thresh = amp/2 + T; // set thresh at 50% of the amplitude
P = thresh; // reset these for next time
T = thresh;
}

if (N > 2500)
{ // if 2.5 seconds go by without a beat
thresh = 512; // set thresh default
P = 512; // set P default
T = 512; // set T default
lastBeatTime = sampleCounter; // bring the lastBeatTime up to date
firstBeat = true; // set these to avoid noise
secondBeat = false; // when we get the heartbeat back
}

sei(); // enable interrupts when youre done!


}// end isr

RESULT:
The hence developed protype measures and displays the number of heart beats per minute. The
LCD display refreshes according the delay command in the code and the detection of pulse by
the sensor.

CONCLUSION:

The prototype was developed successfully. The pulse rate sensor is highly useful. Pulse rate
sensor senses and measures the heart beat rate of the body. The heart beats per minute is an
important data that is used in various fields such as medicine, sports etc.
The pulse rate sensor being a plug and play device makes the job of measuring the heart beats
per minute a easy task with the aid of computer programming by Arduino.
Prototype:

You might also like