I've downloaded your code and when I send anything from the phone I don't receive anything back. I have 100% connected the circuit exactly correct according to the circuit schematics posted much earlier on. I am using 5V and ground to power the module but I am using a voltage divider. The problem could be with a faulty module? To test this I turned my master into a slave with the same configuration (role = 0, cmode = 1) and I had the exact same issue: apparently successful connection but nothing happened when I sent text through the serial app.
I can buy one defective module, but not two. ![]()
If you reconfigure the master back to a slave and it connects but doesn't communicate with the phone using the simple code, then there must be something wrong with the wiring. Please attach a photo.
Perhaps you can try some different software serial pins.
You appear to be familiar with using AT mode to change things around. Perhaps you can do a factory reset on the modules.
While testing the code you sent me that just checks communication with the phone, I took out everything except for the module. I've included a photo of my actual circuit (for the voltage divider I am using 2x 1Kohm resisters in series because I couldn't find a normal 2Kohm one connected to ground. The other 1Kohm resistor is connected to the pin). Also, I'm using an Arduino prototyping shield instead of just a breadboard.
I've also included a photo of the serial interface app. (the 'test' messages were ones I sent)
Interestingly, when I tried experimenting with different RX and TX pins I found that even if I unplugged them entirely, I would get the same result: the phone would print that it connected and the module's light would flash correctly but nothing happens when I send messages through the serial app.
I understand that you are finding that the word "test" sent from the phone does not show up in the Serial monitor, and if you enter "hello" into the serial monitor and press send and it does not show up on the phone.
Somehow the module Rx and Tx are not being connected to the software serial pins 11 and 10 on the underlying Uno.
My only suggestion is for testing purposes, to simplify further. Do not use the shield. Remove the voltage divider on module Rx (the modules are pretty tolerant with 5v on the Rx), and just try the module on a breadboard and the Uno. Use different wires if you have them .The Dupont wires can be defective. Do you have another breadboard incase it is what is defective?
I would also suggest that you wire to the side of the module which lists the connects to I can verify what is going where. The photo you attach does not show the connections clearly and I'm not clear what you have done with the resistors.
Can you provide a hand drawn schematic of your wiring?
If the main symptom is that the phone message is not communicated to the Arduino, there is one more thing you can do to simplify the testing. Just connect the module Tx to the Arduino Rx. There are no resistors required for this connection.
You should be able to see a message sent by the phone in the Arduino serial monitor, and if you test the message for content, you can turn a led on and off based on what you sent. You can send simple one character commands from the phone like 'a' or 'b'.
There is no need to connect the module Rx to the Arduino Tx for this test.
I'm getting the test message through now!!
I took everything off apart from the bluetooth module and connecting wires and the message was getting through. I've moved on now to layering up my circuit to see if I can get an LED working when a message is sent
![]()
I haven't got the light working yet but I came across another inconsistency. I went back to my original code and changed "if (BTserial.available() > 0)" to "if (BTserial.available())" and I also added the code in post #20 so I can see what is happening to the messages. Sometimes they are sending fine but other times they are sending inconsistently. Any ideas on how to fix this?

