无法从ECG检索数据 - Arduino

时间:2014-12-22 00:45:53

标签: c arduino circuit

您好StackOverflow社区,

在过去的几周里,我一直无法找到解决问题的方法。我的问题是我无法从我从Arduino创建的自制心电图中检索数据。我是一个非常业余的人,但我很确定这是一个电路问题。这就是我的电路现在的样子。 (注意:最左边的'Dual O'是仪表放大器,而不是像中间附近那样的运算放大器)

1 http://i61.tinypic.com/2s6lf0l.jpg

这是我的代码:

const int  signal = 5;    // Pin connected to the filtered signal from the circuit
unsigned long currentBeatTime;   
unsigned long previousBeatTime;

unsigned long frequency;

// Internal variables
unsigned long period = 0;
int input = 0;
int lastinput = 0;


void setup() {
pinMode(signal, INPUT);
Serial.begin(9600);

previousBeatTime = millis();
}

void loop() {
delay(500);
input = digitalRead(signal);

if ((input != lastinput) && (input == HIGH)) {
    // If the pin state has just changed from low to high (edge detector)
    currentBeatTime = millis();

    period = currentBeatTime - previousBeatTime; // Compute the time between the previous beat and the one that has just been detected
    previousBeatTime = currentBeatTime; // Define the new time reference for the next period computing
}

lastinput = input; // Save the current pin state for comparison at the next loop iteration

// Detect if there is no beat after more than 2 seconds
if ( (millis() - previousBeatTime) > 2000 ) 
{ 
    Serial.println("dead");
}
else 
{
    if (period <= 0) 
    {
        frequency = 0;
    }
    else 
    {
        frequency = 60000/period; // Compute the heart rate in beats per minute (bpm) with the period in milliseconds
    }

    Serial.print(frequency);
    Serial.println(" : alive! ");
}
}

如果有人能尽快回复我,我将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

在电流通过LED后,您似乎正在读取引脚5处的电压。 LED产生电压降,因此电压可能永远不会高到在digitalRead()调用时注册为高电平。或许改变了采样电压的位置,或尝试使用analogRead()。

在任何情况下,您都需要确定这是与此板上发布的编程相关问题。也许,electronics.stackexchange会提供更好的帮助。