my hc 05 Bluetooth module is fine. it connects to phone and enters AT mode. But the sent data to Bluetooth module is not receiving on my serial monitor. help me solve this issue. Also, i have tried both using diff gpio's and baud rate(9600,38400)
#include <SoftwareSerial.h>
// Define RX and TX pins (Use GPIOs that support software serial)
SoftwareSerial hc05(4, 5); // GPIO4 (D2) = RX, GPIO5 (D1) = TX
void setup() {
Serial.begin(115200); // Hardware Serial for debugging
hc05.begin(38400); // Software Serial for communication
Serial.println("SoftSerial started!");
}
void loop() {
// listen for communication from the ESP8266 and then write it to the serial monitor
if (hc05.available()) {
Serial.write(hc05.read());
}
// listen for user input and send it to the ESP8266
if (Serial.available() > 0) {
Serial.println("Writing to hc05...");
Serial.println(Serial.available());
Serial.println(Serial.read());
hc05.write(Serial.read());
}
}
I don't know what you eactly mean with "" and how is the BT module settings, but based on my previous (old, 3 years ago) experiences with HC05 I remember the default baud rate is 9600 not 38400.
This was one of my test sketches, just to check the communication with the phone (with a simple AppInventor app sending 'A' to turn the LED on, or 'a' off), give it a try and report the serial output when sending characters:
#include <SoftwareSerial.h>
/*
BT module:
RXD <--> Pin 4 (Tx)
TXD <--> Pin 5 (Rx)
VCC <--> 5V
GND <--> GND
Add a LED on pin D3 with 220 Ohm resistor
*/
#define LED 3
SoftwareSerial HC05(4, 5); // TX, RX
void setup ()
{
Serial.begin(115200);
HC05.begin(9600);
pinMode (LED, OUTPUT);
Serial.println("INIT");
}
void loop ()
{
if ( HC05.available() ) {
char c = HC05.read();
Serial.print(c);
Serial.println(" received!");
if (c == 'A') {
digitalWrite(LED, HIGH);
Serial.println("ON");
}
if (c == 'a') {
digitalWrite(LED, LOW);
Serial.println("OFF");
}
delay(100);
}
}
Since you are attempting to enter AT mode, you use 38400, no exceptions. Nothing you have done, or said, confirms your wiring is correct, so check that it is.