Pulse sensor + GSM call
hello,
im having trouble pulse sensor sim800l gsm.
the propose call xxxxx number if bpm <100, value tests.
the modules work alone fine, when put 2 cant make work.
a little help? thx.
srry bad english.
code:
#include <softwareserial.h>
#define sim800_tx_pin 10
#define sim800_rx_pin 11
softwareserial serialsim800(sim800_tx_pin, sim800_rx_pin);
int pulsepin = 0;
// volatile variables, used in interrupt service routine!
volatile int bpm; // int holds raw analog in 0. updated every 2ms
volatile int signal; // holds incoming raw data
volatile int ibi = 600; // int holds time interval between beats! must seeded!
volatile boolean pulse = false; // "true" when user's live heartbeat detected. "false" when not "live beat".
volatile boolean qs = false; // becomes true when arduoino finds beat.
// regards serial output -- set needs
static boolean serialvisual = true; // set 'false' default. re-set 'true' see arduino serial monitor ascii visual pulse
volatile int rate[10]; // array hold last ten ibi values
volatile unsigned long samplecounter = 0; // used determine pulse timing
volatile unsigned long lastbeattime = 0; // used find ibi
volatile int p = 512; // used find peak in pulse wave, seeded
volatile int t = 512; // used find trough in pulse wave, seeded
volatile int thresh = 525; // used find instant moment of heart beat, seeded
volatile int amp = 100; // used hold amplitude of pulse waveform, seeded
volatile boolean firstbeat = true; // used seed rate array startup reasonable bpm
volatile boolean secondbeat = false; // used seed rate array startup reasonable bpm
char buffer[16];
void setup()
{
serial.begin(115200);
while (!serial);
serialsim800.begin(4800);
interruptsetup();
}
void loop(){
serialoutput();
if (qs == true) // heartbeat found
{
serialoutputwhenbeathappens(); // beat happened, output serial.
qs = false; // reset quantified self flag next time
}
delay(20); // take break
}
void interruptsetup()
{
// initializes timer2 throw interrupt every 2ms.
tccr2a = 0x02; // disable pwm on digital pins 3 , 11, , go ctc mode
tccr2b = 0x06; // don't force compare, 256 prescaler
ocr2a = 0x7c; // set top of count 124 500hz sample rate
timsk2 = 0x02; // enable interrupt on match between timer2 , ocr2a
sei(); // make sure global interrupts enabled
}
void serialoutput()
{ // decide how output serial.
if (serialvisual == true)
{
arduinoserialmonitorvisual('-', signal); // goes function makes serial monitor visualizer
}
else
{
senddatatoserial('s', signal); // goes senddatatoserial function
}
}
void serialoutputwhenbeathappens()
{
serialvisual == true; // code make serial monitor visualizer work
serial.print("bpm: ");
serial.println(bpm);
if( bpm<100){ //verifie right value of bpm sent sms.it example
//take value of bpm
serial.print("test");
//set format ascii
serialsim800.write("at+cmgf=1 \r\n");
delay(100);
//send new call command , message number
serialsim800.write("atdxxxnumberherexxxx; \r\n"); <<
delay(10000);
}}
void arduinoserialmonitorvisual(char symbol, int data )
{
const int sensormin = 0; // sensor minimum, discovered through experiment
const int sensormax = 1024; // sensor maximum, discovered through experiment
int sensorreading = data; // map sensor range range of 12 options:
int range = map(sensorreading, sensormin, sensormax, 0, 11);
// different depending on
// range value:
}
void senddatatoserial(char symbol, int data )
{
serial.print(symbol);
serial.println(data);
}
isr(timer2_compa_vect) //triggered when timer2 counts 124
{
cli(); // disable interrupts while this
signal = analogread(pulsepin); // read pulse sensor
samplecounter += 2; // keep track of time in ms variable
int n = samplecounter - lastbeattime; // monitor time since last beat avoid noise
// find peak , trough of pulse wave
if(signal < thresh && n > (ibi/5)*3) // avoid dichrotic noise waiting 3/5 of last ibi
{
if (signal < t) // t trough
{
t = signal; // keep track of lowest point in pulse wave
}
}
if(signal > thresh && signal > p)
{ // thresh condition helps avoid noise
p = signal; // p peak
} // keep track of highest point in pulse wave
// it's time heart beat
// signal surges in value every time there pulse
if (n > 250)
{ // avoid high frequency noise
if ( (signal > thresh) && (pulse == false) && (n > (ibi/5)*3) )
{
pulse = true; // set pulse flag when think there pulse
ibi = samplecounter - lastbeattime; // measure time between beats in ms
lastbeattime = samplecounter; // keep track of time next pulse
if(secondbeat)
{ // if second beat, if secondbeat == true
secondbeat = false; // clear secondbeat flag
for(int i=0; i<=9; i++) // seed running total realisitic bpm @ startup
{
rate = ibi;
}
}
if(firstbeat) // if it's first time found beat, if firstbeat == true
{
firstbeat = false; // clear firstbeat flag
secondbeat = true; // set second beat flag
sei(); // enable interrupts again
return; // ibi value unreliable discard it
}
// keep running total of last 10 ibi values
word runningtotal = 0; // clear runningtotal variable
for(int i=0; i<=8; i++)
{ // shift data in rate array
rate = rate[i+1]; // , drop oldest ibi value
runningtotal += rate; // add 9 oldest ibi values
}
rate[9] = ibi; // add latest ibi rate array
runningtotal += rate[9]; // add latest ibi runningtotal
runningtotal /= 10; // average last 10 ibi values
bpm = 60000/runningtotal; // how many beats can fit minute? that's bpm!
qs = true; // set quantified self flag
// qs flag not cleared inside isr
}
}
if (signal < thresh && pulse == true)
{ // when values going down, beat over
pulse = false; // reset pulse flag can again
amp = p - t; // amplitude of pulse wave
thresh = amp/2 + t; // set thresh @ 50% of amplitude
p = thresh; // reset these next time
t = thresh;
}
if (n > 2500)
{ // if 2.5 seconds go without beat
thresh = 512; // set thresh default
p = 512; // set p default
t = 512; // set t default
lastbeattime = samplecounter; // bring lastbeattime date
firstbeat = true; // set these avoid noise
secondbeat = false; // when heartbeat back
}
sei(); // enable interrupts when youre done!
}
im having trouble pulse sensor sim800l gsm.
the propose call xxxxx number if bpm <100, value tests.
the modules work alone fine, when put 2 cant make work.
a little help? thx.
srry bad english.
code:
#include <softwareserial.h>
#define sim800_tx_pin 10
#define sim800_rx_pin 11
softwareserial serialsim800(sim800_tx_pin, sim800_rx_pin);
int pulsepin = 0;
// volatile variables, used in interrupt service routine!
volatile int bpm; // int holds raw analog in 0. updated every 2ms
volatile int signal; // holds incoming raw data
volatile int ibi = 600; // int holds time interval between beats! must seeded!
volatile boolean pulse = false; // "true" when user's live heartbeat detected. "false" when not "live beat".
volatile boolean qs = false; // becomes true when arduoino finds beat.
// regards serial output -- set needs
static boolean serialvisual = true; // set 'false' default. re-set 'true' see arduino serial monitor ascii visual pulse
volatile int rate[10]; // array hold last ten ibi values
volatile unsigned long samplecounter = 0; // used determine pulse timing
volatile unsigned long lastbeattime = 0; // used find ibi
volatile int p = 512; // used find peak in pulse wave, seeded
volatile int t = 512; // used find trough in pulse wave, seeded
volatile int thresh = 525; // used find instant moment of heart beat, seeded
volatile int amp = 100; // used hold amplitude of pulse waveform, seeded
volatile boolean firstbeat = true; // used seed rate array startup reasonable bpm
volatile boolean secondbeat = false; // used seed rate array startup reasonable bpm
char buffer[16];
void setup()
{
serial.begin(115200);
while (!serial);
serialsim800.begin(4800);
interruptsetup();
}
void loop(){
serialoutput();
if (qs == true) // heartbeat found
{
serialoutputwhenbeathappens(); // beat happened, output serial.
qs = false; // reset quantified self flag next time
}
delay(20); // take break
}
void interruptsetup()
{
// initializes timer2 throw interrupt every 2ms.
tccr2a = 0x02; // disable pwm on digital pins 3 , 11, , go ctc mode
tccr2b = 0x06; // don't force compare, 256 prescaler
ocr2a = 0x7c; // set top of count 124 500hz sample rate
timsk2 = 0x02; // enable interrupt on match between timer2 , ocr2a
sei(); // make sure global interrupts enabled
}
void serialoutput()
{ // decide how output serial.
if (serialvisual == true)
{
arduinoserialmonitorvisual('-', signal); // goes function makes serial monitor visualizer
}
else
{
senddatatoserial('s', signal); // goes senddatatoserial function
}
}
void serialoutputwhenbeathappens()
{
serialvisual == true; // code make serial monitor visualizer work
serial.print("bpm: ");
serial.println(bpm);
if( bpm<100){ //verifie right value of bpm sent sms.it example
//take value of bpm
serial.print("test");
//set format ascii
serialsim800.write("at+cmgf=1 \r\n");
delay(100);
//send new call command , message number
serialsim800.write("atdxxxnumberherexxxx; \r\n"); <<
delay(10000);
}}
void arduinoserialmonitorvisual(char symbol, int data )
{
const int sensormin = 0; // sensor minimum, discovered through experiment
const int sensormax = 1024; // sensor maximum, discovered through experiment
int sensorreading = data; // map sensor range range of 12 options:
int range = map(sensorreading, sensormin, sensormax, 0, 11);
// different depending on
// range value:
}
void senddatatoserial(char symbol, int data )
{
serial.print(symbol);
serial.println(data);
}
isr(timer2_compa_vect) //triggered when timer2 counts 124
{
cli(); // disable interrupts while this
signal = analogread(pulsepin); // read pulse sensor
samplecounter += 2; // keep track of time in ms variable
int n = samplecounter - lastbeattime; // monitor time since last beat avoid noise
// find peak , trough of pulse wave
if(signal < thresh && n > (ibi/5)*3) // avoid dichrotic noise waiting 3/5 of last ibi
{
if (signal < t) // t trough
{
t = signal; // keep track of lowest point in pulse wave
}
}
if(signal > thresh && signal > p)
{ // thresh condition helps avoid noise
p = signal; // p peak
} // keep track of highest point in pulse wave
// it's time heart beat
// signal surges in value every time there pulse
if (n > 250)
{ // avoid high frequency noise
if ( (signal > thresh) && (pulse == false) && (n > (ibi/5)*3) )
{
pulse = true; // set pulse flag when think there pulse
ibi = samplecounter - lastbeattime; // measure time between beats in ms
lastbeattime = samplecounter; // keep track of time next pulse
if(secondbeat)
{ // if second beat, if secondbeat == true
secondbeat = false; // clear secondbeat flag
for(int i=0; i<=9; i++) // seed running total realisitic bpm @ startup
{
rate = ibi;
}
}
if(firstbeat) // if it's first time found beat, if firstbeat == true
{
firstbeat = false; // clear firstbeat flag
secondbeat = true; // set second beat flag
sei(); // enable interrupts again
return; // ibi value unreliable discard it
}
// keep running total of last 10 ibi values
word runningtotal = 0; // clear runningtotal variable
for(int i=0; i<=8; i++)
{ // shift data in rate array
rate = rate[i+1]; // , drop oldest ibi value
runningtotal += rate; // add 9 oldest ibi values
}
rate[9] = ibi; // add latest ibi rate array
runningtotal += rate[9]; // add latest ibi runningtotal
runningtotal /= 10; // average last 10 ibi values
bpm = 60000/runningtotal; // how many beats can fit minute? that's bpm!
qs = true; // set quantified self flag
// qs flag not cleared inside isr
}
}
if (signal < thresh && pulse == true)
{ // when values going down, beat over
pulse = false; // reset pulse flag can again
amp = p - t; // amplitude of pulse wave
thresh = amp/2 + t; // set thresh @ 50% of amplitude
p = thresh; // reset these next time
t = thresh;
}
if (n > 2500)
{ // if 2.5 seconds go without beat
thresh = 512; // set thresh default
p = 512; // set p default
t = 512; // set t default
lastbeattime = samplecounter; // bring lastbeattime date
firstbeat = true; // set these avoid noise
secondbeat = false; // when heartbeat back
}
sei(); // enable interrupts when youre done!
}
update
the call worked, changed atd xxxxx atdl xxxxxx.
still dunno why worked.
the call worked, changed atd xxxxx atdl xxxxxx.
still dunno why worked.
Arduino Forum > Using Arduino > Programming Questions > Pulse sensor + GSM call
arduino
Comments
Post a Comment