Send information with Arduino and HC=5

Hey, I've been working on a project which I have to send information of my serial monitor of Arduino trough Bluetooth (HC05) and print it in a MIT App, but I'm not able to do so. I use a proximity sensor (SRHC04) to grab the info, then print it into the serial monitor but I can't send it to MIT
This is the Arduino's code:

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
#define Pecho 6
#define Ptrig 7
float duracion, distancia; 

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  pinMode(Pecho, INPUT);     
  pinMode(Ptrig, OUTPUT);
  pinMode(2, INPUT);               
}

void loop() {
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }

  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }

  digitalWrite(Ptrig, LOW);
  delayMicroseconds(2);
  digitalWrite(Ptrig, HIGH);   
  delayMicroseconds(10);
  digitalWrite(Ptrig, LOW);
  
  duracion = pulseIn(Pecho, HIGH);
  distancia = (duracion/2) / 29;            
  
  if (distancia >= 500 || distancia <= 0){   
    Serial.println("---");                  
  }
  else {
    Serial.println(distancia);                                     
    digitalWrite(4, 1);
    digitalWrite(2, 1); 
  } 
  delay(1000);                                

}

Add this line to your Arduino code in the appropriate place.

BTSerial.println(distancia);

Thank you so much! You literally saved my life on God!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.