Source: https://mokxi.com/learn/arduino-hc05-bluetooth
Updated: 2026-10-05

Learn

# Arduino and the HC-05 Bluetooth module

Beginner

Written by the Mokxi team, updated October 5, 2026

Start building free Open the editor

Or see every lesson.

- 261 parts on the bench
- 31 boards running now
- 1.00x real time, on every board

Type 1 in the HC-05 box of the serial monitor

The Bluetooth chat example on a simulated ATmega328P. Type in the HC-05 box of the serial monitor to be the phone.

The HC-05 is the small blue Bluetooth board with six pins. To your Arduino it is just a serial port. Bytes the Uno sends come out on the phone. Bytes the phone sends come into the Uno. That makes it an easy way to control a project from a phone app.

The circuit above is an Arduino Uno with an HC-05 on pins 2 and 3. It runs the sketch every HC-05 tutorial starts with, using the SoftwareSerial library at 9600 baud. Press Run and open the serial monitor. The module has its own box there, next to the board’s. That box is the phone.

To be clear about one thing: there is no radio here. Mokxi does not model Bluetooth, pairing or a phone. It models the part of the HC-05 your Uno can see, which is its serial port, bit by bit. Everything your sketch does with the module works the same way.

## What you need

- An Arduino Uno
- An HC-05 Bluetooth module
- Jumper wires
- On a real desk: a 1k and a 2k resistor for the RXD divider, and a phone with a Bluetooth serial app

## Wiring

Part and pin | Goes to | Note

HC-05 VCC | 5 V | The board has its own 3.3 V regulator

HC-05 GND | GND | Shared ground

HC-05 TXD | Pin 2 | The sketch’s RX

HC-05 RXD | Pin 3 | The sketch’s TX; add a divider on real hardware

HC-05 EN | Not connected | Only for AT mode, below

HC-05 STATE | Not connected | High while a phone is connected

## Why SoftwareSerial?

The Uno has one hardware serial port, on pins 0 and 1. The USB cable and the serial monitor already use it. So the HC-05 gets a second port made in software, on two ordinary pins.

SoftwareSerial does this with a pin-change interrupt. When the start bit arrives, the interrupt fires and the library times the other bits with counted loops. At 9600 baud, one bit lasts about 104 microseconds. In Mokxi the chip runs every instruction at its real speed, so the library’s timing is the real timing.

Remember the order in the constructor: SoftwareSerial BTSerial(2, 3) means RX on pin 2 and TX on pin 3. The module’s TXD goes to the Uno’s RX pin, and its RXD goes to the Uno’s TX pin. Transmit always goes to receive.

## The sketch, step by step

In setup(), both ports start at 9600 baud, because an HC-05 ships at 9600. The sketch prints "Bluetooth chat ready at 9600 baud." to the serial monitor and sends a hello to the phone.

In loop(), anything that arrives from the phone goes to the serial monitor. Anything you type in the board’s box goes to the phone. The sketch also collects each line from the phone. A line that says 1 turns on the LED on pin 13 and answers "LED on". A line that says 0 turns it off.

Try it: type hello in the HC-05 box and it shows up under the board. Type 1 and the Uno’s LED comes on, and "LED on" shows up under the HC-05.

The loop, from the Bluetooth chat example

## Wait for the whole line before you answer

SoftwareSerial can listen or talk, but not both at once. While it sends a byte, interrupts are off, so a byte coming in at the same moment is lost. That is true on a real Uno too.

That is why the sketch answers only after the phone’s line has ended. If it answered in the middle of a line, the rest of the line would be lost. When you add your own commands, follow the same rule.

## AT commands

An HC-05 has a second mode for changing its settings, called AT mode. Hold the EN pin high (it is marked KEY on some boards) and the module stops passing data. It answers commands instead. In AT mode the module always talks at 38400 baud, whatever the data speed is.

The sketch below is the usual AT sketch. Wire EN to pin 9, run it, and type commands in the board’s box. AT answers OK. AT+VERSION? answers +VERSION:3.0-20170601. AT+NAME=Robot renames the module, and AT+NAME? reads the name back. AT+UART? tells you the data speed, 9600 as shipped.

On a real module, set your serial monitor to send both CR and LF ("Both NL & CR" in the Arduino IDE). The module wants both. Mokxi’s monitor sends a newline, and the model accepts that too.

The AT-mode sketch (EN on pin 9)

## Try it in the editor

Click the HC-05 and change its baud property to 38400, then run again. The sketch still listens at 9600, so what you type as the phone turns into junk. This is the most common HC-05 problem there is. Set the module and the sketch to the same speed and it works again.

Add a second command, like "2" for a buzzer on pin 8. Or wire STATE to pin 4 and print a message when the phone hangs up. Click the module on the canvas to hang up and dial again.

## Common mistakes

TX to TX. The module’s TXD must go to the Uno’s RX pin, which is the first number in SoftwareSerial(2, 3).

Two different speeds. The sketch’s BTSerial.begin() must match the module: 9600 as shipped, or 38400 in AT mode.

Using pins 0 and 1. They belong to the USB serial port. The module will fight the upload and the serial monitor.

Skipping the divider on real hardware. The HC-05’s RXD pin takes 3.3 V. A 1k and 2k divider on the Uno’s TX line keeps it safe.

## Questions

Which pins does an HC-05 use on an Arduino Uno?

Any two digital pins with SoftwareSerial. Pins 2 and 3 are the usual choice: TXD to pin 2 (RX) and RXD to pin 3 (TX), with VCC to 5 V and GND to GND. Avoid pins 0 and 1, which the USB port uses.

What baud rate does the HC-05 use?

9600 baud for data, as shipped. In AT mode it always talks at 38400 baud. You can change the data speed with a command like AT+UART=38400,0,0.

Why does my HC-05 print strange characters?

The sketch and the module are at different speeds. Make BTSerial.begin() match the module. You can cause this on purpose above by changing the module’s baud property.

Can I connect a real phone to Mokxi?

No. There is no Bluetooth radio in Mokxi. The HC-05’s box in the serial monitor plays the part of the phone. The serial side, the SoftwareSerial timing and the AT commands are modeled, so your sketch works the same on real hardware.

Related

## Keep going

Arduino NEO-6M GPS: Wiring, TinyGPS++ and Code Arduino nRF24L01: Wiring, Code and a Radio Doorbell Arduino RC522 RFID Reader: Wiring and Code How the HC-05 is modeled The Bluetooth lamp project Intermediate The Arduino Uno simulator The project page, with the full sketch Beginner

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
