Use Arduino to simply test the HC-08 Bluetooth module

Module introduction

HC-08 Bluetooth serial communication module is a new generation of data transmission module based on Bluetooth Specification V4.0 BLE Bluetooth protocol. The wireless operating frequency band is 2.4GHz ISM, and the modulation method is GFSK. The maximum transmit power of the module is 4dBm, and the receiving sensitivity is -93dBm. It can achieve ultra-long distance communication of 80 meters with iPhone 4s in an open environment. The module adopts stamp hole packaging method and can be patch welded. The module size is 26.9mm×13mm×2.2mm, which is very convenient for customers to embed into application systems. The module uses TI's CC2540 chip, configures 256K Byte space, and supports AT commands. Users can change roles (master and slave modes) as well as serial port baud rate, device name, pairing password and other parameters as needed, making it flexible to use.Insert image description here

Module testing

wiring

Here I mainly talk about how to use the arduino uno development board to test the quality of HC-08 Bluetooth. It is suitable for situations where you only have an arduino development board and no serial port to TTL module.
Connect the module to the development board as follows:

arduino HC-08
5V VCC
GND GND
TX RX
RX TX

The actual connection diagram is as follows (the lamp is connected to pin 13):
Insert image description here

code

int LED = 13;

void setup() {
    
    
  pinMode(LED,OUTPUT);// 定义13为输出引脚
  Serial.begin(9600);//模块上电灯快闪,arduino发送指令时需要按住模块上的按键
}
void loop() {
    
    
   while(Serial.available())
  {
    
    
    char ch;
    ch = Serial.read();
    Serial.print(ch); 
    if(ch=='1')
    digitalWrite(LED,HIGH);//接收到1亮灯
    else if(ch=='0')
    digitalWrite(LED,LOW);//接收到0灭灯
    else
    {
    
    
       Serial.println("error cmd");//错误指令不作任何操作并输出error
    } 
  } 
}

Test phenomenon

Download the Bluetooth debugger on your mobile phone, send character 1, and the corresponding pin will output a high level. If you connect a light to pin 13, the phenomenon will be more obvious. (When connecting a light, you need to connect a resistor to limit the current. The voltage output by the pin is 5V)
Insert image description here
0 lights out
Insert image description here

Summarize

When testing, be sure to connect a resistor to limit the current if there is a light connected.
If there is no light, you can use a multimeter to test the voltage output by the pin. When it sends a 1, it outputs a high level, and when it sends a 0, it outputs a low level.

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/133080257