Hello, I'm at a loss for what to do and come to you as my last hope. I've spent a couple of days (over 10 hours) trying to figure this out. I have a HC-05 which is working fine for receiving commands connected to an arduino uno using the schematic "hc05 circuit" I have attached in this thread below.
The problem though is I'm unable to use the HC-05 to transmit anything back to my smart phone. here is my code. It will turn an led on when it receives a 1 and turn the led off when it receives a 0. this works but I need to be able to send back a command to the smart phone so i can confirm the arduino has finished what it's done and the smart phone can continue. This is needed as I am writing my own android app using android studio, where I need to perform an action on the arduino when the user pushes a button and then wait for the arduino to reply when it's finished.
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(2, 3); // RX | TX
int flag = 0;
int LED = 8;
void setup()
{
Serial.begin(9600);
MyBlue.begin(9600);
pinMode(LED, OUTPUT);
Serial.println("Ready to connect\nDefault password is 1234 or 000");
}
void loop()
{
if (MyBlue.available())
flag = MyBlue.read();
Serial.println(flag);
if (flag == 49)
{
MyBlue.print(49); // THIS DOESN'T WORK I TRIED PRINT AND WRITE FUNCTION WITH NO RESULTS I RECIEVE NOTHING BACK TO MY PHONE
MyBlue.write(49);
digitalWrite(LED, HIGH);
Serial.println("LED On");
}
else if (flag == 48)
{
digitalWrite(LED, LOW);
Serial.println("LED Off");
}
}
I have also attached the screenshot on my phone of the bluetooth terminal sending a 1 and 0 to the HC05 but nothing coming back. Please note that in the bluetooth screenshot, all the 1s and 0s are just me sending the data multiple times while testing. It's not the reply from the arduino.
amazon link to the HC-05 module i have: https://www.amazon.co.uk/gp/product/B01G9KSAF6/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1
app im using for testing transmit and recieve: https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&gl=GB
I followed this tutorial from how to mechatronics on how to use the HC-05