Trouble with HC-05 blutooth connection to Arduino

Hello everyone !

I'm new to all of this so this might be trivial to you, but I can't get my HC-05 bluetooth module to work. I'm trying to use it to control my arduino uno and my LCD screen but whenever I plug it in, the red led of the module blinks fast and stops after 1-2s (varying time). I tried plugging only the VCC and GND to the arduino's 5V and GND and had similar results. I also tried with an additional power source which also does the same. I'm wondering if my module is broken or if I don't understand how it works. I'm linking my full Fritzing connection (which is quite a mess sorry about that), and the code if that can help.

I would much appreciate some tips ! :slight_smile:

#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>  // Ajout de la bibliothèque pour gérer le module Bluetooth

RTC_DS1307 rtc;

// Définition des broches du LCD 1602
int RS_1602 = 12;
int Enable_1602 = 11;
int D4_1602 = 5;
int D5_1602 = 4;
int D6_1602 = 3;
int D7_1602 = 2;

// Déclaration de l'objet LCD
LiquidCrystal lcd(RS_1602, Enable_1602, D4_1602, D5_1602, D6_1602, D7_1602);

// Déclaration du port série logiciel pour le module Bluetooth
SoftwareSerial BTSerial(10, 13);  // TX sur 10, RX sur 13

// Tableau contenant les messages à afficher selon le jour
const char* messages[] = {
  "Dimanche: ",
  "Lundi : ",
  "Mardi : ",
  "Mercredi : ",
  "Jeudi : ",
  "Vendredi : ",
  "Samedi : "
};

String SpaceString = "                "; // 16 espaces pour l'effet de défilement
int Scroll_Speed = 300; // Vitesse du défilement

void setup() {
  lcd.begin(16, 2);
  Wire.begin();

  Serial.begin(9600);    // Communication avec le moniteur série
  BTSerial.begin(9600);  // Communication avec le module Bluetooth

  if (!rtc.begin()) {
    lcd.print("RTC Erreur");
    while (1); // Arrêt du programme si l'RTC ne fonctionne pas
  }

  // Vérification si l'heure RTC est correctement initialisée
  DateTime now = rtc.now();
  if (now.year() < 2000) {  // RTC réinitialisé
    lcd.clear();
    lcd.print("RTC Reset");
    delay(2000);
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Réinitialisation avec l'heure de compilation de l'Arduino
  }

  lcd.clear();
  lcd.print("RTC & LCD OK");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Vérifier si un message a été reçu via Bluetooth
  if (BTSerial.available()) {
    String receivedMessage = BTSerial.readString();  // Lire un message reçu
    DisplayMessage(receivedMessage);  // Afficher le message reçu sur l'écran LCD
  }

  // Affichage du message du jour selon l'horloge RTC
  DateTime now = rtc.now();
  int dayOfWeek = now.dayOfTheWeek(); // Obtenir le jour (0=Dimanche, 6=Samedi)
  
  String message = messages[dayOfWeek]; // Récupération du message du jour
  ShowString(message);
  
  delay(2000); // Pause avant le prochain affichage
}

void ShowString(String Scroll_String) {
  lcd.setCursor(0, 0);
  int StrLen = (SpaceString + Scroll_String).length();

  for (int l = 0; l < StrLen + 1; l++) {
    lcd.clear();
    lcd.print((SpaceString + Scroll_String).substring(l, l + 16));
    delay(Scroll_Speed);
  }
}

void DisplayMessage(String msg) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(msg);  // Afficher le message complet reçu
}

hello my name is Mikey! i have been working with arduino for a few years! I am glad to help you! it seems like you are using an arduino uno! which is great for projects like this! i am curious though, do you have a LCD I2C?

It's perfectly fine to be new to this! Bluetooth modules can be a bit tricky at first. Let's break down the HC-05 behavior and how to troubleshoot it.

Understanding the HC-05 LED:

  • Fast Blinking: This generally indicates that the HC-05 is not connected to another Bluetooth device and is in slave mode (waiting for a connection).
  • Slow Blinking or Steady On: This usually means the HC-05 is connected.

