Bluetooth in Embedded Systems: Integration Guide
In this article
Integrating Bluetooth into an embedded system means adding a short-range wireless link between your microcontroller and a phone, sensor, or another device. The shortest working path is: pick a Bluetooth module that matches your power and range needs, connect it over UART, SPI, or USB, load the vendor's stack or use a module with a built-in stack, then pair and test with a phone app or a second board. Most first projects fail at power, antenna placement, or the pairing step, not at the code.
What You'll Need
- A microcontroller board (for example an STM32, ESP32, nRF52, or Arduino-class board) with a free UART or SPI port.
- A Bluetooth module or SoC: a ready-made module with a built-in stack (such as an HC-05/HC-06 for classic SPP, or a module based on the Nordic nRF52 or Espressif ESP32 for BLE) is easiest for a first build.
- A regulated 3.3 V supply that can deliver the module's peak current (often 50–150 mA during radio activity).
- Level shifters if your MCU runs at 5 V and the module is 3.3 V.
- Breadboard, jumper wires, and a USB-to-serial adapter for debugging.
- A phone with a Bluetooth serial or BLE scanner app, or a second development board.
- The module's datasheet and the vendor's SDK or AT-command reference.
Step-by-Step
- Choose classic Bluetooth or BLE. Classic Bluetooth (SPP) is simpler for continuous serial-style links. BLE is better for battery-powered sensors that send small packets occasionally. Decide before you buy a module, because the stacks and pairing flows differ.
- Check the module's supply and pinout. Read the datasheet for supply voltage, peak current, and logic levels. Most modules are 3.3 V logic; feeding 5 V into a 3.3 V RX pin can damage it permanently.
- Wire power and ground first. Connect the module's VCC and GND to a stable 3.3 V rail. Add a 10 µF and a 100 nF capacitor close to the module's power pins to absorb current spikes during transmission. Do not power the module from a microcontroller pin.
- Connect the data lines. For a UART module, cross the lines: MCU TX to module RX, MCU RX to module TX. Use a level shifter on any line where the voltages differ. For SPI or USB modules, follow the datasheet's pin names exactly.
- Set the baud rate. Most serial Bluetooth modules default to 9600 baud, but check the datasheet. Configure your MCU's UART to the same rate, 8 data bits, no parity, 1 stop bit.
- Put the module in the right mode. Many modules have a command mode (often entered by holding a pin or sending a specific sequence) and a data mode. In command mode you can set the device name, PIN, and baud rate using AT commands. In data mode, bytes pass through transparently.
- Load or enable the stack. If you use a module with a built-in stack, you only need to send and receive bytes. If you use a bare SoC, install the vendor's SDK and start from their BLE peripheral or SPP example rather than writing the stack from scratch.
- Advertise and pair. Power the board and scan from your phone. The module should appear under its configured name. Pair with the PIN from the datasheet (often 1234 or 0000) for classic Bluetooth; BLE devices usually pair without a PIN unless you enable bonding.
- Send a test message. From the phone app, send a short string and confirm it arrives on the MCU's UART. Then send from the MCU to the phone. If both directions work, the link is up.
- Add error handling. Check that the module responds to AT commands before you rely on it. Add a timeout when waiting for a connection, and reconnect logic if the link drops. Bluetooth links drop when the phone goes out of range or the module resets.
- Test range and power. Walk the phone away from the board and note where the link fails. Measure current draw with a multimeter in series with the supply, both idle and transmitting, and confirm your battery or regulator can handle the peak.
Common Mistakes
- Powering the module from a 5 V rail or from an MCU GPIO pin. Both cause unstable behavior or permanent damage.
- Forgetting to cross TX and RX. If nothing arrives, swap the two data wires first.
- Mismatched baud rates. Garbage characters usually mean the two sides disagree on speed.
- Placing the antenna against a metal enclosure or under a ground plane. Keep at least 10 mm of clear space around the antenna.
- Leaving the module in command mode. In command mode, AT commands are interpreted instead of being passed through as data.
- Assuming BLE and classic Bluetooth devices can talk to each other. They use different protocols and generally cannot connect directly.
Tips
- Start with a module that has a built-in stack. You can move to a bare SoC once the link works.
- Keep the antenna away from the MCU's crystal and switching regulators; both add noise.
- Use a serial terminal on your PC to send AT commands before wiring the module to your MCU. It isolates module problems from firmware problems.
- Log every byte sent and received during development. Most link bugs are visible in the log.
- For battery devices, set the BLE connection interval and advertising interval as long as your application allows. Longer intervals save power.
Troubleshooting
If the module does not appear in a scan, check power and ground first, then confirm the module is not held in a reset or command state. If it appears but pairing fails, delete the old pairing entry on the phone and try again; stale pairings are a common cause.
If pairing succeeds but no data arrives, verify the baud rate, check that TX and RX are crossed, and confirm the module is in data mode. If you see garbled characters, the baud rate or logic level is wrong.
If the link drops after a few seconds, suspect power. A weak supply or a long, thin jumper wire can cause the module to brown out during transmission. Add the decoupling capacitors and use short, thick power wires.
If range is much shorter than the datasheet claims, move the antenna away from metal and from your body, and check that the module's antenna is not covered by the enclosure.
Frequently Asked Questions
Can I use a 5 V microcontroller with a 3.3 V Bluetooth module?
Yes, but only with a level shifter on the data lines and a 3.3 V supply for the module. Do not connect 5 V logic directly to a 3.3 V input.
Do I need a license to use Bluetooth?
Bluetooth modules are certified by the module vendor for radio compliance in most regions. Using a pre-certified module is the usual path for small projects; check the module's certification documents for your region.
What is the difference between classic Bluetooth and BLE?
Classic Bluetooth is designed for continuous links such as audio and serial data. BLE is designed for low-power, intermittent data. They are not interoperable at the application level.
How far can a Bluetooth link reach?
Typical modules reach about 10 meters in open air, and some reach 100 meters or more with a clear line of sight. Walls, metal, and antenna placement reduce this significantly.
Why does my module show garbage characters?
Almost always a baud rate mismatch or a logic level problem. Confirm both sides use the same baud rate and that the signal voltages match.
Can two Bluetooth modules connect to each other without a phone?
Yes. Two modules of the same type can often be paired directly, which is useful for a wireless serial bridge between two boards.