Go Down

Topic: KY039 Arduino Heart rate code (Read 88043 times) previous topic - next topic

saidbk

Jan 07, 2014, 06:55 pm Last Edit: Jan 08, 2014, 08:30 am by saidbk Reason: 1
Hi all,

I am a newly using arduino. I got an KY039 sensor to get heartbeat and rate.

So I have 2 questions
2- is it normal that  last value are around 1023?
1 - How to calculate Rate every 1min in this code?

this is the code ...thanks

Code: [Select]
// Project 12 - Pulse Monitor Test Script

int ledPin = 13;
int sensorPin = 0;
double alpha = 0.75;
int period = 20;
double change = 0.0;
void setup()                  
{
 pinMode(ledPin, OUTPUT);
 Serial.begin(115200);
}
void loop()                    
{
   static double oldValue = 0;
   static double oldChange = 0;
   int rawValue = analogRead(sensorPin);
   double value = alpha * oldValue + (1 - alpha) * rawValue;
   Serial.print(rawValue);
   Serial.print(",");
   Serial.println(value);
   oldValue = value;
   delay(period);
}









UKHeliBob

Please remove the unnecessary blank lines from your code and post it again using code tags as requested in http://forum.arduino.cc/index.php?topic=97455.0

Is that really the output from that program ?   Why are there no commas in it ?

How is the sensor wired ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

saidbk

#2
Jan 08, 2014, 07:47 am Last Edit: Jan 08, 2014, 07:53 am by saidbk Reason: 1
Hi,
I tried to delete spacing , sorry.
with commas is the same,  with using commas,I tried to get value, oldvalue and change still weird too. 
I add a pic of the sensor

UKHeliBob

The code is easier to read but you have put it in quote tags rather than code tags.

The picture of the sensor is no good at all.  Too small and it does not show how you have connected it to the Arduino.  If you are consistently reading rawValue as 1023 then my guess would be that the sensor is wired wrongly.  Please provide a diagram, hand drawn if necessary, of how the sensor is wired.  The sensor appears to have 3 pins.  What are they and which Arduino pins are they wired to ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

saidbk

#4
Jan 08, 2014, 08:35 am Last Edit: Jan 08, 2014, 08:37 am by saidbk Reason: 1
Ok thanks, my post is much better now.

Sensor is well connected, do you know why I am getting data around 1023 plz?


UKHeliBob

Quote
Sensor is well connected, do you know why I am getting data around 1023 plz?
I will ask one more time then I am going to give up if you don't provide details. 

Exactly how is it connected ?  Which sensor pin to which Arduino pin ?  The larger picture tells us nothing.  For instance, have you got the sensor analogue pin connected to Arduino A0 or Arduino pin 0 ?

If you have got the wiring right then have you tried shielding the whole sensor to prevent ambient light affecting the reading ?  I assume that you are actually putting your finger between the LED and the sensor in the first place.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

saidbk

Hi,
signal pin of Sensor is connected to A0 analog Arduino UNO.
I think that you just answered my question...  and yah I was puting finger between two led emitter/reciever. I shall cover it from light, that is right?

saidbk

a pic of my connection.

The zedgraph Im a getting on C# is weired too.


UKHeliBob

The connections to the sensor look right in the picture but I cannot see a resistor for that other LED.  I know that you are not using it in this project, but it looks wrong to me just connected to two Arduino pins.

Yes, I meant that you should put the sensor in the dark and try reading it.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

saidbk

Hi,

even in dark it give same results... I will change sensor, maybe it is defected
Thanks

limeychiney

I also didn't understand how to make use of the data this sensor was returning. When I probed the signal from the pulse rate sensor with an oscilloscope, there was no discernible voltage change when my finger was on the sensor. i.e. it wasn't picking up any pulse and showing even a slight difference in values. The waveform was flat and zoomed in as far as the scope would allow.

The sensor was responding though. When I had my finger on the sensor with the IR LED right on top of my finger nail I was getting integer values in the 960's. When uncovered, I got readings in the low 900's.

My code is almost identical to that posted above (it's the sample code shown in the pdf for the sensor pack this comes in).

Code: [Select]
// Pulse Monitor Test Script from 37-1 manual
int  sensPin      = 19;     //Sample code specs pin 2, which is digital and does nothing that I can tell
                                       // in that the return values don't change, regardless of sensor being covered
                                       // So I assigned an analog pin
double alpha   = 0.75;
int period         = 20;
double change = 0.0;

void setup ()
{
  pinMode (sensPin, INPUT);
  Serial.begin (115200);
}

void loop ()
{
static double oldValue = 0;
int rawValue = analogRead (sensPin);
double value = alpha * oldValue + (1 - alpha) * rawValue;
Serial.print (rawValue);
Serial.print (",");
Serial.println (value);
oldValue = value;
delay (period);
}


Not sure how to proceed but if anyone has had success with this sensor, I'd love to hear about it. Thanks

UKHeliBob

Try the code on this page http://www.ebay.co.uk/itm/NEW-KY-039-Finger-Measuring-Heartbeat-Sensor-Module-for-Arduino-/331127966386

Note the advice on the page about shielding stray light from the sensor.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

KVinS

#12
Apr 10, 2014, 07:52 pm Last Edit: Apr 10, 2014, 07:57 pm by KVinS Reason: 1
The same problem: The same connected; The same code
Always ~1022 in console (light / dark)
Tested two sensors

With finger drop to ~900


The sensor does not light up. So it should be?

Quote
1021,1021.54
1022,1021.65
1021,1021.49
1021,1021.37
1021,1021.28
1022,1021.46
1022,1021.59
1021,1021.44
1021,1021.33
1021,1021.25
1022,1021.44
1021,1021.33
1022,1021.50
1021,1021.37
1021,1021.28
1021,1021.21
1021,1021.16
1021,1021.12
1022,1021.34
1022,1021.50
1022,1021.63
1021,1021.47
1021,1021.35
1022,1021.51
1021,1021.39
1022,1021.54
1021,1021.40
1022,1021.55
1021,1021.42
1022,1021.56
1022,1021.67
1021,1021.50


Code: [Select]
int ledPin = 13;
int sensorPin = 0;
double alpha = 0.75;
int period = 20;
double change = 0.0;
void setup ()
{
  pinMode (ledPin, OUTPUT);
  Serial.begin (115200);
}
void loop ()
{
    static double oldValue = 0;
    static double oldChange = 0;
    int rawValue = analogRead (sensorPin);
    double value = alpha * oldValue + (1 - alpha) * rawValue;
   
    Serial.print (rawValue);
    Serial.print (",");
    Serial.println (value);
    oldValue = value;
    delay (period);
}


cpu20

Like you are holding the sensor in the picture it can not work. The light from the led is going over your finger. The concept is that it reflects from your finger tot the phototransistor. Or it goes trough your finger.
So you will have to point the led on your finger, for it to work.

johnjameson

I'm after getting one of these sensors,should there be light coming from the Led when you apply power to the sensor?

Go Up