Why Your HC-05 Might Not Be Working:

  1. Not in AT Command Mode (If You Need to Configure):
  • To configure the HC-05 (change baud rate, name, etc.), you need to enter AT command mode.
  • To enter AT mode, you typically need to power the module while the KEY pin (sometimes labeled EN or STATE) is HIGH. The exact method varies slightly between HC-05 versions.
  • If you haven't put it in AT command mode, it will simply be in data mode, waiting for a connection.
  1. Incorrect Wiring (Especially RX/TX):
  • Crucial: The RX (receive) pin of the HC-05 must be connected to the TX (transmit) pin of the Arduino, and the TX of the HC-05 to the RX of the Arduino.
  • Voltage Level: The HC-05 operates at 3.3V logic levels. The Arduino Uno's TX pin outputs 5V, which can potentially damage the HC-05. A voltage divider (two resistors) or a logic level converter is recommended for the Arduino's TX to HC-05 RX connection.
  1. Baud Rate Mismatch:
  • The HC-05 and the Arduino's serial communication must use the same baud rate. The default baud rate of the HC-05 is often 9600, but it can be changed.
  • If the arduino serial monitor and the HC-05 are trying to communicate at different speeds, then they will not be able to communicate.
  1. Power Issues (Less Likely, but Possible):
  • While you've tried different power sources, ensure that the HC-05 is receiving a stable 3.3V. It can work at 5v, however it is not recommended.
  1. Module Damage:
  • It's possible, though less common, that the HC-05 is damaged.

Troubleshooting Steps:

  1. Simplify Your Setup:
  • Disconnect the LCD and any other components.
  • Focus on getting the HC-05 and Arduino communicating first.
  1. Verify Wiring:
  • Double-check the RX/TX connections.
  • Use a voltage divider on the Arduino's TX pin (to HC-05 RX) if you haven't already. A simple divider can be made with a 1k ohm resistor and a 2k ohm resistor.
  1. Enter AT Command Mode:
  • Method:
    • Disconnect the HC-05.
    • Connect the KEY pin to 5V (or 3.3V, depending on your module).
    • Connect VCC and GND.
    • The LED should blink slowly (or stay on), indicating AT command mode.
  • Serial Monitor:
    • Open the Arduino Serial Monitor.
    • Set the baud rate to 38400 (common for AT command mode).
    • Set "Both NL & CR" (or "Newline and Carriage Return").
    • Type "AT" (without quotes) and press Enter.
    • If the HC-05 responds with "OK," you're in AT command mode.
  1. Test Basic Communication (Without LCD):
  • Once you have confirmed that the HC-05 is working by getting an "OK" response from the AT command, remove the key pin from the 5v or 3.3v source.
  • Use a simple Arduino sketch to send and receive data via the HC-05.
  • Use a Bluetooth serial terminal app on your phone or computer to connect to the HC-05.
  • Send data from the app to the Arduino and from the Arduino to the app.
  1. Add the LCD:
  • Once the basic communication is working, gradually add the LCD and integrate it into your code.
  • Make sure that the LCD does not interfere with the serial communication.
  1. Code Example (Basic HC-05 Communication):

`

C++
#include <SoftwareSerial.h>

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

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("Bluetooth Serial Started");
}

void loop() {
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }
  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }
}`

Important Notes:

  • If you use SoftwareSerial, choose pins that don't conflict with other components.
  • Always disconnect power before changing wiring.
  • Be patient! Bluetooth communication can take some trial and error.

By following these steps, you should be able to get your HC-05 working. If you still have trouble, provide more details about your wiring and the code you're using, and I'll do my best to help.

This suggests inadequate power, or perhaps simply a slack connection in the breadboard. I suspect the former, and you might get some confirmation of this by getting a longer life if you disconnect the LCD. Your Fritz is fine except there is no mention of the power supply. Please don't tell us you are using a PP3 9v battery. There is nothing (yet) to suggest there is anything wrong with Bluetooth.

I originally used the 5v (and the 3.3v to test) pin of the arduino powered by a usb cable to my computer and since it didn't work I switched to a 5v module that directly powers the bread board by a 9v power plug.
I also tried connecting juste the bluetooth module directly to the arduino with all the rest disconnected and it did the same thing. I tried connecting the module alone on the bread board with cables to the different power sources, and without the bread board directly with the cables with no success

the Arduino has a power limiter to prevent damage to the board, so no matter what plug you are using, you will get 5 volts into the board. I would suggest just trying to use a 9v battery to power it first, no Arduino, just to see if it works.

Just to be clear, it is normal practice to run the peripherals you have from Arduino's 5v pin. There is nothing unusual there, but you don't show it, or the power supply, on your Fritz.

My concern is the supply to Uno. This would not be the first time where the USB port on the PC isn't up to the job.

I think the biggest consumer you have is the LCD backlight, hence my comment.

It appears you have a 9v wall adapter, which I assume plugs into the barrel socket. This needs to be at least 1Amp, which sounds a lot but it isn't and, if it is less than 1A, it is likely to be a lot less. I guess your symptoms could be from an undersized wall adapter, i.e. you could be getting a short shot from a capacitor, but I was really talking about battery power.

The implication in reply #12 to "use a 9v battery to power it first, no Arduino," on a device clearly marked 3.6 - 6v is a pretty silly idea. Leave the 9v battery out of the game - permanently.