Hi all,
So im having problems sending data to my bluetooth HC-05, the code works as it should but no matter what i try it wont send the information to my app via bluetooth. the project is an ultrasonic sensor measuring distance and when it reaches 10cm i want it to send the measurement to my app i have got the code to acknowledge the fact its reached 10cm but for some reason it wont send it to my app. any help would be gratefully appreciated.
#include <SoftwareSerial.h>
String readString;
SoftwareSerial BT(10, 9); // RX, TX
// defines pins numbers
const int trigPin = 7;
const int echoPin = 8;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
BT.begin(9600);
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
delay(1000);
Serial.println(distance);
if (distance == 10){
Serial.println("OK");
delay(100);
BT.write("ten");
delay(100);
}}