HC05 module with arduino pro mini

Hello,

I've recently been trying to set up my arduino pro mini (3.3v 8MHz) to be able to receive OTA programming updates via a HC05 bluetooth module.

For starters, i have been able to receive serial data from the HC05 module sent out from an app from my phone and can also send AT commands to configure the HC05 module. However, i am currently unable to upload a new code to the pro mini via the HC05 module.


I have configured my HC05 based on the above image (which i have found on many websites) and my physical connections between my pro mini and HC05 are as follows:

(Pro Mini/HC05)
VCC => VCC
GND => GND
RST => STATE (connected ONLY when i am trying to upload code via HC05)
PIN0 => RXD
PIN1 => TXD

I've initially connected the TXD and RXD pins of the HC05 to 2 SoftwareSerial pins but it does not work. Following this website: Arduino Remote Programming Using A HC-05 Bluetooth Module | Paynter's Palace, I switched the TXD/RXD to connect to the TXD/RXD of the pro mini but it still does not seem to work.

When i open the serial monitor on the arduino IDE using the bluetooth serial port, i can see that the connection is established (LED on HC05 blinks twice every 5 seconds), and when i close the serial monitor the LED goes back to blinking twice every second.

Would appreciate if anyone here could give me some advice on this!

Edit: The error message that is displayed on the arduino IDE whenever i try to upload a code via the HC05 module is as follows;

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM23
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x90

avrdude done.  Thank you.

An error occurred while uploading the sketch

you should swap the lines, so that RX of arduino will be connected to TX of HC05 and wise verso

Hi,

I tried swapping the lines but the issue is still not resolved.

You must do that whether it solves the issue or not.
It only mean that the problem is elsewhere.

Hi,

Yes i have swapped the lines, i believe the problem is somewhere else because i can send AT commands from the pro mini to the HC05 and receive acknowledgements too.

So you are running SoftwareSerial on the hardware serial pins. Makes little sense and won't work. That is why you are getting the failure to connect. The HC05 is conflicting with hardware serial trying to upload. Move to different pins (see below).

Where did you see to connect the state pin to reset. Makes no sense. The state pin connects to nothing while setting up the module using AT mode. Later you can use it to detect a connection.

If you want to enter AT mode, connect EN to 3.3V. Make sure to connect to 3.3V not 5V or you will kill the HC05.

What baud rate did you use? It must be 38400.

Here is a proven instruction for setting to AT mode:
This instruction is for the HC05 module marked ZS-040 connected to an Arduino Uno, Nano or any mega328 based board. Connect the HC05 as shown in the Martyn Currey page HC05 TX to Arduino pin 2 and HC05 RX to Arduino pin 3 (through voltage divider).

To change the baud rate you must first put the HC05 into AT mode. Do that by connecting the EN pin to 3.3V, NOT 5V. Then power up the Arduino board and HC05 module. The LED on the module should alternate lit for about 3 seconds and off about 3 second if it enters AT mode.

Upload the following code to the Arduino board.

// To enable AT mode connect the EN pin of the HC05 then power
// the HC05
// to 3.3V. Caution, do not connect EN to 5V.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX

const long baudRate = 38400;
char c = ' ';
boolean NL = true;

void setup()
{
Serial.begin(38400);
Serial.print("Sketch: "); Serial.println(FILE);
Serial.print("Uploaded: "); Serial.println(DATE);
Serial.println(" ");

BTserial.begin(baudRate);
Serial.print("BTserial started at ");
Serial.println(baudRate);
//BTserial.print("BTserial started at ");
//BTserial.println(baudRate);
Serial.println(" ");
}

void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}

// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
BTserial.write(c);

  // Echo the user input to the main window. The ">" character indicates the user entered text.
  if (NL)
  {
     Serial.print(">");
     NL = false;
  }
  Serial.write(c);
  if (c == 10)
  {
     NL = true;
  }

}
}

In serial monitor (baud rate set to 38400) you should see something like (the file directory and date will be a bit different):

    ⸮Sketch: D:\bt_test_AT\bt_test_AT.ino
    Uploaded: May 19 2022

BTserial started at 38400

Type "AT" (no quotes) and enter. You may see:

    AT
    ERROR:(0)

That is normal.

Type "AT" (no quotes) and enter again. Now you should see:

    AT
    OK

If that is what you see, the HC05 is in AT mode and ready to accept AT commands.

To set to baud 115200, enter "AT+UART=115200,0,0" (no quotes).
Note: 115200 will not work with a software serial port. That is 38400, max.

Hi

I tried working with SoftwareSerial pins first (digital pins 10 and 11) because i had to use the TXD/RXD pins in order to view serial data on the serial monitor. Subsequently, i connected the TX/RX pins of the HC05 to the TXD/RXD pins of the pro mini only when i wanted to upload my code via bluetooth.

I also only connected the STATE pin to my RST pin when i wanted to upload my code via bluetooth, my apologies for not being clear in my first post.

Currently i have already been able to send AT commands to the HC05 through my pro mini, but thank you for this information.

Then I do not understand what your issue is.

If you want to display data using the serial monitor, you can't use software serial on the hardware serial pins. A serial port can only connect to one thing at a time. If you are not sending data to serial monitor (like in my Bluetooth enabled plotter where the data goes to Grbl) you can connect to the hardware serial pins, but use hardware serial and disconnect to upload. Using hardware serial lets you take advantage of much higher baud rates.

Hi,

I would like to upload an arduino code to my pro mini wirelessly via the HC05, which i am having issues with currently.

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM23
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x90
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xb8
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x90

avrdude done.  Thank you.

An error occurred while uploading the sketch

This is the issue that i get when i try to upload the sketch via the bluetooth serial port.

I see now. I did not read your OP carefully enough. Early morning is my excuse.

I have no experience with uploading code with Bluetooth.

Sorry for wasting your time.

Hello, can anyone help me with this?

Your bootloader baudrate may be 115200 and not 57600.

See what the verbose output from a successful code load over USB looks like. You may see something like this

 Using Port                    : COM5
  Using Programmer              : arduino
  Overriding Baud Rate          : 115200
  AVR Part                      : ATmega328P

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.