HC-05 Bluetooth Module - Introduction

The AZDelivery HC-05 Bluetooth module allows you to send and receive data via Bluetooth using the Arduino. As a communication partner, every other Bluetooth device is basically suitable.

 HC-05

Wiring

For easy wiring of the AZDelivery Bluetooth module to the Arduino, the device communicates with the Arduino via a serial connection and forwards each received character, similar to the PC via the serial console, to the Arduino. This only requires four connections:

Pin on the AZDelivery HC-05 Bluetooth module

Pin des Arduino

Gnd

Gnd

Vcc

+5V

Txd

2

Rxd

3

 

Setup of the Arduino

As an introduction, we want to establish a Bluetooth connection with the phone and output characters sent on the phone in the serial console. For this reason, we cannot use pin 0 and 1 of the Arduino, as these are necessary for connecting to the PC. Instead, we can connect the Bluetooth module to pins 2 and 3 via the SoftwareSerial library, which can make an additional serial connection. If a connection to the PC is not necessary during the Arduino is not necessary, this detour can of course be omitted and directly TXD of the module can be connected to RX and RXD to TX. 

In the Sketch, all you need to do is reload the Software Serial Library and create a Software Serial connection. Then both connections must be started in the setup part, and as soon as something has been received in the loop part via the serial connection to the AZDelivery Bluetooth module, are cached, and sent to the PC. The entire sketch looks like this:


#
include<SoftwareSerial.h>

SoftwareSerial serialbluetooth(2, 3);

void setup() s serialbluetooth.begin(9600);   Serial.begin(9600); 

}

                          void loop() - if(serialbluetooth.available() > 0) 
                               String text = serialbluetooth.readString(); 
                               Serial.println((String)text);                             } 

}

 

Sending information:

To send something to the Arduino via your smartphone, you need a Bluetooth terminal app for the respective operating system. However, a short search in the Appstore should show a wide range of options. For Android, for example, the BlueTerm app is recommended. After installing the app, all you have to do is connect to the AZDelivery Bluetooth module in Bluetooth Manager, and then send strings to the device directly in the app. So when you open the serial console on the PC and connect the phone to the Arduino, you can type something on the phone and after a short time you can see the text on the PC. For example, as an extension of the project, you could insert another query in the loop part to see if a string was sent to the Arduino from the PC via the USB connection, and then forward it to the mobile phone via the Bluetooth module. To do this, only the if query would have to be copied and the two serial connections would have to be exchanged:

 

  if(Serial.available() > 0) 
     String text2 = Serial.readString(); 
     serialbluetooth.println((String)text2);   }


In the following article we want to send the information sent from the mobile phone not only via the serial connection to the PC, but also let the Arduino evaluate the information in order to react accordingly.


Do you need HC-05 modules? Click here

Produktvorstellungen

1 comment

Hans Kusch

Hans Kusch

Es gibt eine App Virtuino.
Einfach und genial.
Einfacher Sketch auf dem Arduino, den Rest erledigt die App.
Vergleichbar mit Blynk , nur eben Bluetooth.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN