0

I have connected hc-05 bluetooth module and Esp8266 wifi module to my arduino uno. This is my code

#include <SoftwareSerial.h>// import the serial library

SoftwareSerial BluetoothModule(10, 11); // RX, TX

int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer

void setup() {
  // put your setup code here, to run once:
  BluetoothModule.begin(9600);
  BluetoothModule.println("Bluetooth On please press 1 or 0 blink LED ..");
  pinMode(ledpin,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

   if (BluetoothModule.available()){
        BluetoothData=BluetoothModule.read();
        if(BluetoothData=='1') {   // if number 1 pressed ....

            digitalWrite(ledpin,1);
            BluetoothModule.println("LED  On D13 ON ! ");
        }
        if (BluetoothData=='0'){// if number 0 pressed ....

            digitalWrite(ledpin,0);
            BluetoothModule.println("LED  On D13 Off ! ");
        }
    }

  delay(100);// prepare for next data ...
}

As you can see the code is fairly simple ( taken from instructables.com ) And it works fine .I am able to send "0" and "1" from my app and the LED goes on/off.

I have also added ESP8266 wifi module to my arduino and I am able to send AT commands . Here is what I do :

1) Open Serial Monitor

2) Set Baud Rate as 115200

3) Switch to CL and NL 4) Start sending AT commands from Serial Monitor and it works fine. enter image description here

=======

Now my next approach is to receive single character like "a", "b" and then forward this command to ESP8266.

I tried creating a software serial on 8,9 (RX,TX) and tried forwarding "a" as "AT" to the module and receive data from ESP8266 to bluetooth module but that did not work.

if( data == "a" ) {
    ESPserial.write( "AT");
    Bluetooth.println( ESPserial.readString() );
} 

How can I share data between hc-05/esp8266 wifi module ?

abhishekrana
  • 144
  • 1
  • 9

0 Answers0