STM32 Blue Pill HC-05 Bluetooth on USART2: Wiring, Code and Simulator
To build this STM32 Blue Pill HC-05 Bluetooth on USART2 project you need an STM32 Blue Pill (STM32F103C8) and a Bluetooth HC-05. USART2 (PA2/PA3) talks to an HC-05 while Serial (USART1) reports what arrives: switch the PC13 LED from the phone terminal. Make the 4 connections in the wiring table, upload the Arduino C++ code, and pair from the Radio tab and send 1. Remember PC13 is active-low: LOW turns the LED on.
Open this circuit in the free STM32 Blue Pill (STM32F103C8) simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) | the microcontroller board |
| 1 | Bluetooth HC-05 | Bluetooth serial module: VCC 5 V, GND, TXD → the board’s RX pin, RXD ← the board’s TX pin (through a 1k/2k divider on a 5 V board). Starts at 9600 baud; hold EN high at power-up for AT commands at 38400. Pair it from the Radio tab’s phone terminal, or with a master HC-05 in another circuit (open it in a second tab). |
Wiring
| # | From | To |
|---|---|---|
| 1 | STM32 Blue Pill (STM32F103C8) 5V | Bluetooth HC-05 VCC |
| 2 | STM32 Blue Pill (STM32F103C8) GND | Bluetooth HC-05 GND |
| 3 | STM32 Blue Pill (STM32F103C8) PA3 | Bluetooth HC-05 TXD |
| 4 | STM32 Blue Pill (STM32F103C8) PA2 | Bluetooth HC-05 RXD |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the STM32 Blue Pill (STM32F103C8). No install or account is needed.
- Add the parts. Add a Bluetooth HC-05 from the parts palette.
- Wire 1. Connect STM32 Blue Pill (STM32F103C8) 5V to Bluetooth HC-05 VCC.
- Wire 2. Connect STM32 Blue Pill (STM32F103C8) GND to Bluetooth HC-05 GND.
- Wire 3. Connect STM32 Blue Pill (STM32F103C8) PA3 to Bluetooth HC-05 TXD.
- Wire 4. Connect STM32 Blue Pill (STM32F103C8) PA2 to Bluetooth HC-05 RXD.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Pair from the Radio tab and send 1. Remember PC13 is active-low: LOW turns the LED on.
Arduino C++ code
// Bluetooth on an STM32 Blue Pill: an HC-05 on USART2 (PA2 TX, PA3 RX).
// Pair from the Radio tab's phone terminal (PIN 1234), send 1 or 0 to
// switch the green LED; what the phone sends is also shown on Serial.
// Wiring: HC-05 VCC 5V, GND, TXD -> PA3, RXD <- PA2 (3.3 V: no divider).
Uart bt(PA3, PA2); // RX, TX (STM32duino 3; older tutorials call it HardwareSerial)
void setup() {
Serial.begin(9600);
bt.begin(9600);
pinMode(PC13, OUTPUT);
digitalWrite(PC13, HIGH); // the LED is wired to 3.3 V: HIGH is off
Serial.println("Blue Pill waiting for a phone...");
}
void loop() {
if (bt.available()) {
char c = bt.read();
Serial.print("Phone sent: ");
Serial.println(c);
if (c == '1') { digitalWrite(PC13, LOW); bt.println("LED is ON"); }
else if (c == '0') { digitalWrite(PC13, HIGH); bt.println("LED is OFF"); }
}
}
What to try
Pair from the Radio tab and send 1. Remember PC13 is active-low: LOW turns the LED on.
Frequently asked questions
How do I wire the HC-05 Bluetooth on USART2 project on an STM32 Blue Pill (STM32F103C8)?
Make 4 connections: STM32 Blue Pill (STM32F103C8) 5V to Bluetooth HC-05 VCC; STM32 Blue Pill (STM32F103C8) GND to Bluetooth HC-05 GND; STM32 Blue Pill (STM32F103C8) PA3 to Bluetooth HC-05 TXD; STM32 Blue Pill (STM32F103C8) PA2 to Bluetooth HC-05 RXD.
What parts do I need for this STM32 Blue Pill project?
An STM32 Blue Pill (STM32F103C8) and a Bluetooth HC-05.
Can I simulate this STM32 Blue Pill project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is built with the STM32duino core and runs on an STM32F103 emulated instruction by instruction: its ARM Cortex-M3 core, NVIC and peripherals (GPIO, EXTI, USART, timers, ADC and I²C).
What does the code do?
USART2 (PA2/PA3) talks to an HC-05 while Serial (USART1) reports what arrives: switch the PC13 LED from the phone terminal.
More STM32 Blue Pill (STM32F103C8) projects
- STM32 Blue Pill LED Blink and Serial: Wiring, Code and Simulator
- STM32 Blue Pill Button Interrupt (EXTI): Wiring, Code and Simulator
- STM32 Blue Pill ADC Potentiometer and PWM LED: Wiring, Code and Simulator
- STM32 Blue Pill I2C BMP280 with Wire: Wiring, Code and Simulator
- STM32 Blue Pill Serial UART Echo: Wiring, Code and Simulator
- STM32 Blue Pill Servo Motor Sweep: Wiring, Code and Simulator