hi , I`m building a push up counter up using arduino HC-06 bluetooth & ultrasonic sensor HC-SR04
I successfully connect the arduino to the app but the counter is not changing! could use some help
this part of the code:
#define echoPin 2 // Echo Pin
#define trigPin 3 // Trigger Pin
int vibePin = 4; // Vibrabion Pin
SoftwareSerial BT(0, 1); // RX, TX Bluetooth
int BTdata = 0 ; // app variable
long duration, distance; // distance variables
boolean trigUp = false; // upper body trigger
boolean trigDown = false; // lower body trigger
float Cnt=0; // Push Up counter
void Pushup()
{
while (BTdata == '1')
{
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin,HIGH); // receive, convert time (us) to cm
distance = duration * 0.034/2;
if (distance >= 30 && distance <=45) //upper body trigger
{
trigUp = true;
delay(1000);
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin,HIGH); // receive, convert time (us) to cm
distance = duration * 0.034/2;
if (distance >= 10 && distance <=20) // lower body trigger
{
trigDown = true;
}
else if (distance < 10 || distance > 45) //vibration trigger
{
digitalWrite(vibePin,HIGH);
}
if (trigUp == true && trigDown == true)
{
Cnt = Cnt +1;
trigUp = false;
trigDown = false;
}
Serial.write(Cnt);
BTdata == BT.read();
if (BTdata == '0');
{
exit;
}
}
BTdata == BT.read();
if (BTdata == '3')
{
Cnt = 0;
Serial.write(Cnt);
}
}
}