Beginner Help. Transferring data from arduino into phone app through bluetooth.

Hello,

I am relatively new to using the arduino and I have started a project that uses an ultrasonic sensor that sends the data from that sensor into a phone app I made in MIT app inventor through bluetooth. The arduino and ultrasonic sensor are working ( I can see this in the serial monitor); however, my app isn't displaying the values of the data even though the bluetooth is connecting. My understanding from the youtube videos I have watched is that this should be relatively simple since the app should just display what the serial.print() function spits out. My block diagram should be attached below.I'm also using the bluetooth HC-05.

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10,11); // RX, TX

int echoPin=3;//connect the echo pin on ultrasound sensor to pin3 of arduino
int trigPin=2;//connects the trig pin on ultrasound sensor to pin2 of arduino

void setup()
{
// Set pin ports and baud rate
pinMode(2,OUTPUT);
pinMode(3,INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
//
}

void loop()
{
//Following lines create a digital pulse that triggers the "trig" pin on
//sensor and sends out bursts of ultrasound pulses
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
//
long deltaT = pulseIn(3, HIGH);// measures ∆t in microseconds
float distance = ((343deltaT.0001)/2); //measures distance in m
Serial.println(distance);//Prints ∆t to the serial monitor
delay(1000); //waits 1000ms and refreshes screen

BTSerial.println(distance); }}

You are including software serial but are not using it, only hardware serial Serial.begin(9600);
You might fix this by connecting bluetooth to the hardware serial pins 0,1, no change to code, or by writing the software serial commands as you probably intended but didn't.
Just note that, if using hardware serial, you would must disconnect bluetooth first if you need upload any changes to your programme. Any other problems are at the phone end, which you should check by using a standard bluetooth terminal.

Welcome,

You forgot to call BTSerial.begin in setup :slight_smile: