0

I followed this tutorial http://www.martyncurrey.com/using-an-arduino-mega-with-a-hc-05-zs-040-at-mode/ and it seems that the AT mode is on. (the LED is blinking like it's supposed)

I connected my pins like this:

BT VCC to Arduino 5V out. Disconnect before running the sketch

BT GND to Arduino GND

BT RX (through a voltage divider) to Arduino TX1 (pin 18)

BT TX to Arduino RX1 (no need voltage divider) (pin 19)

This is the code I run: (from the tutorial)

// Basic Bluetooth test sketch 5a for the Arduino Mega. 
// AT mode using button switch
// HC-05 with EN pin and button switch
//
// Uses serial with the host computer and serial1 for communication with the Bluetooth module
//
//  Pins
//  BT VCC to Arduino 5V out. Disconnect before running the sketch
//  BT GND to Arduino GND
//  BT RX (through a voltage divider) to Arduino TX1 (pin 18)
//  BT TX  to Arduino RX1 (no need voltage divider)   (pin 19)
//
// When a command is entered in to the serial monitor on the computer 
// the Arduino will relay it to the Bluetooth module and display the result.
//

char serialByte = '0';
const byte  LEDPIN = 13; 

void setup() 
{
    pinMode(LEDPIN, OUTPUT);

    // communication with the host computer
    Serial.begin(9600);  

    Serial.println("Do not power the BT module");
    Serial.println(" ");
    Serial.println("On the BT module, press the button switch (keep pressed, and at the same time power the BT module");
    Serial.println("The LED on the BT module should now flash on/off every 2 seconds");
    Serial.println("Can now release the button switch on the BT module");
    Serial.println(" ");
    Serial.println("After entering AT mode, type 1 and hit send");
    Serial.println(" ");


    // wait for the user to type "1" in the serial monitor
    while (serialByte !='1')
    {
        if ( Serial1.available() )   {  serialByte = Serial1.read();  }
    }  


    // communication with the BT module on serial1
    Serial1.begin(38400);

    // LED to show we have started the serial channels
    digitalWrite(LEDPIN, HIGH);  

    Serial.println(" ");
    Serial.println("AT mode.");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("The HC-05 accepts commands in both upper case and lower case");
    Serial.println(" "); 
}


void loop() 
{
    // listen for communication from the BT module and then write it to the serial monitor
    if ( Serial1.available() )   {  Serial.write( Serial1.read() );  }

    // listen for user input and send it to the HC-05
   if ( Serial.available() )   {  Serial1.write( Serial.read() );  }
}

I want to mention that the baud rate is set to 9600 and Both NL & CR is also set.

The problem is when I insert 1 in the Serial Monitor and nothing happens. How can I solve this problem?

0

Solution

Connection:

  • Bluetooth RXD to Arduino Mega pin 11
  • Bluetooth TXD to Arduino Mega pin 10
  • Bluetooth VCC to Arduino Mega 5V
  • Bluetooth GND to Arduino Mega GND

I used this code:

#include <SoftwareSerial.h>

#define RxD 10
#define TxD 11

SoftwareSerial BTSerial(RxD, TxD);

void setup(){
  // replace BAUDRATE as suggested
  BTSerial.begin(BAUDRATE);
  Serial.begin(9600);
  BTSerial.print("AT\r\n");
}

void loop(){

  if (BTSerial.available())
    Serial.write(BTSerial.read());

  if (Serial.available())
    BTSerial.write(Serial.read());

}

after setting AT mode as described in the tutorial above.

I tried running the code with BAUDRATE starting from 9600 to 460800:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.