Arduino Nano and ECG

Connection, ECG, EMG, EDA, etc.
MarcusKirsch
Posts: 10
Joined: Mon Sep 30, 2013 2:02 pm

Arduino Nano and ECG

Postby MarcusKirsch » Fri Jan 03, 2014 11:37 am

So I hooked up the ECG to an Arduino Nano.

GND & VCC (on3.3V)

A4 of the sensor is connected to the Arduino's A1 analog input pin.

I connected the dual sherlock contacts.

for visual check I added an LED to transform the 0-1000 from the sensor(right?) to be turned into a 0-255 brightness LED flicker/fade.

However all I get is flicker.
the values show the same.

0
720
738
17
0
0
721
738
17
0


thats about 300 milliseconds, I cant see something that looks like a heartbeat. Am I wiring wrong ?

CODE:

Code: Select all

int analogPin = 1;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;
int ledPin = 9;    // LED connected to digital pin 9
int fadeValue = 9;    // LED connected to digital pin 9

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  val = analogRead(analogPin);    // read the input pin
  fadeValue = 255*val/1000;
  analogWrite(ledPin, fadeValue);
 Serial.println(val);
 // delay(10);
}

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Arduino Nano and ECG

Postby BITalino » Mon Jan 13, 2014 12:00 pm

GND & VCC (on3.3V)

A4 of the sensor is connected to the Arduino's A1 analog input pin.

I connected the dual sherlock contacts.

for visual check I added an LED to transform the 0-1000 from the sensor(right?) to be turned into a 0-255 brightness LED flicker/fade.

However all I get is flicker.
the values show the same.



Here's a quick checklist that may come in handy when connecting a BITalino ECG sensor to an Arduino or any other third-party board (it is VERY IMPORTANT to ensure that your third party board is battery powered either directly or indirectly).

1) Besides the GND & VCC (3.3V), it is very important that you connect the VSS pin as well:
viewtopic.php?f=12&t=100

2) When using the sensors with third-party boards, you should use the 3-lead electrode cable, and make sure that you have the electrodes (sticky pads), snapped on each of the leads:
viewtopic.php?f=12&t=7&p=7&hilit=accessories#p7

3) From the 3-lead electrode cable, you should have the IN+ in one hand, the IN- in the other hand, and the REF in one or the other

4) Given the properties of the ECG, your loop has to run at least 100 times per second; note that the Serial port speed can condition that, and when using the Serial port, its recommended that you set it up at 115200

5) Depending on your intended use (e.g. if its just to blink an LED), you may want to narrow the passing band of the sensor, by using a high pass filter to remove the baseline fluctuations introduced for example by the respiration:
viewtopic.php?f=12&t=101

Bellow you'll find a breadboard setup using an Arduino, which together with the following code snippet, produces the result shown in this video:
http://youtu.be/IXzitOZypJ8

Code: Select all

extern volatile unsigned long timer0_millis;
const int analogIn = A1;

int sensorValue = 0;

int dt = 5;

int scnt = 0;
int ssum = 0;

int msum = 0;

int dcnt = 0;
int dsum = 0;

int tcnt = 0;

int aux = 0;

int brightness = 0;
int fadeAmount = 2;

int beatThreshold = 500 // might be user dependant.

const int wlen = 4;

void setup() {
  Serial.begin(115200);
 
  pinMode(9, OUTPUT);
}

void loop() {
  sensorValue = analogRead(analogIn);
 
  if (scnt == wlen) {
    aux = ssum - msum;
   
    if (aux < 0) {
      aux = abs(aux);
    }

    if (dcnt == wlen) {
      if (dsum > beatThreshold) {
        brightness = 255;
      }
     
      dcnt = 0;
      dsum = 0;
    }

    dsum = dsum + aux;
    dcnt = dcnt + 1;
   
    msum = ssum;
   
    scnt = 0;
    ssum = 0;

  }
 
  if (brightness > 0) {
    brightness = brightness - fadeAmount;
  }
 
  ssum = ssum + sensorValue;
  scnt = scnt + 1;
   
  analogWrite(9, brightness);
 
  Serial.print(sensorValue);
  Serial.println(',');
 
  delay (dt-millis());
 
  timer0_millis = 0;
}


Arduino HeartBIT.JPG
BITalino ECG sensor with an Arduino Diecimila
Arduino HeartBIT.JPG (1.45 MiB) Viewed 12475 times

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Arduino Nano and ECG

