// ECG arduino code - v2 - Sep13 - Alan Blackham

//
ecg.htm



#define ANALOG_IN 0

int sensorPin = A0; // select the input pin for the potentiometer long sensorValue = sensorValue; // variable to store the value coming from the sensor int sounder = 11; // sounder int led = 13; // led unsigned long ptime=millis(); // store for time of last pulse void setup() {
  
  // initialize the serial communication:   Serial.begin(9600);
  
  pinMode(sounder, OUTPUT); // sounder pin   digitalWrite(sounder, LOW); // turn sounder off      pinMode(led, OUTPUT); // led pin   digitalWrite(led, LOW); // turn led off } void loop() {
  
  // read the value from the sensor and send via serial once   int val = analogRead(ANALOG_IN);
  Serial.println( val );
  
  // if reading high then log as a pulse   if (val > 300) { // if pulse detected      if ((millis()-ptime) > 300) { // if not to soon since last one        // pulse detected        digitalWrite(sounder, HIGH); // turn sounder on              }      ptime = millis(); // update time of last pulse   }      // flash led and set timing   digitalWrite(led, HIGH); // turn led off   delayMicroseconds(5000); // pause 5ms   digitalWrite(led, LOW); // turn led off   delayMicroseconds(4650); // pause 5ms (tweaked to get timing spot on)        digitalWrite(sounder, LOW); // turn sounder off } // end