Hello,
I’ve got a bluetooth project where I need to transmit data between two Arduino’s. I’m using one Arduino as a slave (HC-06 module) and another as the master (HC-05 module). I’ve configured the HC-05 module successfully with the AT commands and am able to have it pair with the HC-06 automatically.
The problem I’m having is getting the HC-06 to receive the correct data transmitted from the Arduino with the HC-05 module. I know my code on the HC-06 works because I can remove the HC-05 module from the Arduino and attach it to my TTL to RS-232 module, open up a terminal on my computer and send a number (1, 2 or 3) to command LED13 on the slave arduino to turn on, off and blink.
However, when I attach the HC-05 module back to the Arduino and program it to send a 1, 2 or 3, I am unable to get the slave Arduino to react. I debugged the slave Arduino to see if I am getting any data from the master using the Serial Monitor; however, I am getting incorrect numbers/values.
I have my code listed below for the two different arduino sketches and the output of the Serial Monitor of the slave Arduino.
Slave Arduino Code
#include <SoftwareSerial.h>
int receivedval;
int LED = 13;
SoftwareSerial mySerial(3,4); // RX, TX
//RX on Bluetooth to TX on uC
void setup()
{
pinMode(LED, OUTPUT);
mySerial.begin(38400);
Serial.begin(9600);
}
void loop()
{
while (!mySerial.available()); // stay here so long as COM port is empty
receivedval = mySerial.read(); //Store received data
Serial.println(receivedval); //print received data in Serial Monitor
if (receivedval == 1) { //Series of if-statements will turn LED on (1), off(2) or flash(3)
digitalWrite(LED, HIGH);
}// if it's a 1 turn LED on
if (receivedval == 2) {
digitalWrite(LED, LOW);
} // if it's a 2 turn LED off
if (receivedval == 3) {
for (int i = 0; i < 30; i++) {
digitalWrite(LED, HIGH);
delay(20);
digitalWrite(LED, LOW);
delay(20);
}
}
}
Master Arduino Code
#include <SoftwareSerial.h>
SoftwareSerial mySerialMaster(3,4); // RX, TX
//RX on Bluetooth to TX on uC
void setup()
{
mySerialMaster.begin(38400);
}
void loop()
{
mySerialMaster.println(1);
delay(1000);
mySerialMaster.println(2);
delay(1000);
mySerialMaster.println(3);
delay(1000);
}
See attachement for Output from Slave Arduino
Any input/help is deeply appreciated.