Components and supplies
Jumper wires (generic)
Slide Switch
SparkFun Single Lead Heart Rate Monitor - AD8232
9V battery (generic)
Arduino Nano R3
HC-06 Bluetooth Module
9V Battery Clip
Apps and platforms
EcgSmartApp_ver_4.4
Project description
Code
Arduino Sketch
arduino
Code for the Arduino Nano Board
1int value=0; // analog value 2int index=1; 3byte sntmsg[6]; // vector to send 4 5/* sntmsg 6sntmsg is a 6 bytes vector: 71st byte is always 0xFF and it is used as a check 82nd to 6th bytes contain 4 analog values read form the arduino input A0 and converted into 10 bit numbers: 9 102nd byte: most significant 8 bits of the 1st analog value 113rd byte: least significant 2 bits of the 1st analog value + most significant 6 bits of the 2nd analog value 124th byte: least significant 4 bits of the 2nd analog value + most significant 4 bits of the 3rd analog value 135th byte: least significant 6 bits of the 3rd analog value + most significant 2 bits of the 4th analog value 146th byte: least significant 8 bits of the 4th analog value 15*/ 16 17void setup() { 18 19 sntmsg[0] = 0xFF; // byte1: check 20 21Serial.begin(9600); // initialization serial 22 23noInterrupts(); // interrupts OFF 24 25//set timer1 interrupt at 600 Hz 26 TCCR1A = 0;// set entire TCCR1A register to 0 27 TCCR1B = 0;// same for TCCR1B 28 TCNT1 = 0;//initialize counter value to 0 29 // set compare match register for 1hz increments 30 OCR1A = 416; // = [(16*10^6) / (600*64)]- 1 (must be <65536) 31 // turn on CTC mode 32 TCCR1B |= (1 << WGM12); 33 // Set CS10 and CS12 bits for 64 prescaler 34 TCCR1B |= (1 << CS11) | (1 << CS10);; 35 // enable timer compare interrupt 36 TIMSK1 |= (1 << OCIE1A); 37 38 interrupts(); // interrupts ON 39 40} 41 42ISR(TIMER1_COMPA_vect){ //timer1 interrupt 600Hz 43 44 // read analog value 45 value = analogRead(A0); // read analog value 46 47 switch (index) { 48 49 case 1: 50 51sntmsg[1]= (byte) (value >> 2); // most significant 8 bits of the 1st analog value 52sntmsg[2]= (byte) (value << 6); // least significant 2 bits of the 1st analog value 53++index; 54 break; 55 56 case 2: 57 58//most significant 6 bits of the 2nd analog value 59bitWrite(sntmsg[2], 5, bitRead(value, 9)); 60bitWrite(sntmsg[2], 4, bitRead(value, 8)); 61bitWrite(sntmsg[2], 3, bitRead(value, 7)); 62bitWrite(sntmsg[2], 2, bitRead(value, 6)); 63bitWrite(sntmsg[2], 1, bitRead(value, 5)); 64bitWrite(sntmsg[2], 0, bitRead(value, 4)); 65 66sntmsg[3]= (byte) (value << 4); // least significant 4 bits of the 2nd analog value 67++index; 68 break; 69 70 case 3: 71 72// most significant 4 bits of the 3rd analog value 73bitWrite(sntmsg[3], 3, bitRead(value, 9)); 74bitWrite(sntmsg[3], 2, bitRead(value, 8)); 75bitWrite(sntmsg[3], 1, bitRead(value, 7)); 76bitWrite(sntmsg[3], 0, bitRead(value, 6)); 77 78sntmsg[4]= (byte) (value << 2); // least significant 6 bits of the 3rd analog value 79++index; 80 break; 81 82 case 4: 83 84// most significant 2 bits of the 4th analog value 85bitWrite(sntmsg[4], 1, bitRead(value, 9)); 86bitWrite(sntmsg[4], 0, bitRead(value, 8)); 87 88sntmsg[5]= (byte) (value); // least significant 8 bits of the 4th analog value 89index=1; 90 91Serial.write(sntmsg,6); // send value 92 93 break; 94 95 } // end switch 96 97} // end timer1 interrupt 600Hz 98 99 100void loop() { 101} 102
Arduino Sketch
arduino
Code for the Arduino Nano Board
1int value=0; // analog value 2int index=1; 3byte sntmsg[6]; // vector 4 to send 5 6/* sntmsg 7sntmsg is a 6 bytes vector: 81st byte is always 0xFF 9 and it is used as a check 102nd to 6th bytes contain 4 analog values read form 11 the arduino input A0 and converted into 10 bit numbers: 12 132nd byte: most significant 14 8 bits of the 1st analog value 153rd byte: least significant 2 bits of the 1st 16 analog value + most significant 6 bits of the 2nd analog value 174th byte: least 18 significant 4 bits of the 2nd analog value + most significant 4 bits of the 3rd 19 analog value 205th byte: least significant 6 bits of the 3rd analog value + most 21 significant 2 bits of the 4th analog value 226th byte: least significant 8 bits 23 of the 4th analog value 24*/ 25 26void setup() { 27 28 sntmsg[0] = 0xFF; 29 // byte1: check 30 31Serial.begin(9600); // initialization serial 32 33noInterrupts(); 34 // interrupts OFF 35 36//set timer1 interrupt at 600 Hz 37 TCCR1A = 0;// set 38 entire TCCR1A register to 0 39 TCCR1B = 0;// same for TCCR1B 40 TCNT1 = 0;//initialize 41 counter value to 0 42 // set compare match register for 1hz increments 43 OCR1A 44 = 416; // = [(16*10^6) / (600*64)]- 1 (must be <65536) 45 // turn on CTC mode 46 47 TCCR1B |= (1 << WGM12); 48 // Set CS10 and CS12 bits for 64 prescaler 49 TCCR1B 50 |= (1 << CS11) | (1 << CS10);; 51 // enable timer compare interrupt 52 TIMSK1 53 |= (1 << OCIE1A); 54 55 interrupts(); // interrupts ON 56 57} 58 59ISR(TIMER1_COMPA_vect){ 60 //timer1 interrupt 600Hz 61 62 // read analog value 63 value = analogRead(A0); 64 // read analog value 65 66 switch (index) { 67 68 case 1: 69 70sntmsg[1]= 71 (byte) (value >> 2); // most significant 8 bits of the 1st analog value 72sntmsg[2]= 73 (byte) (value << 6); // least significant 2 bits of the 1st analog value 74++index; 75 76 break; 77 78 case 2: 79 80//most significant 6 bits of the 2nd 81 analog value 82bitWrite(sntmsg[2], 5, bitRead(value, 9)); 83bitWrite(sntmsg[2], 84 4, bitRead(value, 8)); 85bitWrite(sntmsg[2], 3, bitRead(value, 7)); 86bitWrite(sntmsg[2], 87 2, bitRead(value, 6)); 88bitWrite(sntmsg[2], 1, bitRead(value, 5)); 89bitWrite(sntmsg[2], 90 0, bitRead(value, 4)); 91 92sntmsg[3]= (byte) (value << 4); // least significant 93 4 bits of the 2nd analog value 94++index; 95 break; 96 97 case 3: 98 99// 100 most significant 4 bits of the 3rd analog value 101bitWrite(sntmsg[3], 3, bitRead(value, 102 9)); 103bitWrite(sntmsg[3], 2, bitRead(value, 8)); 104bitWrite(sntmsg[3], 1, bitRead(value, 105 7)); 106bitWrite(sntmsg[3], 0, bitRead(value, 6)); 107 108sntmsg[4]= (byte) (value 109 << 2); // least significant 6 bits of the 3rd analog value 110++index; 111 112 break; 113 114 case 4: 115 116// most significant 2 bits of the 4th analog 117 value 118bitWrite(sntmsg[4], 1, bitRead(value, 9)); 119bitWrite(sntmsg[4], 0, bitRead(value, 120 8)); 121 122sntmsg[5]= (byte) (value); // least significant 8 bits of the 4th analog 123 value 124index=1; 125 126Serial.write(sntmsg,6); // send value 127 128 break; 129 130 131 } // end switch 132 133} // end timer1 interrupt 600Hz 134 135 136void loop() 137 { 138} 139
Downloadable files
User Manual
User Manual
Assembly Manual
Assembly Manual
Assembly Manual
Assembly Manual
Device picture
Device picture
Device picture
Device schematics
How to connect all the hardware components
Device schematics
Device schematics
How to connect all the hardware components
Device schematics
Device picture
Device picture
Device picture
Comments
Only logged in users can leave comments