hi,
Ive build an app using MIT app inventor for push up project. for the project I
m using arduino uno, HC-06 Bluetooth & ultrasonic sensor HC-SR04
the app is successfully is connected to arduino but not receiving data and the counter is not changing.
I`ve tried
MIT app code
arduino code:
#include <SoftwareSerial.h>
#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
unsigned long start, finished, elapsed; // variables used on more than 1 function need to be declared here
void setup() {
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(vibePin, OUTPUT);
digitalWrite(vibePin, LOW); //vibration off
BT.begin(9600); // Default communication rate of the Bluetooth module
}
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.print(Cnt);
BTdata == BT.read();
if (BTdata == '0');
{
exit;
}
}
BTdata == BT.read();
if (BTdata == '3')
{
Cnt = 0;
Serial.print(Cnt);
}
}
}