Well done ![]()
You can now focus on the shield and the wiring and stop worrying that the module is defective.
You can now go back to using the original slave code of your first posting. It's robust with the start/end markers receive process.
I would suggest using the onboard led on pin13 when you start. Once you have the code working with both the phone and the master module, then you can switch to an external LED on pin3. Confirm first the the led has the correct resistor and polarity orientation and works with a jumpered 5v.
If you are going to talk to the modules from the Arduino, you should put the voltage divider back on the Arduino Tx to Module Rx line. Do you have the divider on the master HC05 and Arduino which will replace the phone?
If all the slave module/Arduino does is receive commands and has the Arduino read and execute them then the divider is not necessary.
I've moved to experimenting with code that only receives one character to try and work around the inconsistencies I was experimenting with earlier. Using the same circuit setup, I'm using this code instead:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
char receivedChar;
boolean newData = false;
void setup() {
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("<Arduino is ready>");
BTserial.print("<Arduino is ready>");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (BTserial.available() > 0) {
receivedChar = BTserial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChar);
newData = false;
if (receivedChar == 1) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("light on");
}
if (receivedChar == 0) {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("light off");
}
}
}
I modified this code from someone else's forum post (Serial Input Basics). The serial monitor is printing the inputs from the connected phone but two things aren't quite working: two extra instances of "this just in..." are printing after the character, and the comparison between the variable "receivedChar" and the value doesn't seem to be working. Any ideas on how to compare the input with the expected value?
To indicate that a value is a single char and not a number you need to surround it with single quote marks.
https://www.arduino.cc/reference/en/language/variables/data-types/char/
//if (receivedChar == 1) {
if (receivedChar == '1') {
//if (receivedChar == 0) {
if (receivedChar == '0') {
two extra instances of "this just in..." are printing after the character
These are likely the non printing characters for the new line and carriage return: '\n' and '\r'.
Just adding the single quotation wasn't working so I changed to use "strcmp" instead.
if (strcmp(receivedChar,'1')==0) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("light on");
}
if (strcmp(receivedChar,'0')==0) {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("light off");
}
This was really effective because I now have the on board LED turning on and off consistently with the phone commands.
I finally got it working with two Arduino boards communicating with each other. There is a button on one board that turns the on-board LED on the second board on.
The final code that I ended up using is as follows:
Code for master Arduino:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
boolean DEBUG = true; //changing to true outputs debug information to serial monitor
const int ledPin = 2;
const int buttonPin = 5;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
if (DEBUG)
{
// open serial communication for debugging and show
// the sketch filename and the date compiled
Serial.begin(9600);
Serial.println(__FILE__);
Serial.println(__DATE__);
Serial.println(" ");
}
// open software serial connection to the Bluetooth module.
BTserial.begin(9600);
if (DEBUG) { Serial.println("BTserial started at 9600"); }
} // void setup()
void loop()
{
buttonState = digitalRead(buttonPin);
Serial.println(buttonState); // check if button is working because of wrong message sending
if (buttonState == 1) {
digitalWrite(ledPin, HIGH);
BTserial.println('1');
if (DEBUG) {Serial.println("LEDON command sent");}
delay (500);
}
if (buttonState == 0) {
digitalWrite(ledPin, LOW);
BTserial.println('0');
if (DEBUG) {Serial.println("LEDOFF command sent");}
delay (500);
}
}
Code for slave Arduino:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
char receivedChar;
boolean newData = false;
void setup() {
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("<Arduino is ready>");
BTserial.print("<Arduino is ready>");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (BTserial.available() > 0) {
receivedChar = BTserial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChar);
newData = false;
if (strcmp(receivedChar,'1')==0) {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("light on");
}
if (strcmp(receivedChar,'0')==0) {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("light off");
}
}
}
Thank you for helping get this to work ![]()
This is totally incorrect. strcmp() is for null terminated character arrays and not for single chars. It's quite surprising that it actually works correctly.
-
Please post the code you say did not work. In my testing of your code with strcmp() replaced by the single char comparison it runs successfully.
if(receivedChar == '0') or if(receivedChar == '1') -
Learn to use compiler warnings. You should learn to write code without warnings.
In the ide window menu select File>Preferences>Settings
Then select the options
Show verbose output during compilation
Compiler warnings All
Here is the code that didn't work with the suggested change:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(10, 11); // RX | TX
char receivedChar;
boolean newData = false;
void setup() {
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("<Arduino is ready>");
BTserial.print("<Arduino is ready>");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
recvOneChar();
showNewData();
}
void recvOneChar() {
if (BTserial.available() > 0) {
receivedChar = BTserial.read();
newData = true;
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChar);
newData = false;
if (receivedChar == '0') {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("light on");
}
if (receivedChar == '0') {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("light off");
}
}
}
//if (receivedChar == '0') {
if (receivedChar == '1') {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("light on");
}
if (receivedChar == '0') {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("light off");
}
The code you posted has the same test for both received commands. When I correct as above the code runs correctly with the == comparison for a single char.
Thank you!
That's working now with the correct comparison ![]()

