After uploading the empty sketch I am getting no response in my serial monitor. So I followed the this tutorial
For Slave module I uplaoded the code as:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
BTSerial.write(Serial.read());
}
Connections as :
arduino 5v -> 5V of module
arduino digital 9 -> EN of module
arduino GND -> GND of module
arduino digital 11 -> RX of module
arduino digital 10 -> TX of module ( through voltage divider)
Uploaded the sketch , did the connections and opened the serial monitor after entering in AT MODE:
AT
->OK
AT+UART?
->+UART(9600,0,0)
AT+ROLE?
->+ROLE=0
AT+ADDR?
->+ADDR:98d3:35:cd7d
For master module , uploaded the same code, connected the bluetooth module(same way) ,started the module in AT Mode, opened serial monitor
AT
->OK
AT+UART?
->+UART(9600,0,0)
AT+ROLE?
->+ROLE=0
AT+ROLE=1
->OK
AT+BIND=98d3,35,cd7d
->OK
AT+CMODE=0
->OK
Then I powered down both the arduino started the slave part first and then master. The led in bluetooth module (both master and slave) starts blinking together rapidly 2 times with 2 seconds interval after every 2 blinks. According to me I think the module is paired.
I added a pushbutton to Slave and an led to master.
The code of slave as:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
int button = 2;
int state = 20;
int buttonState = 0;
void setup()
{
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
digitalWrite(9, HIGH);
pinMode(button, INPUT);
Serial.begin(9600);
BTSerial.begin(38400);
}
void loop()
{
buttonState = digitalRead(button);
if (buttonState == HIGH)
{
BTSerial.write('1'); // Sends '1' to the master to turn on LED
}
else
{
BTSerial.write('0');
}
}
The code of master as:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
int ledPin = 12;
int state = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
BTSerial.begin(38400);
}
void loop()
{
if(BTSerial.available() > 0)
{ // Checks whether data is comming from the serial port
state = Serial.write(BTSerial.read());
}
// Controlling the LED
if (state == '1')
{
digitalWrite(ledPin, HIGH); // LED ON
state = 0;
}
else if (state == '0')
{
digitalWrite(ledPin, LOW); // LED ON
state = 0;
}
delay(10);
}
After uploading the code , the pattern of module led blink shows that it is paired but the master led is not working after pressing the push button. I have been trying all different things but I could not get the output.
Can somebody point out what am I missing..
Please help me out
Thanks in advance