'2) Sensor/Heartbeat_Pulse'에 해당되는 글 2건

  1. 2016.09.17 Finger Heartbeat Detection Sensor Module (KY-039) [S033]
  2. 2016.09.17 Pulse Sensor [S032]

Finger Heartbeat Detection Sensor Module (KY-039) [S033]




https://www.youtube.com/watch?v=PlpGS6BdtK4


*GitHubhttps://github.com/rdiot/rdiot-s033.git


* Specs

KY-039 Finger Detector Heartbeat Detection Sensor Module For Arduino

Specification:

Working voltage: 5V

Use IR LED and optical transistor to detect pulsation in fingers

Used for synthesized teaching experiment

Dimensions: 25 x 22 x 17mm

Weight: 2g


* Contents 



- Connect

S ----- A0

Middle ----- 5V

- ----- GND


Schematic



- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

#define HBDEBUG(i)

 

LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004

 

int sensorPin = A0;

double alpha = 0.75;

int period = 100;

double change = 0.0;

double minval = 0.0;

const int delayMsec = 60; // 100msec per sample


void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

  Serial.begin(9600);

  delay(1000);

 

  lcd.clear();

}

 

void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S033:KY-039");

 

 

  static double oldValue = 0;

  static double oldChange = 0;

  int rawValue = analogRead (sensorPin);

  double value = alpha * oldValue + (1 - alpha) * rawValue;

 

  lcd.setCursor(0,1);

  lcd.print("rawValue=" + (String)rawValue + "   ");

 

  oldValue = value;

 

 

  static int beatMsec = 0;

  int heartRateBPM = 0;

  

  if (heartbeatDetected(sensorPin, delayMsec)) {

    heartRateBPM = 60000 / beatMsec;

    //digitalWrite(ledPin,1);

 

    // Print msec/beat and instantaneous heart rate in BPM

    //Serial.print(beatMsec);

    

    lcd.setCursor(0,2);

    lcd.print("beatMsec=" + (String)beatMsec + "    ");

 

 

    lcd.setCursor(0,3); 

     lcd.print("BPM=" + (String)heartRateBPM + "    ");

 

    beatMsec = 0;

  } else {

    //digitalWrite(ledPin,0);

  }


  delay(delayMsec);

  beatMsec += delayMsec;

 

 

  //delay (period);

}

 

bool heartbeatDetected(int IRSensorPin, int delay)

{

  static int maxValue = 0;

  static bool isPeak = false;

  int rawValue;

  bool result = false;

    

  rawValue = analogRead(IRSensorPin);

  // Separated because analogRead() may not return an int

  rawValue *= (1000/delay);

  HBDEBUG(Serial.print(isPeak); Serial.print("p, "));

  HBDEBUG(Serial.print(rawValue); Serial.print("r, "));

  HBDEBUG(Serial.print(maxValue); Serial.print("m, "));

 

  // If sensor shifts, then max is out of whack.

  // Just reset max to a new baseline.

  if (rawValue * 4L < maxValue) {

    maxValue = rawValue * 0.8;

    HBDEBUG(Serial.print("RESET, "));

  }

  

  // Detect new peak

  if (rawValue > maxValue - (1000/delay)) {

    if (rawValue > maxValue) {

      maxValue = rawValue;

    }

    // Only return true once per peak.

    if (isPeak == false) {

      result = true;

      Serial.print(result); Serial.print(",  *");

    }

    isPeak = true;

  } else if (rawValue < maxValue - (3000/delay)) {

    isPeak = false;

    maxValue-=(1000/delay);

 }

  HBDEBUG(Serial.print("\n"));

  return result;

}

'2) Sensor > Heartbeat_Pulse' 카테고리의 다른 글

Pulse Sensor [S032]  (0) 2016.09.17
Posted by RDIoT
|

Pulse Sensor [S032]



https://www.youtube.com/watch?v=S2rxaMF0KfY


*GitHubhttps://github.com/rdiot/rdiot-s032.git


* Specs

Heart rate data can be really useful whether you’re designing an exercise routine, studying your activity or anxiety levels or just want your shirt to blink with your heart beat. The problem is that heart rate can be difficult to measure. Luckily, the Pulse Sensor Amped can solve that problem!


The Pulse Sensor Amped 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.It essentially combines a simple optical heart rate sensor with amplification and noise cancellation circuitry making it fast and easy to get reliable pulse readings. Also, it sips power with just 4mA current draw at 5V so it’s great for mobile applications.


Simply clip the Pulse Sensor to your earlobe or finger tip and plug it into your 3 or 5 Volt Arduino and you’re ready to read heart rate! The 24" cable on the Pulse Sensor is terminated with standard male headers so there’s no soldering required. Of course Arduino example code is available as well as a Processing sketch for visualizing heart rate data.


* Contents

- Arduino Source : https://github.com/WorldFamousElectronics/PulseSensor_Amped_Arduino (ZIP)

- Processing Source : https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer  (ZIP)


- Connect

White - A0

Black - 5V / 3V

Blue - GND


- in processing 

port = new Serial(this, "COM4", 115200);  // make sure Arduino is talking serial at this baud rate


- Key Code

//  Variables

int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog 


pin 0

int blinkPin = 13;                // pin to blink led at each beat

int fadePin = 5;                  // pin to do fancy classy fading blink at each beat

int fadeRate = 0;                 // used to fade LED on with PWM on fadePin

 

// 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.

 

// Regards Serial OutPut  -- Set This Up to your needs

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

 

 

/* interruptsetup */

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

 


interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 

Posted by RDIoT
|