Postby BITalino » Wed Jan 15, 2014 7:18 pm

Here's another example on a breadboard, this time using an Arduino Pro Mini 3.3V, which produces the following result:
http://youtu.be/nV68hZDTFyg

HeartBIT Arduino Pro Mini.JPG
HeartBIT using an Arduino Pro Mini
HeartBIT Arduino Pro Mini.JPG (1.89 MiB) Viewed 12454 times

tamberg
Posts: 2
Joined: Sat Apr 12, 2014 9:12 pm

Re: Arduino Nano and ECG

Postby tamberg » Sat Apr 12, 2014 9:23 pm

Hi, here's an attempt to make the wiring more clearly visible. Does this correspond to your first picture?

Kind regards,
Thomas
Attachments
bitalino.png
Fritzing.org, CC BY-SA
bitalino.png (234.27 KiB) Viewed 12033 times

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Arduino Nano and ECG

Postby BITalino » Mon Apr 14, 2014 6:30 pm

That's perfect.

Thank you,
The BITalino Team

rfmfp
Posts: 2
Joined: Sun Feb 11, 2018 11:11 pm

Re: Arduino Nano and ECG

Postby rfmfp » Mon Feb 12, 2018 1:04 am

Hey!

I made the wiring you posted here and I decided to join a LiquidCrystal LCD to print the values the ECG/EMG sensor was reading. The problem is when I rewrite the code to print those values the sensor stops reading... I don't understand why. Can you help me?
here's the code:

Code: Select all

#include <LiquidCrystal.h>
extern volatile unsigned long timer0_millis;
const int analogIn = A1;
LiquidCrystal lcd(12,11, 5 , 4 , 3 ,2);
int sensorValue = 0;

int dt = 5;

int scnt = 0;
int ssum = 0;

int msum = 0;

int dcnt = 0;
int dsum = 0;

int tcnt = 0;

int aux = 0;

int brightness = 0;
int fadeAmount = 2;

int beatThreshold = 500 ;// might be user dependant.
int contador = 0;
const int wlen = 4;

void setup() {

  Serial.begin(115200);
 
  pinMode(9, OUTPUT);
  lcd.begin(16,2);
}

void loop() {
  sensorValue = analogRead(analogIn);


lcd.setCursor(0,0);
lcd.print(sensorValue);

 
  if (scnt == wlen) {
    aux = ssum - msum;
   
    if (aux < 0) {
      aux = abs(aux);
    }

    if (dcnt == wlen) {
      if (dsum > beatThreshold) {
        brightness = 255;
      }
     
      dcnt = 0;
      dsum = 0;
    }

    dsum = dsum + aux;
    dcnt = dcnt + 1;
   
    msum = ssum;
   
    scnt = 0;
    ssum = 0;

  }
 
  if (brightness > 0) {
    brightness = brightness - fadeAmount;
  }
 
  ssum = ssum + sensorValue;
  scnt = scnt + 1;
   
  analogWrite(9, brightness);
 
  Serial.print(sensorValue);
  Serial.println(',');
 
  delay (dt-millis());
 
  timer0_millis = 0;
}

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Arduino Nano and ECG

Postby BITalino » Mon Feb 12, 2018 7:21 pm

Hi,

Can you provide additional information that helps zoom in on the problem? Is it associated with the inclusion of the LiquidCrystal.h header that might be redefining some critical variable? If you try to print the readings to the serial port and receive them on the serial monitor is data appearing there? Any additional information would be appreciated.

Best regards,
The BITalino Team

rfmfp
Posts: 2
Joined: Sun Feb 11, 2018 11:11 pm

Re: Arduino Nano and ECG

Postby rfmfp » Mon Feb 12, 2018 9:47 pm

Hey,
When I try to print the readings no data appears in the serial monitor... The LCD displays 0 (zero) and the led doesn't shine on
When I delete all the code related to the LCD it works fine.
Thanks,
Renato

BITalino
Site Admin
Posts: 567
Joined: Tue Aug 27, 2013 3:47 pm

Re: Arduino Nano and ECG

Postby BITalino » Mon Feb 12, 2018 9:58 pm

Hi Renato,

Please check the following thread on the Arduino forum as it could it be related with this issue:
https://forum.arduino.cc/index.php?topic=422150.0

Do keep us posted on your progress and we will try to do our best to provide additional support.

Best regards,
The BITalino Team


Return to “Sensors”




cron