thank you for your guiding.
I have change some coding in MIT apps Inventor, however it doesn't works. Could you please help me to change if u think the code is wrong? Because I am just a beginner in the coding world.
Actually, my project is going to make a connection with my heart beat sensor and the bluetooth to phone.
I want to show the waveform which is the blue line, to show it on the phone using MIT apps Inventor.
the value that was circled it the data value for the waveform
this is the code for the MIT apps Inventor, but actually dont know whether it is correct.
Also, how can I change the coding for Arduino in order to communicate with the code of MIT apps inventor to show the graph?
Here is my apps inventor code and Arduino code.
Heart2020 (1).aia (7.8 KB)
#include <SoftwareSerial.h>
SoftwareSerial HC06(2,3);
int UpperThreshold = 550;
int LowerThreshold = 490;
int reading = 0;
float BPM = 0.0;
bool IgnoreReading = false;
bool FirstPulseDetected = false;
unsigned long FirstPulseTime = 0;
unsigned long SecondPulseTime = 0;
unsigned long PulseInterval = 0;
const unsigned long delayTime = 10;
const unsigned long delayTime2 = 1000;
const unsigned long baudRate = 9600;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
void setup(){
Serial.begin(baudRate);
HC06.begin(9600);
}
void loop(){
if (HC06.available()){
Serial.write(HC06.read());
}
//Write from Serial Monitor to HC06
if (Serial.available()){
HC06.write(Serial.read());
}
// Get current time
unsigned long currentMillis = millis();
// First event
if(myTimer1(delayTime, currentMillis) == 1){
reading = analogRead(0);
// Heart beat leading edge detected.
if(reading > UpperThreshold && IgnoreReading == false){
if(FirstPulseDetected == false){
FirstPulseTime = millis();
FirstPulseDetected = true;
}
else{
SecondPulseTime = millis();
PulseInterval = SecondPulseTime - FirstPulseTime;
FirstPulseTime = SecondPulseTime;
}
IgnoreReading = true;
}
// Heart beat trailing edge detected.
if(reading < LowerThreshold && IgnoreReading == true){
IgnoreReading = false;
}
// Calculate Beats Per Minute.
BPM = (1.0/PulseInterval) * 60.0 * 1000;
}
// Second event
if(myTimer2(delayTime2, currentMillis) == 1){
Serial.print(reading);
Serial.print("\t");
Serial.print(PulseInterval);
Serial.print("\t");
Serial.print(BPM);
Serial.println(" BPM");
Serial.flush();
HC06.print(BPM);
HC06.print(" BPM");
HC06.print("/");
HC06.println(reading);
}
}
// First event timer
int myTimer1(long delayTime, long currentMillis){
if(currentMillis - previousMillis >= delayTime){previousMillis = currentMillis;return 1;}
else{return 0;}
}
// Second event timer
int myTimer2(long delayTime2, long currentMillis){
if(currentMillis - previousMillis2 >= delayTime2){previousMillis2 = currentMillis;return 1;}
else{return 0;}
}
Thank you so much for your help!!!


